Class: RubyEventStore::SpecificationResult
- Inherits:
-
Object
- Object
- RubyEventStore::SpecificationResult
- Defined in:
- lib/ruby_event_store/specification_result.rb
Instance Method Summary collapse
-
#==(other_spec) ⇒ TrueClass, FalseClass
Two specification attributess are equal if: * they are of the same class * have identical data (verified with eql? method).
-
#all? ⇒ Boolean
Read strategy.
-
#backward? ⇒ Boolean
Read direction.
-
#batch_size ⇒ Integer
Size of batch to read (only for :batch read strategy) / Find out more.
-
#batched? ⇒ Boolean
Read strategy.
-
#dup {|new_attributes| ... } ⇒ SpecificationResult
Clone [SpecificationResult] If block is given cloned attributes might be modified.
-
#first? ⇒ Boolean
Read strategy.
-
#forward? ⇒ Boolean
Read direction.
-
#hash ⇒ Integer
Generates a Fixnum hash value for this object.
-
#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) ⇒ SpecificationResult
constructor
A new instance of SpecificationResult.
-
#last? ⇒ Boolean
Read strategy.
-
#limit ⇒ Integer|Infinity
Results limit or infinity if limit not defined / Find out more.
-
#limit? ⇒ Boolean
Limited results.
-
#newer_than ⇒ Time
Starting time.
-
#newer_than_or_equal ⇒ Time
Starting time.
-
#older_than ⇒ Time
Ending time.
-
#older_than_or_equal ⇒ Time
Ending time.
-
#start ⇒ String
Starting position.
-
#stop ⇒ String|Symbol
Stop position.
-
#stream ⇒ Stream|nil
Stream definition.
-
#time_sort_by ⇒ Symbol
Time sorting strategy.
-
#time_sort_by_as_at? ⇒ Boolean
Read strategy.
-
#time_sort_by_as_of? ⇒ Boolean
Read strategy.
-
#with_ids ⇒ Array|nil
Ids of specified event to be read (if any given) / Find out more.
-
#with_ids? ⇒ Boolean
Read by specified ids.
-
#with_types ⇒ Array|nil
Event types to be read (if any given) / Find out more.
-
#with_types? ⇒ Boolean
Read by specified event types.
Constructor Details
#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) ⇒ SpecificationResult
Returns a new instance of SpecificationResult.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 |
# 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 |
Instance Method Details
#==(other_spec) ⇒ TrueClass, FalseClass
Two specification attributess are equal if:
-
they are of the same class
-
have identical data (verified with eql? method)
259 260 261 |
# File 'lib/ruby_event_store/specification_result.rb', line 259 def ==(other_spec) other_spec.hash.eql?(hash) end |
#all? ⇒ Boolean
Read strategy. True if all items will be read / Find out more.
222 223 224 |
# File 'lib/ruby_event_store/specification_result.rb', line 222 def all? attributes.read_as.equal?(:all) end |
#backward? ⇒ Boolean
Read direction. True is reading backward / Find out more.
150 151 152 |
# File 'lib/ruby_event_store/specification_result.rb', line 150 def backward? get_direction.equal?(:backward) end |
#batch_size ⇒ Integer
Size of batch to read (only for :batch read strategy) / Find out more.
158 159 160 |
# File 'lib/ruby_event_store/specification_result.rb', line 158 def batch_size attributes.batch_size end |
#batched? ⇒ Boolean
Read strategy. True if items will be read in batches / Find out more.
198 199 200 |
# File 'lib/ruby_event_store/specification_result.rb', line 198 def batched? attributes.read_as.equal?(:batch) end |
#dup {|new_attributes| ... } ⇒ SpecificationResult
Clone [SpecificationResult] If block is given cloned attributes might be modified.
246 247 248 249 250 |
# 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? ⇒ Boolean
Read strategy. True if first item will be read / Find out more.
206 207 208 |
# File 'lib/ruby_event_store/specification_result.rb', line 206 def first? attributes.read_as.equal?(:first) end |
#forward? ⇒ Boolean
Read direction. True is reading forward / Find out more.
142 143 144 |
# File 'lib/ruby_event_store/specification_result.rb', line 142 def forward? get_direction.equal?(:forward) end |
#hash ⇒ Integer
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
-
class
-
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
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# 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? ⇒ Boolean
Read strategy. True if last item will be read / Find out more.
214 215 216 |
# File 'lib/ruby_event_store/specification_result.rb', line 214 def last? attributes.read_as.equal?(:last) end |
#limit ⇒ Integer|Infinity
Results limit or infinity if limit not defined / Find out more.
70 71 72 |
# File 'lib/ruby_event_store/specification_result.rb', line 70 def limit attributes.count || Float::INFINITY end |
#limit? ⇒ Boolean
Limited results. True if number of read elements are limited / Find out more.
62 63 64 |
# File 'lib/ruby_event_store/specification_result.rb', line 62 def limit? !attributes.count.nil? end |
#newer_than ⇒ Time
Starting time. / Find out more.
118 119 120 |
# File 'lib/ruby_event_store/specification_result.rb', line 118 def newer_than attributes.newer_than end |
#newer_than_or_equal ⇒ Time
Starting time. / Find out more.
126 127 128 |
# File 'lib/ruby_event_store/specification_result.rb', line 126 def newer_than_or_equal attributes.newer_than_or_equal end |
#older_than ⇒ Time
Ending time. / Find out more.
102 103 104 |
# File 'lib/ruby_event_store/specification_result.rb', line 102 def older_than attributes.older_than end |
#older_than_or_equal ⇒ Time
Ending time. / Find out more.
110 111 112 |
# File 'lib/ruby_event_store/specification_result.rb', line 110 def older_than_or_equal attributes.older_than_or_equal end |
#start ⇒ String
Starting position. Event id of starting event / Find out more.
86 87 88 |
# File 'lib/ruby_event_store/specification_result.rb', line 86 def start attributes.start end |
#stop ⇒ String|Symbol
Stop position. Event id of stopping event / Find out more.
94 95 96 |
# File 'lib/ruby_event_store/specification_result.rb', line 94 def stop attributes.stop end |
#stream ⇒ Stream|nil
Stream definition. Stream to be read or nil / Find out more.
78 79 80 |
# File 'lib/ruby_event_store/specification_result.rb', line 78 def stream attributes.stream end |
#time_sort_by ⇒ Symbol
Time sorting strategy. Nil when not specified. / Find out more.
134 135 136 |
# File 'lib/ruby_event_store/specification_result.rb', line 134 def time_sort_by attributes.time_sort_by end |
#time_sort_by_as_at? ⇒ Boolean
Read strategy. True if results will be sorted by timestamp / Find out more.
230 231 232 |
# 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? ⇒ Boolean
Read strategy. True if results will be sorted by valid_at / Find out more.
238 239 240 |
# 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 ⇒ Array|nil
Ids of specified event to be read (if any given) / Find out more.
166 167 168 |
# File 'lib/ruby_event_store/specification_result.rb', line 166 def with_ids attributes.with_ids end |
#with_ids? ⇒ Boolean
Read by specified ids. True if event ids have been specified. / Find out more.
174 175 176 |
# File 'lib/ruby_event_store/specification_result.rb', line 174 def with_ids? !with_ids.nil? end |
#with_types ⇒ Array|nil
Event types to be read (if any given) / Find out more.
182 183 184 |
# File 'lib/ruby_event_store/specification_result.rb', line 182 def with_types attributes.with_types&.map(&:to_s) end |
#with_types? ⇒ Boolean
Read by specified event types. True if event types have been specified. / Find out more.
190 191 192 |
# File 'lib/ruby_event_store/specification_result.rb', line 190 def with_types? !(with_types || []).empty? end |