Class: Sourced::Projector
- Inherits:
-
Object
- Object
- Sourced::Projector
- Extended by:
- Consumer
- 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
Defined Under Namespace
Classes: EventSourced, StateStored
Constant Summary
Constants included from Sync
Constants included from Evolve
Evolve::NOOP_HANDLER, Evolve::PREFIX
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#seq ⇒ Object
readonly
Returns the value of attribute seq.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
- #handle_events(events) ⇒ Object
-
#initialize(id, backend: Sourced.config.backend, logger: Sourced.config.logger) ⇒ Projector
constructor
A new instance of Projector.
- #inspect ⇒ Object
Methods included from Consumer
Methods included from Sync
Methods included from Evolve
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
15 16 17 |
# File 'lib/sourced/projector.rb', line 15 def id @id end |
#seq ⇒ Object (readonly)
Returns the value of attribute seq.
15 16 17 |
# File 'lib/sourced/projector.rb', line 15 def seq @seq end |
#state ⇒ Object (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_events ⇒ Object
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 |
#inspect ⇒ Object
25 26 27 |
# File 'lib/sourced/projector.rb', line 25 def inspect %(<#{self.class} id:#{id} seq:#{seq}>) end |