Class: Dry::Facts::Event
- Inherits:
-
Object
- Object
- Dry::Facts::Event
- Defined in:
- lib/dry/facts/event.rb
Constant Summary collapse
- @@_aggregate_constructor =
false
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Class Method Summary collapse
Instance Method Summary collapse
- #aggregate_id ⇒ Object
- #id ⇒ Object
-
#initialize(data: {}, metadata: {}) ⇒ Event
constructor
data.
- #to_h ⇒ Object
- #uuid ⇒ Object
Constructor Details
#initialize(data: {}, metadata: {}) ⇒ Event
data
37 38 39 40 41 42 |
# File 'lib/dry/facts/event.rb', line 37 def initialize data: {}, metadata: {} @metadata = () || Hash.new @data = {}.merge(data) || Hash.new freeze end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/dry/facts/event.rb', line 10 def data @data end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
11 12 13 |
# File 'lib/dry/facts/event.rb', line 11 def @metadata end |
Class Method Details
.aggregate_constructor ⇒ Object
14 15 16 |
# File 'lib/dry/facts/event.rb', line 14 def aggregate_constructor @@_aggregate_constructor = true end |
.from_h(h) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/dry/facts/event.rb', line 18 def from_h(h) Object .const_get(h[:metadata][:type][:name]) .new( data: h[:data], metadata: h[:metadata]) end |
Instance Method Details
#aggregate_id ⇒ Object
56 57 58 |
# File 'lib/dry/facts/event.rb', line 56 def aggregate_id self.[:aggregate_id] end |
#id ⇒ Object
44 45 46 |
# File 'lib/dry/facts/event.rb', line 44 def id @metadata[:id] end |
#to_h ⇒ Object
60 61 62 63 |
# File 'lib/dry/facts/event.rb', line 60 def to_h { data: self.data, metadata: self. } end |
#uuid ⇒ Object
48 49 50 |
# File 'lib/dry/facts/event.rb', line 48 def uuid @metadata[:uuid] end |