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.
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 = {}) ⇒ EventMetadata
constructor
Build metadata from a hash-like structure.
-
#to_h ⇒ Hash{String=>Object}
Return the normalized Ractor-shareable hash.
Constructor Details
#initialize(data = {}) ⇒ EventMetadata
Build metadata from a hash-like structure.
17 18 19 20 |
# File 'lib/cdc/core/event_metadata.rb', line 17 def initialize(data = {}) @data = deep_shareable_hash(data) Ractor.make_shareable(self) end |
Instance Attribute Details
#data ⇒ Hash{String=>Object} (readonly)
Returns normalized metadata.
12 13 14 |
# File 'lib/cdc/core/event_metadata.rb', line 12 def data @data end |
Instance Method Details
#[](key) ⇒ Object?
Fetch a metadata value by string or symbol key.
26 27 28 |
# File 'lib/cdc/core/event_metadata.rb', line 26 def [](key) data[key] || data[key.to_s] || data[key.to_sym] end |
#to_h ⇒ Hash{String=>Object}
Return the normalized Ractor-shareable hash.
33 34 35 |
# File 'lib/cdc/core/event_metadata.rb', line 33 def to_h data end |