Class: EventStore::HTTP::Write::Substitute::Write

Inherits:
Object
  • Object
show all
Defined in:
lib/event_store/http/write/substitute.rb

Defined Under Namespace

Classes: Record

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#versionObject

Returns the value of attribute version.



10
11
12
# File 'lib/event_store/http/write/substitute.rb', line 10

def version
  @version
end

Instance Method Details

#call(batch, stream, expected_version: nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/event_store/http/write/substitute.rb', line 12

def call(batch, stream, expected_version: nil)
  if version && expected_version && version != expected_version
    raise ExpectedVersionError
  end

  if expected_version.nil?
    expected_version = -1
    stream_version = version || -1
  else
    stream_version = expected_version
  end

  path = "#{HTTP::Write.stream_path stream}/#{stream_version + 1}"

  location = URI::HTTP.build :path => path

  batch.events.each do |event|
    write_records << Record.new(event, stream, expected_version)
  end

  location
end

#write_recordsObject



35
36
37
# File 'lib/event_store/http/write/substitute.rb', line 35

def write_records
  @write_records ||= [] 
end

#written?(&block) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'lib/event_store/http/write/substitute.rb', line 39

def written?(&block)
  block ||= proc { true }

  write_records.any? do |record|
    block.(*record.to_a)
  end
end