Class: SimpleEventSourcing::Events::StoredEvent
- Inherits:
-
Object
- Object
- SimpleEventSourcing::Events::StoredEvent
- Defined in:
- lib/simple_event_sourcing/events/stored_event.rb
Instance Attribute Summary collapse
-
#aggregate_id ⇒ Object
readonly
Returns the value of attribute aggregate_id.
-
#event_data ⇒ Object
readonly
Returns the value of attribute event_data.
-
#event_type ⇒ Object
readonly
Returns the value of attribute event_type.
-
#occurred_on ⇒ Object
readonly
Returns the value of attribute occurred_on.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ StoredEvent
constructor
A new instance of StoredEvent.
- #to_json(*a) ⇒ Object
Constructor Details
#initialize(args) ⇒ StoredEvent
Returns a new instance of StoredEvent.
9 10 11 12 13 14 |
# File 'lib/simple_event_sourcing/events/stored_event.rb', line 9 def initialize(args) @aggregate_id = args[:aggregate_id] @occurred_on = args[:occurred_on] @event_type = args[:event_type] @event_data = args[:event_data] end |
Instance Attribute Details
#aggregate_id ⇒ Object (readonly)
Returns the value of attribute aggregate_id.
7 8 9 |
# File 'lib/simple_event_sourcing/events/stored_event.rb', line 7 def aggregate_id @aggregate_id end |
#event_data ⇒ Object (readonly)
Returns the value of attribute event_data.
7 8 9 |
# File 'lib/simple_event_sourcing/events/stored_event.rb', line 7 def event_data @event_data end |
#event_type ⇒ Object (readonly)
Returns the value of attribute event_type.
7 8 9 |
# File 'lib/simple_event_sourcing/events/stored_event.rb', line 7 def event_type @event_type end |
#occurred_on ⇒ Object (readonly)
Returns the value of attribute occurred_on.
7 8 9 |
# File 'lib/simple_event_sourcing/events/stored_event.rb', line 7 def occurred_on @occurred_on end |
Class Method Details
.create_from_json(json) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/simple_event_sourcing/events/stored_event.rb', line 20 def self.create_from_json(json) stored_event_hash = JSON.parse(json) self.new( aggregate_id: stored_event_hash['aggregate_id'], occurred_on: stored_event_hash['occurred_on'], event_type: stored_event_hash['event_type'], event_data: stored_event_hash['event_data'] ) end |
Instance Method Details
#to_json(*a) ⇒ Object
16 17 18 |
# File 'lib/simple_event_sourcing/events/stored_event.rb', line 16 def to_json(*a) {"aggregate_id" => @aggregate_id, "occurred_on" => @occurred_on.to_i, "event_type" => @event_type.to_s, "event_data" => @event_data }.to_json(*a) end |