Class: EventSourcedRecord::Calculator

Inherits:
Object
  • Object
show all
Defined in:
lib/event_sourced_record/calculator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lookup) ⇒ Calculator

Returns a new instance of Calculator.



12
13
14
# File 'lib/event_sourced_record/calculator.rb', line 12

def initialize(lookup)
  @lookup = lookup
end

Class Method Details

.event_classesObject



6
7
8
9
10
# File 'lib/event_sourced_record/calculator.rb', line 6

def self.event_classes
  @@event_symbols.map { |sym| 
    Module.const_get(sym.to_s.singularize.camelize)
  }
end

.events(*event_symbols) ⇒ Object



2
3
4
# File 'lib/event_sourced_record/calculator.rb', line 2

def self.events(*event_symbols)
  @@event_symbols = event_symbols
end

Instance Method Details

#run(options = {}) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/event_sourced_record/calculator.rb', line 16

def run(options = {})
  instance_variable_set(projection_variable_name, find_or_build_record)
  sorted_events(options[:last_event_time]).each do |event|
    advance_event(event)
  end
  instance_variable_get projection_variable_name
end