Class: Sequent::Core::Projector

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::DescendantsTracker, 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 Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Migratable

all, included, #managed_tables, none, projectors

Methods included from Helpers::MessageHandler

#dispatch_message, #handle_message, included

Constructor Details

#initialize(persistor = Sequent::Core::Persistors::ActiveRecordPersistor.new) ⇒ Projector

Returns a new instance of Projector.



95
96
97
98
# File 'lib/sequent/core/projector.rb', line 95

def initialize(persistor = Sequent::Core::Persistors::ActiveRecordPersistor.new)
  ensure_valid!
  @persistor = persistor
end

Class Attribute Details

.abstract_classObject

Returns the value of attribute abstract_class.



92
93
94
# File 'lib/sequent/core/projector.rb', line 92

def abstract_class
  @abstract_class
end

.skip_autoregisterObject

Returns the value of attribute skip_autoregister.



92
93
94
# File 'lib/sequent/core/projector.rb', line 92

def skip_autoregister
  @skip_autoregister
end

Class Method Details

.replay_persistorObject



100
101
102
# File 'lib/sequent/core/projector.rb', line 100

def self.replay_persistor
  nil
end