Module: Familia::IdentifierExtractor
- Included in:
- Familia
- Defined in:
- lib/familia/identifier_extractor.rb
Overview
IdentifierExtractor - Extracts identifiers from Familia objects for storage
This module provides a focused mechanism for converting object references into Redis-storable strings. It handles two primary cases:
- Class references: Customer → "Customer"
- Familia::Base instances: customer_obj → customer_obj.identifier
This is primarily used by DataType serialization when storing object references in Redis data structures (lists, sets, zsets). It extracts the identifier rather than serializing the entire object.
Instance Method Summary collapse
-
#identifier_extractor(value) ⇒ String
Extracts a Redis-storable identifier from a Familia object or class.
Instance Method Details
#identifier_extractor(value) ⇒ String
Extracts a Redis-storable identifier from a Familia object or class.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/familia/identifier_extractor.rb', line 32 def identifier_extractor(value) case value when ::Symbol, ::String, ::Integer, ::Float Familia.trace :IDENTIFIER_EXTRACTOR, nil, 'simple_value' if Familia.debug? # DataTypes (lists, sets, zsets) can store simple values directly # Convert to string for Redis storage value.to_s when Class Familia.trace :IDENTIFIER_EXTRACTOR, nil, 'class' if Familia.debug? value.name when Familia::Base Familia.trace :IDENTIFIER_EXTRACTOR, nil, 'base_instance' if Familia.debug? value.identifier else # Check if value's class inherits from Familia::Base if value.class.ancestors.member?(Familia::Base) Familia.trace :IDENTIFIER_EXTRACTOR, nil, 'base_ancestor' if Familia.debug? value.identifier else Familia.trace :IDENTIFIER_EXTRACTOR, nil, 'error' if Familia.debug? raise Familia::NotDistinguishableError, value end end end |