Class: MessageStore::Get::Substitute
- Inherits:
-
Object
- Object
- MessageStore::Get::Substitute
- Includes:
- Initializer, MessageStore::Get, Virtual
- Defined in:
- lib/message_store/get/substitute.rb
Instance Attribute Summary collapse
- #batch_size ⇒ Object
-
#stream_name ⇒ Object
Returns the value of attribute stream_name.
Class Method Summary collapse
Instance Method Summary collapse
Methods included from MessageStore::Get
Instance Attribute Details
#batch_size ⇒ Object
11 12 13 |
# File 'lib/message_store/get/substitute.rb', line 11 def batch_size @batch_size ||= 1 end |
#stream_name ⇒ Object
Returns the value of attribute stream_name.
9 10 11 |
# File 'lib/message_store/get/substitute.rb', line 9 def stream_name @stream_name end |
Class Method Details
.build ⇒ Object
20 21 22 |
# File 'lib/message_store/get/substitute.rb', line 20 def self.build new end |
.category_stream?(stream_name) ⇒ Boolean
67 68 69 |
# File 'lib/message_store/get/substitute.rb', line 67 def self.category_stream?(stream_name) StreamName.category?(stream_name) end |
Instance Method Details
#call(position) ⇒ Object
24 25 26 27 28 29 30 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 |
# File 'lib/message_store/get/substitute.rb', line 24 def call(position) position ||= 0 logger.trace(tag: :get) { "Getting (Position: #{position}, Stream Name: #{stream_name.inspect}, Batch Size: #{batch_size})" } logger.debug(tag: :data) { "Items: \n#{items.pretty_inspect}" } logger.debug(tag: :data) { "Position: #{position.inspect}" } logger.debug(tag: :data) { "Batch Size: #{batch_size.inspect}" } # No specialized Gets for substitute # Complexity has to be inline for the control # Scott, Tue Oct 1 2019 unless self.class.category_stream?(stream_name) index = (items.index { |i| i.position >= position }) else index = (items.index { |i| i.global_position >= position }) end logger.debug(tag: :data) { "Index: #{index.inspect}" } if index.nil? items = [] else range = index..(index + batch_size - 1) logger.debug(tag: :data) { "Range: #{range.pretty_inspect}" } items = self.items[range] end logger.info(tag: :data) { "Got: \n#{items.pretty_inspect}" } logger.info(tag: :get) { "Finished getting (Position: #{position}, Stream Name: #{stream_name.inspect})" } items end |
#items ⇒ Object
16 17 18 |
# File 'lib/message_store/get/substitute.rb', line 16 def items @items ||= [] end |
#last_position(batch) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/message_store/get/substitute.rb', line 59 def last_position(batch) if self.class.category_stream?(stream_name) batch.last.global_position else batch.last.position end end |