Class: Sequent::Core::AggregateRoot
- Inherits:
-
Object
- Object
- Sequent::Core::AggregateRoot
- Includes:
- Helpers::SelfApplier
- Defined in:
- lib/sequent/core/aggregate_root.rb
Overview
Base class for all your domain classes.
load_from_history functionality to be loaded_from_history, meaning a stream of events.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#sequence_number ⇒ Object
readonly
Returns the value of attribute sequence_number.
-
#uncommitted_events ⇒ Object
readonly
Returns the value of attribute uncommitted_events.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_events ⇒ Object
-
#initialize(id) ⇒ AggregateRoot
constructor
A new instance of AggregateRoot.
- #load_from_history(events) ⇒ Object
- #to_s ⇒ Object
Methods included from Helpers::SelfApplier
Constructor Details
#initialize(id) ⇒ AggregateRoot
Returns a new instance of AggregateRoot.
20 21 22 23 24 |
# File 'lib/sequent/core/aggregate_root.rb', line 20 def initialize(id) @id = id @uncommitted_events = [] @sequence_number = 1 end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/sequent/core/aggregate_root.rb', line 12 def id @id end |
#sequence_number ⇒ Object (readonly)
Returns the value of attribute sequence_number.
12 13 14 |
# File 'lib/sequent/core/aggregate_root.rb', line 12 def sequence_number @sequence_number end |
#uncommitted_events ⇒ Object (readonly)
Returns the value of attribute uncommitted_events.
12 13 14 |
# File 'lib/sequent/core/aggregate_root.rb', line 12 def uncommitted_events @uncommitted_events end |
Class Method Details
.load_from_history(events) ⇒ Object
14 15 16 17 18 |
# File 'lib/sequent/core/aggregate_root.rb', line 14 def self.load_from_history(events) aggregate_root = allocate() # allocate without calling new aggregate_root.load_from_history(events) aggregate_root end |
Instance Method Details
#clear_events ⇒ Object
39 40 41 |
# File 'lib/sequent/core/aggregate_root.rb', line 39 def clear_events uncommitted_events.clear end |
#load_from_history(events) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/sequent/core/aggregate_root.rb', line 26 def load_from_history(events) raise "Empty history" if events.empty? @id = events.first.aggregate_id @uncommitted_events = [] @sequence_number = events.size + 1 events.each { |event| (event) } end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/sequent/core/aggregate_root.rb', line 34 def to_s "#{self.class.name}: #{@id}" end |