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.



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

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.



6
7
8
# File 'lib/sequent/support/view_projection.rb', line 6

def name
  @name
end

#schema_definitionObject (readonly)

Returns the value of attribute schema_definition.



6
7
8
# File 'lib/sequent/support/view_projection.rb', line 6

def schema_definition
  @schema_definition
end

#versionObject (readonly)

Returns the value of attribute version.



6
7
8
# File 'lib/sequent/support/view_projection.rb', line 6

def version
  @version
end

Instance Method Details

#build!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sequent/support/view_projection.rb', line 14

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



28
29
30
# File 'lib/sequent/support/view_projection.rb', line 28

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