Class: MessageStore::Get::Substitute

Inherits:
Object
  • Object
show all
Includes:
MessageStore::Get
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



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

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

.category?(stream_name) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/message_store/get.rb', line 63

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

Instance Method Details

#batch_sizeObject



19
20
21
# File 'lib/message_store/get.rb', line 19

def batch_size
  @batch_size ||= 1
end

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



31
32
33
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
# File 'lib/message_store/get.rb', line 31

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



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

def items
  @items ||= []
end