Class: Sourced::Projector

Inherits:
Object
  • Object
show all
Extended by:
Consumer
Includes:
Evolve, Sync
Defined in:
lib/sourced/projector.rb

Overview

Projectors react to events and update views of current state somewhere (a DB, files, etc)

Direct Known Subclasses

EventSourced, StateStored

Defined Under Namespace

Classes: EventSourced, StateStored

Constant Summary

Constants included from Sync

Sync::CallableInterface

Constants included from Evolve

Evolve::NOOP_HANDLER, Evolve::PREFIX

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Consumer

consumer, consumer_info

Methods included from Sync

included, #run_sync_blocks

Methods included from Evolve

#evolve, included

Constructor Details

#initialize(id, backend: Sourced.config.backend, logger: Sourced.config.logger) ⇒ Projector



17
18
19
20
21
22
23
# File 'lib/sourced/projector.rb', line 17

def initialize(id, backend: Sourced.config.backend, logger: Sourced.config.logger)
  @id = id
  @seq = 0
  @backend = backend
  @logger = logger
  @state = init_state(id)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



15
16
17
# File 'lib/sourced/projector.rb', line 15

def id
  @id
end

#seqObject (readonly)

Returns the value of attribute seq.



15
16
17
# File 'lib/sourced/projector.rb', line 15

def seq
  @seq
end

#stateObject (readonly)

Returns the value of attribute state.



15
16
17
# File 'lib/sourced/projector.rb', line 15

def state
  @state
end

Class Method Details

.handled_eventsObject



12
# File 'lib/sourced/projector.rb', line 12

def handled_events = handled_events_for_evolve

Instance Method Details

#handle_events(events) ⇒ Object



29
30
31
32
33
# File 'lib/sourced/projector.rb', line 29

def handle_events(events)
  evolve(state, events)
  save
  [] # no commands
end

#inspectObject



25
26
27
# File 'lib/sourced/projector.rb', line 25

def inspect
  %(<#{self.class} id:#{id} seq:#{seq}>)
end