Class: Lyra::Projection

Inherits:
Object
  • Object
show all
Defined in:
lib/lyra/projection.rb

Overview

Base class for projections (read models)

Direct Known Subclasses

AuditProjection, StateProjection

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.handle(event) ⇒ Object



5
6
7
# File 'lib/lyra/projection.rb', line 5

def handle(event)
  new.handle(event)
end

.subscribe_to(*event_types) ⇒ Object



9
10
11
12
13
# File 'lib/lyra/projection.rb', line 9

def subscribe_to(*event_types)
  event_types.each do |event_type|
    Lyra.config.event_store.subscribe(self, to: [event_type])
  end
end

Instance Method Details

#handle(event) ⇒ Object



16
17
18
19
# File 'lib/lyra/projection.rb', line 16

def handle(event)
  method_name = "apply_#{event.class.name.demodulize.underscore}"
  send(method_name, event) if respond_to?(method_name, true)
end