Class: CDC::Core::EventMetadata
- Inherits:
-
Object
- Object
- CDC::Core::EventMetadata
- Defined in:
- lib/cdc/core/event_metadata.rb
Overview
Immutable metadata container for CDC domain objects.
Metadata keys are normalized to frozen strings. Nested hashes and arrays are recursively converted into Ractor-shareable objects. Values that Ruby cannot make shareable are stored as frozen #inspect strings.
Constant Summary collapse
- EMPTY_DATA =
Ractor.make_shareable( {} # : Hash[untyped, untyped] .freeze )
Instance Attribute Summary collapse
-
#data ⇒ Hash{String=>Object}
readonly
Normalized metadata.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Fetch a metadata value by string or symbol key.
-
#initialize(data = EMPTY_DATA) ⇒ EventMetadata
constructor
Build metadata from a hash-like structure.
-
#to_h ⇒ Hash{String=>Object}
Return the normalized Ractor-shareable hash.
Constructor Details
#initialize(data = EMPTY_DATA) ⇒ EventMetadata
Build metadata from a hash-like structure.
22 23 24 25 |
# File 'lib/cdc/core/event_metadata.rb', line 22 def initialize(data = EMPTY_DATA) @data = deep_shareable_hash(data) Ractor.make_shareable(self) end |
Instance Attribute Details
#data ⇒ Hash{String=>Object} (readonly)
Returns normalized metadata.
17 18 19 |
# File 'lib/cdc/core/event_metadata.rb', line 17 def data @data end |
Instance Method Details
#[](key) ⇒ Object?
Fetch a metadata value by string or symbol key.
31 32 33 34 35 36 |
# File 'lib/cdc/core/event_metadata.rb', line 31 def [](key) string_key = key.to_s return data[string_key] if data.key?(string_key) data[key] end |
#to_h ⇒ Hash{String=>Object}
Return the normalized Ractor-shareable hash.
41 42 43 |
# File 'lib/cdc/core/event_metadata.rb', line 41 def to_h data end |