Class: MessageStore::Get::Substitute

Inherits:
Object
  • Object
show all
Includes:
Initializer, MessageStore::Get, Virtual
Defined in:
lib/message_store/get.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MessageStore::Get

included

Class Method Details

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



30
31
32
# File 'lib/message_store/get.rb', line 30

def self.build(batch_size: nil, session: nil)
  new(batch_size)
end

.category?(stream_name) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/message_store/get.rb', line 66

def self.category?(stream_name)
  !stream_name.include?('-')
end

Instance Method Details

#batch_sizeObject



22
23
24
# File 'lib/message_store/get.rb', line 22

def batch_size
  @batch_size ||= 1
end

#call(stream_name = nil, position: nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/message_store/get.rb', line 34

def call(stream_name=nil, position: nil)
  position ||= 0

  logger.trace(tag: :control) { "Getting (Position: #{position}, Batch Size: #{batch_size}, Stream Name: #{stream_name.inspect})" }

  logger.debug(tags: [:control, :data]) { "Items: \n#{items.pretty_inspect}" }
  logger.debug(tag: :control) { "Position: #{position.inspect}" }
  logger.debug(tag: :control) { "Batch Size: #{batch_size.inspect}" }

  unless self.class.category?(stream_name)
    index = (items.index { |i| i.position >= position })
  else
    index = (items.index { |i| i.global_position >= position })
  end

  logger.debug(tag: :control) { "Index: #{index.inspect}" }

  if index.nil?
    items = []
  else
    range = index..(index + batch_size - 1)
    logger.debug(tag: :control) { "Range: #{range.pretty_inspect}" }

    items = self.items[range]
  end

  logger.info(tags: [:control, :data]) { "Got: \n#{items.pretty_inspect}" }
  logger.info(tag: :control) { "Finished getting (Position: #{position}, Stream Name: #{stream_name.inspect})" }

  items
end

#itemsObject



26
27
28
# File 'lib/message_store/get.rb', line 26

def items
  @items ||= []
end