Class: Sequent::Support::ViewProjection

Inherits:
Object
  • Object
show all
Defined in:
lib/sequent/support/view_projection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ViewProjection

Returns a new instance of ViewProjection.



10
11
12
13
14
15
# File 'lib/sequent/support/view_projection.rb', line 10

def initialize(options)
  @name = options.fetch(:name)
  @version = options.fetch(:version)
  @schema_definition = options.fetch(:definition)
  @replay_event_handlers = options.fetch(:event_handlers)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/sequent/support/view_projection.rb', line 8

def name
  @name
end

#schema_definitionObject (readonly)

Returns the value of attribute schema_definition.



8
9
10
# File 'lib/sequent/support/view_projection.rb', line 8

def schema_definition
  @schema_definition
end

#versionObject (readonly)

Returns the value of attribute version.



8
9
10
# File 'lib/sequent/support/view_projection.rb', line 8

def version
  @version
end

Instance Method Details

#build!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sequent/support/view_projection.rb', line 17

def build!
  with_default_configuration do
    Sequent.configuration.event_handlers = @replay_event_handlers

    load schema_definition
    event_store = Sequent.configuration.event_store
    ordering = Events::ORDERED_BY_STREAM
    event_store.replay_events_from_cursor(
      block_size: 10_000,
      get_events: -> { ordering[event_store] },
    )
  end
end

#schema_nameObject



31
32
33
# File 'lib/sequent/support/view_projection.rb', line 31

def schema_name
  "#{name}_#{version}"
end