Class: Legion::Data::EventStore::Projection

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/data/event_store/projection.rb

Direct Known Subclasses

ConsentState, GovernanceTimeline

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProjection

Returns a new instance of Projection.



9
10
11
# File 'lib/legion/data/event_store/projection.rb', line 9

def initialize
  @state = {}
end

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



7
8
9
# File 'lib/legion/data/event_store/projection.rb', line 7

def state
  @state
end

Class Method Details

.build_from(stream, since: nil) ⇒ Object



17
18
19
20
21
22
# File 'lib/legion/data/event_store/projection.rb', line 17

def self.build_from(stream, since: nil)
  projection = new
  events = EventStore.read_stream(stream, since: since)
  events.each { |e| projection.apply(e) }
  projection
end

Instance Method Details

#apply(_event) ⇒ Object

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/legion/data/event_store/projection.rb', line 13

def apply(_event)
  raise NotImplementedError, "#{self.class} must implement #apply"
end