class EventSource::Get::Substitute
Public Class Methods
build(batch_size: nil, session: nil)
click to toggle source
# File lib/event_source/get.rb, line 24 def self.build(batch_size: nil, session: nil) new(batch_size) end
Public Instance Methods
batch_size()
click to toggle source
# File lib/event_source/get.rb, line 16 def batch_size @batch_size ||= 1 end
call(stream_name=nil, position: nil)
click to toggle source
# File lib/event_source/get.rb, line 28 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 EventSource::StreamName.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
items()
click to toggle source
# File lib/event_source/get.rb, line 20 def items @items ||= [] end