Class: RailsEventStore::Event
- Inherits:
-
Object
- Object
- RailsEventStore::Event
- Defined in:
- lib/rails_event_store/event.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#event_id ⇒ Object
readonly
Returns the value of attribute event_id.
-
#event_type ⇒ Object
readonly
Returns the value of attribute event_type.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#initialize(event_data) ⇒ Event
constructor
A new instance of Event.
- #to_h ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(event_data) ⇒ Event
Returns a new instance of Event.
6 7 8 9 10 11 |
# File 'lib/rails_event_store/event.rb', line 6 def initialize(event_data) @event_type = event_data.fetch(:event_type, event_name) @event_id = event_data.fetch(:event_id, generate_id).to_s @metadata = event_data.fetch(:metadata, nil) @data = event_data.fetch(:data, nil) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
13 14 15 |
# File 'lib/rails_event_store/event.rb', line 13 def data @data end |
#event_id ⇒ Object (readonly)
Returns the value of attribute event_id.
13 14 15 |
# File 'lib/rails_event_store/event.rb', line 13 def event_id @event_id end |
#event_type ⇒ Object (readonly)
Returns the value of attribute event_type.
13 14 15 |
# File 'lib/rails_event_store/event.rb', line 13 def event_type @event_type end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
13 14 15 |
# File 'lib/rails_event_store/event.rb', line 13 def @metadata end |
Instance Method Details
#to_h ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/rails_event_store/event.rb', line 21 def to_h { event_type: event_type, event_id: event_id, metadata: , data: data } end |
#validate! ⇒ Object
15 16 17 18 19 |
# File 'lib/rails_event_store/event.rb', line 15 def validate! [event_type, event_id, data].each do |attribute| raise IncorrectStreamData if is_invalid?(attribute) end end |