class RubyEventStore::SpecificationResult

Attributes

attributes[R]

Public Class Methods

new( direction: :forward, start: nil, stop: nil, older_than: nil, older_than_or_equal: nil, newer_than: nil, newer_than_or_equal: nil, time_sort_by: nil, count: nil, stream: Stream.new(GLOBAL_STREAM), read_as: :all, batch_size: Specification::DEFAULT_BATCH_SIZE, with_ids: nil, with_types: nil ) click to toggle source
# File lib/ruby_event_store/specification_result.rb, line 5
def initialize(
  direction: :forward,
  start: nil,
  stop: nil,
  older_than: nil,
  older_than_or_equal: nil,
  newer_than: nil,
  newer_than_or_equal: nil,
  time_sort_by: nil,
  count: nil,
  stream: Stream.new(GLOBAL_STREAM),
  read_as: :all,
  batch_size: Specification::DEFAULT_BATCH_SIZE,
  with_ids: nil,
  with_types: nil
)
  @attributes =
    Struct
      .new(
        :direction,
        :start,
        :stop,
        :older_than,
        :older_than_or_equal,
        :newer_than,
        :newer_than_or_equal,
        :time_sort_by,
        :count,
        :stream,
        :read_as,
        :batch_size,
        :with_ids,
        :with_types
      )
      .new(
        direction,
        start,
        stop,
        older_than,
        older_than_or_equal,
        newer_than,
        newer_than_or_equal,
        time_sort_by,
        count,
        stream,
        read_as,
        batch_size,
        with_ids,
        with_types
      )
  freeze
end

Public Instance Methods

==(other_spec) click to toggle source

Two specification attributess are equal if:

  • they are of the same class

  • have identical data (verified with eql? method)

@param other_spec [SpecificationResult, Object] object to compare

@return [TrueClass, FalseClass]

# File lib/ruby_event_store/specification_result.rb, line 259
def ==(other_spec)
  other_spec.hash.eql?(hash)
end
all?() click to toggle source

Read strategy. True if all items will be read {railseventstore.org/docs/read/ Find out more}.

@return [Boolean]

# File lib/ruby_event_store/specification_result.rb, line 222
def all?
  attributes.read_as.equal?(:all)
end
backward?() click to toggle source

Read direction. True is reading backward {railseventstore.org/docs/read/ Find out more}.

@return [Boolean]

# File lib/ruby_event_store/specification_result.rb, line 150
def backward?
  get_direction.equal?(:backward)
end
batch_size() click to toggle source

Size of batch to read (only for :batch read strategy) {railseventstore.org/docs/read/ Find out more}.

@return [Integer]

# File lib/ruby_event_store/specification_result.rb, line 158
def batch_size
  attributes.batch_size
end
batched?() click to toggle source

Read strategy. True if items will be read in batches {railseventstore.org/docs/read/ Find out more}.

@return [Boolean]

# File lib/ruby_event_store/specification_result.rb, line 198
def batched?
  attributes.read_as.equal?(:batch)
end
dup() { |new_attributes| ... } click to toggle source

Clone [SpecificationResult] If block is given cloned attributes might be modified.

@return [SpecificationResult]

# File lib/ruby_event_store/specification_result.rb, line 246
def dup
  new_attributes = attributes.dup
  yield new_attributes if block_given?
  SpecificationResult.new(**new_attributes.to_h)
end
first?() click to toggle source

Read strategy. True if first item will be read {railseventstore.org/docs/read/ Find out more}.

@return [Boolean]

# File lib/ruby_event_store/specification_result.rb, line 206
def first?
  attributes.read_as.equal?(:first)
end
forward?() click to toggle source

Read direction. True is reading forward {railseventstore.org/docs/read/ Find out more}.

@return [Boolean]

# File lib/ruby_event_store/specification_result.rb, line 142
def forward?
  get_direction.equal?(:forward)
end
hash() click to toggle source

Generates a Fixnum hash value for this object. This function have the property that a.eql?(b) implies a.hash == b.hash.

The hash value is used along with eql? by the Hash class to determine if two objects reference the same hash key.

This hash is based on

@return [Integer]

# File lib/ruby_event_store/specification_result.rb, line 287
def hash
  [
    get_direction,
    start,
    stop,
    older_than,
    older_than_or_equal,
    newer_than,
    newer_than_or_equal,
    time_sort_by,
    limit,
    stream,
    attributes.read_as,
    batch_size,
    with_ids,
    with_types
  ].hash ^ self.class.hash
end
last?() click to toggle source

