Class: MessageStore::Postgres::Get::Stream

Inherits:
Object
  • Object
show all
Includes:
MessageStore::Postgres::Get
Defined in:
lib/message_store/postgres/get/stream.rb,
lib/message_store/postgres/get/stream/last.rb

Defined Under Namespace

Modules: Defaults Classes: Last

Constant Summary collapse

Error =
Class.new(RuntimeError)

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MessageStore::Postgres::Get

#configure, #convert, error_message, #get_result, included, message_data, #raise_error, specialization

Class Method Details

.build(stream_name, batch_size: nil, condition: nil, session: nil) ⇒ Object



16
17
18
19
20
# File 'lib/message_store/postgres/get/stream.rb', line 16

def self.build(stream_name, batch_size: nil, condition: nil, session: nil)
  instance = new(stream_name, batch_size, condition)
  instance.configure(session: session)
  instance
end

.call(stream_name, position: nil, batch_size: nil, condition: nil, session: nil) ⇒ Object



11
12
13
14
# File 'lib/message_store/postgres/get/stream.rb', line 11

def self.call(stream_name, position: nil, batch_size: nil, condition: nil, session: nil)
  instance = build(stream_name, batch_size: batch_size, condition: condition, session: session)
  instance.(position)
end

.configure(receiver, stream_name, attr_name: nil, batch_size: nil, condition: nil, session: nil) ⇒ Object



22
23
24
25
26
# File 'lib/message_store/postgres/get/stream.rb', line 22

def self.configure(receiver, stream_name, attr_name: nil, batch_size: nil, condition: nil, session: nil)
  attr_name ||= :get
  instance = build(stream_name, batch_size: batch_size, condition: condition, session: session)
  receiver.public_send("#{attr_name}=", instance)
end

Instance Method Details

#assureObject



53
54
55
56
57
# File 'lib/message_store/postgres/get/stream.rb', line 53

def assure
  if MessageStore::StreamName.category?(stream_name)
    raise Error, "Must be a stream name (Category: #{stream_name})"
  end
end

#last_position(batch) ⇒ Object



45
46
47
# File 'lib/message_store/postgres/get/stream.rb', line 45

def last_position(batch)
  batch.last.position
end

#log_text(stream_name, position) ⇒ Object



49
50
51
# File 'lib/message_store/postgres/get/stream.rb', line 49

def log_text(stream_name, position)
  "Stream Name: #{stream_name}, Position: #{position.inspect}, Batch Size: #{batch_size.inspect}, Condition: #{condition.inspect})"
end

#parameter_values(stream_name, position) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/message_store/postgres/get/stream.rb', line 36

def parameter_values(stream_name, position)
  [
    stream_name,
    position,
    batch_size,
    condition
  ]
end

#parametersObject



32
33
34
# File 'lib/message_store/postgres/get/stream.rb', line 32

def parameters
  '$1::varchar, $2::bigint, $3::bigint, $4::varchar'
end

#sql_commandObject



28
29
30
# File 'lib/message_store/postgres/get/stream.rb', line 28

def sql_command
  "SELECT * FROM get_stream_messages(#{parameters});"
end