Class: Akasha::Aggregate
- Inherits:
-
Object
- Object
- Akasha::Aggregate
- Includes:
- SyntaxHelpers
- Defined in:
- lib/akasha/aggregate.rb
Overview
CQRS Aggregate base class.
Usage:
class User < Akasha::Aggregate
def sign_up(email, password)
changeset.append(:user_signed_up, email: email, password: password)
end
def on_user_signed_up(email:, password:, **_)
@email = email
@password = password
end
end
Instance Attribute Summary collapse
-
#changeset ⇒ Object
readonly
Returns the value of attribute changeset.
-
#revision ⇒ Object
readonly
Returns the value of attribute revision.
Instance Method Summary collapse
-
#apply_events(events) ⇒ Object
Replay events, building up the state of the aggregate.
-
#initialize(id) ⇒ Aggregate
constructor
A new instance of Aggregate.
Methods included from SyntaxHelpers
Constructor Details
Instance Attribute Details
#changeset ⇒ Object (readonly)
Returns the value of attribute changeset.
22 23 24 |
# File 'lib/akasha/aggregate.rb', line 22 def changeset @changeset end |
#revision ⇒ Object (readonly)
Returns the value of attribute revision.
22 23 24 |
# File 'lib/akasha/aggregate.rb', line 22 def revision @revision end |
Instance Method Details
#apply_events(events) ⇒ Object
Replay events, building up the state of the aggregate. Used by Repository.
31 32 33 34 35 36 37 |
# File 'lib/akasha/aggregate.rb', line 31 def apply_events(events) events.each do |event| method_name = event_handler(event) public_send(method_name, event.data) if respond_to?(method_name) end @revision = events.last&.revision.to_i end |