Module: MessageStore::Postgres::Controls::Put

Defined in:
lib/message_store/postgres/controls/put.rb

Class Method Summary collapse

Class Method Details

.call(instances: nil, stream_name: nil, message_data: nil, message: nil, category: nil, type: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/message_store/postgres/controls/put.rb', line 5

def self.call(instances: nil, stream_name: nil, message_data: nil, message: nil, category: nil, type: nil)
  instances ||= 1
  stream_name ||= StreamName.example(category: category)
  message_data ||= message

  message_specified = !message_data.nil?

  message_data ||= MessageData::Write.example(type: type)

  position = nil
  instances.times do
    position = MessageStore::Postgres::Put.(message_data, stream_name)

    unless message_specified
      message_data.id = MessageData::Write.id
    end
  end

  [stream_name, position]
end