Class: RailsSimpleEventSourcing::Event
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- RailsSimpleEventSourcing::Event
- Includes:
- ReadOnly
- Defined in:
- app/models/rails_simple_event_sourcing/event.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.aggregate_model_name(name) ⇒ Object
17 18 19 |
# File 'app/models/rails_simple_event_sourcing/event.rb', line 17 def self.aggregate_model_name(name) singleton_class.instance_variable_set(:@aggregate_model_name, name) end |
.event_attributes(*attributes) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/rails_simple_event_sourcing/event.rb', line 25 def self.event_attributes(*attributes) @event_attributes ||= [] attributes.map(&:to_s).each do |attribute| define_method attribute do self.payload ||= {} self.payload[attribute] end define_method "#{attribute}=" do |argument| self.payload ||= {} self.payload[attribute] = argument end end @event_attributes end |
Instance Method Details
#aggregate_model_name ⇒ Object
21 22 23 |
# File 'app/models/rails_simple_event_sourcing/event.rb', line 21 def aggregate_model_name self.class.singleton_class.instance_variable_get(:@aggregate_model_name) end |
#apply(_aggregate) ⇒ Object
43 44 45 |
# File 'app/models/rails_simple_event_sourcing/event.rb', line 43 def apply(_aggregate) raise NoMethodError, "You must implement #{self.class}#apply" end |