class Messaging::Write::Substitute::Write

Attributes

raise_expected_version_error[W]
sink[RW]

Public Class Methods

build(session: nil) click to toggle source
# File lib/messaging/write/substitute.rb, line 23
def self.build(session: nil)
  new.tap do |instance|
    ::Telemetry.configure instance
  end
end

Public Instance Methods

call(*args, **keyword_args) click to toggle source
Calls superclass method Messaging::Write#call
# File lib/messaging/write/substitute.rb, line 29
def call(*args, **keyword_args)
  raise MessageStore::ExpectedVersion::Error if raise_expected_version_error
  super(*args, **keyword_args)
end
Also aliased as: write
message_replies(&blk) click to toggle source
# File lib/messaging/write/substitute.rb, line 147
def message_replies(&blk)
  if blk.nil?
    return sink.replied_records.map { |record| record.data.message }
  end

  sink.replied_records.select do |record|
    blk.call(record.data.message, record.data.stream_name)
  end.map { |record| record.data.message }
end
message_writes(&blk) click to toggle source
# File lib/messaging/write/substitute.rb, line 126
def message_writes(&blk)
  if blk.nil?
    return sink.written_records.map { |record| record.data.message }
  end

  sink.written_records.select do |record|
    blk.call(record.data.message, record.data.stream_name, record.data.expected_version, record.data.reply_stream_name)
  end.map { |record| record.data.message }
end
one_message(&blk)
Alias for: one_message_write
one_message_reply(&blk) click to toggle source
# File lib/messaging/write/substitute.rb, line 157
def one_message_reply(&blk)
  messages = message_replies(&blk)

  if messages.length > 1
    raise Substitute::Error, "More than one matching message reply was written"
  end

  messages.first
end
Also aliased as: one_reply
one_message_write(&blk) click to toggle source
# File lib/messaging/write/substitute.rb, line 136
def one_message_write(&blk)
  messages = message_writes(&blk)

  if messages.length > 1
    raise Substitute::Error, "More than one matching message was written"
  end

  messages.first
end
Also aliased as: one_message
one_reply(&blk)
Alias for: one_message_reply
raise_expected_version_error() click to toggle source
# File lib/messaging/write/substitute.rb, line 18
def raise_expected_version_error
  @raise_expected_version_error ||= false
end
raise_expected_version_error!() click to toggle source
# File lib/messaging/write/substitute.rb, line 35
def raise_expected_version_error!
  self.raise_expected_version_error = true
  nil
end
replied?(message=nil, &blk) click to toggle source
# File lib/messaging/write/substitute.rb, line 93
def replied?(message=nil, &blk)
  if message.nil?
    if blk.nil?
      return sink.recorded_replied?
    end

    return sink.recorded_replied? do |record|
      blk.call(record.data.message, record.data.stream_name)
    end
  end

  written = sink.recorded_replied? do |record|
    record.data.message == message
  end

  if !written
    return false
  end

  # Is written and no inspection block is provided,
  # therefore no subsequent inspection beyond the
  # message being found in the telemetry
  # Is written
  if blk.nil?
    return true
  end

  # Otherwise, proceed to subsequent inspecting using the block
  sink.recorded_replied? do |record|
    blk.call(record.data.stream_name)
  end
end
replies(&blk) click to toggle source
# File lib/messaging/write/substitute.rb, line 83
def replies(&blk)
  if blk.nil?
    return sink.replied_records
  end

  sink.replied_records.select do |record|
    blk.call(record.data.message, record.data.stream_name)
  end
end
write(*args, **keyword_args)
Alias for: call
writes(&blk) click to toggle source
# File lib/messaging/write/substitute.rb, line 40
def writes(&blk)
  if blk.nil?
    return sink.written_records
  end

  sink.written_records.select do |record|
    blk.call(record.data.message, record.data.stream_name, record.data.expected_version, record.data.reply_stream_name)
  end
end
written?(message=nil, &blk) click to toggle source
# File lib/messaging/write/substitute.rb, line 50
def written?(message=nil, &blk)
  if message.nil?
    if blk.nil?
      return sink.recorded_written?
    end

    return sink.recorded_written? do |record|
      blk.call(record.data.message, record.data.stream_name, record.data.expected_version, record.data.reply_stream_name)
    end
  end

  written = sink.recorded_written? do |record|
    record.data.message == message
  end

  if !written
    return false
  end

  # Is written and no inspection block is provided,
  # therefore no subsequent inspection beyond the
  # message being found in the telemetry
  # Is written
  if blk.nil?
    return true
  end

  # Otherwise, proceed to subsequent inspecting using the block
  sink.recorded_written? do |record|
    blk.call(record.data.stream_name, record.data.expected_version, record.data.reply_stream_name)
  end
end