Class: Estore::Commands::Append

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/estore/commands/append.rb

Instance Attribute Summary

Attributes included from Command

#uuid

Instance Method Summary collapse

Methods included from Command

#handle, #promise, #register!, #reject!, #remove!, #write

Constructor Details

#initialize(connection, stream, events, options = {}) ⇒ Append

Returns a new instance of Append.



8
9
10
11
# File 'lib/estore/commands/append.rb', line 8

def initialize(connection, stream, events, options = {})
  super(connection)
  @stream, @events, @options = stream, events, options
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/estore/commands/append.rb', line 13

def call
  register!

  msg = WriteEvents.new(
    event_stream_id: @stream,
    expected_version: @options[:expected_version] || -2,
    events: Array(@events).map { |event| new_event(event) },
    require_master: true
  )
  write('WriteEvents', msg)

  promise
end

#completed(response) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/estore/commands/append.rb', line 27

def completed(response)
  remove!

  if response.result == OperationResult::Success
    promise.fulfill(response)
  else
    promise.reject Estore::WriteEventsError.new(response)
  end
end