Class: Sequent::Core::Projector
- Inherits:
-
Object
- Object
- Sequent::Core::Projector
- Extended by:
- Forwardable
- Includes:
- Helpers::MessageHandler, Migratable
- Defined in:
- lib/sequent/core/projector.rb
Overview
Projectors listen to events and update the view state as they see fit.
Example of updating view state, in this case the InvoiceRecord table representing an Invoice
class InvoiceProjector < Sequent::Core::Projector
manages_tables InvoiceRecord
on InvoiceCreated do |event|
create_record(
InvoiceRecord,
recipient: event.recipient,
amount: event.amount
)
end
end
Please note that the actual storage is abstracted away in the persistors. Due to this abstraction you can not traverse persist or traverse child objects like you are used to do with ActiveRecord. The following example will not work:
invoice_record.line_item_records << create_record(LineItemRecord, ...)
In this case you should simply do:
create_record(LineItemRecord, invoice_id: invoice_record.aggregate_id)
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(persistor = Sequent::Core::Persistors::ActiveRecordPersistor.new) ⇒ Projector
constructor
A new instance of Projector.
Methods included from Migratable
all, included, #managed_tables, none, projectors
Methods included from Helpers::MessageHandler
Constructor Details
#initialize(persistor = Sequent::Core::Persistors::ActiveRecordPersistor.new) ⇒ Projector
Returns a new instance of Projector.
72 73 74 75 |
# File 'lib/sequent/core/projector.rb', line 72 def initialize(persistor = Sequent::Core::Persistors::ActiveRecordPersistor.new) ensure_valid! @persistor = persistor end |
Class Method Details
.replay_persistor ⇒ Object
77 78 79 |
# File 'lib/sequent/core/projector.rb', line 77 def self.replay_persistor nil end |