Class: MessageStore::Get::Substitute
- Inherits:
-
Object
- Object
- MessageStore::Get::Substitute
- Includes:
- Initializer, MessageStore::Get, TemplateMethod
- Defined in:
- lib/message_store/get/substitute.rb
Instance Attribute Summary collapse
- #batch_size ⇒ Object
-
#stream_name ⇒ Object
(also: #category)
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
12 13 14 |
# File 'lib/message_store/get/substitute.rb', line 12 def batch_size @batch_size ||= 1 end |
#stream_name ⇒ Object Also known as: category
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
21 22 23 |
# File 'lib/message_store/get/substitute.rb', line 21 def self.build new end |
.category_stream?(stream_name) ⇒ Boolean
68 69 70 |
# File 'lib/message_store/get/substitute.rb', line 68 def self.category_stream?(stream_name) StreamName.category?(stream_name) end |
Instance Method Details
#call(position) ⇒ Object
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 58 |
# File 'lib/message_store/get/substitute.rb', line 25 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
17 18 19 |
# File 'lib/message_store/get/substitute.rb', line 17 def items @items ||= [] end |
#last_position(batch) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/message_store/get/substitute.rb', line 60 def last_position(batch) if self.class.category_stream?(stream_name) batch.last.global_position else batch.last.position end end |