Read strategy. True if last item will be read {railseventstore.org/docs/read/ Find out more}.

@return [Boolean]

# File lib/ruby_event_store/specification_result.rb, line 214
def last?
  attributes.read_as.equal?(:last)
end
limit() click to toggle source

Results limit or infinity if limit not defined {railseventstore.org/docs/read/ Find out more}.

@return [Integer|Infinity]

# File lib/ruby_event_store/specification_result.rb, line 70
def limit
  attributes.count || Float::INFINITY
end
limit?() click to toggle source

Limited results. True if number of read elements are limited {railseventstore.org/docs/read/ Find out more}.

@return [Boolean]

# File lib/ruby_event_store/specification_result.rb, line 62
def limit?
  !attributes.count.nil?
end
newer_than() click to toggle source

Starting time. {railseventstore.org/docs/read/ Find out more}.

@return [Time]

# File lib/ruby_event_store/specification_result.rb, line 118
def newer_than
  attributes.newer_than
end
newer_than_or_equal() click to toggle source

Starting time. {railseventstore.org/docs/read/ Find out more}.

@return [Time]

# File lib/ruby_event_store/specification_result.rb, line 126
def newer_than_or_equal
  attributes.newer_than_or_equal
end
older_than() click to toggle source

Ending time. {railseventstore.org/docs/read/ Find out more}.

@return [Time]

# File lib/ruby_event_store/specification_result.rb, line 102
def older_than
  attributes.older_than
end
older_than_or_equal() click to toggle source

Ending time. {railseventstore.org/docs/read/ Find out more}.

@return [Time]

# File lib/ruby_event_store/specification_result.rb, line 110
def older_than_or_equal
  attributes.older_than_or_equal
end
start() click to toggle source

Starting position. Event id of starting event {railseventstore.org/docs/read/ Find out more}.

@return [String]

# File lib/ruby_event_store/specification_result.rb, line 86
def start
  attributes.start
end
stop() click to toggle source

Stop position. Event id of stopping event {railseventstore.org/docs/read/ Find out more}.

@return [String|Symbol]

# File lib/ruby_event_store/specification_result.rb, line 94
def stop
  attributes.stop
end
stream() click to toggle source

Stream definition. Stream to be read or nil {railseventstore.org/docs/read/ Find out more}.

@return [Stream|nil]

# File lib/ruby_event_store/specification_result.rb, line 78
def stream
  attributes.stream
end
time_sort_by() click to toggle source

Time sorting strategy. Nil when not specified. {railseventstore.org/docs/read/ Find out more}.

@return [Symbol]

# File lib/ruby_event_store/specification_result.rb, line 134
def time_sort_by
  attributes.time_sort_by
end
time_sort_by_as_at?() click to toggle source

Read strategy. True if results will be sorted by timestamp {railseventstore.org/docs/read/ Find out more}.

@return [Boolean]

# File lib/ruby_event_store/specification_result.rb, line 230
def time_sort_by_as_at?
  time_sort_by.equal?(:as_at)
end
time_sort_by_as_of?() click to toggle source

Read strategy. True if results will be sorted by valid_at {railseventstore.org/docs/read/ Find out more}.

@return [Boolean]

# File lib/ruby_event_store/specification_result.rb, line 238
def time_sort_by_as_of?
  time_sort_by.equal?(:as_of)
end
with_ids() click to toggle source

Ids of specified event to be read (if any given) {railseventstore.org/docs/read/ Find out more}.

@return [Array|nil]

# File lib/ruby_event_store/specification_result.rb, line 166
def with_ids
  attributes.with_ids
end
with_ids?() click to toggle source

Read by specified ids. True if event ids have been specified. {railseventstore.org/docs/read/ Find out more}.

@return [Boolean]

# File lib/ruby_event_store/specification_result.rb, line 174
def with_ids?
  !with_ids.nil?
end
with_types() click to toggle source

Event types to be read (if any given) {railseventstore.org/docs/read/ Find out more}.

@return [Array|nil]

# File lib/ruby_event_store/specification_result.rb, line 182
def with_types
  attributes.with_types&.map(&:to_s)
end
with_types?() click to toggle source

Read by specified event types. True if event types have been specified. {railseventstore.org/docs/read/ Find out more}.

@return [Boolean]

# File lib/ruby_event_store/specification_result.rb, line 190
def with_types?
  !(with_types || []).empty?
end

Private Instance Methods

get_direction() click to toggle source
# File lib/ruby_event_store/specification_result.rb, line 310
def get_direction
  attributes.direction
end