Class: RubyEventStore::SpecificationResult

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_event_store/specification_result.rb

Instance Method Summary collapse

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
# 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)

Parameters:

Returns:

  • (TrueClass, FalseClass)


257
258
259
# File 'lib/ruby_event_store/specification_result.rb', line 257

def ==(other_spec)
  other_spec.hash.eql?(hash)
end

#all?Boolean

Read strategy. True if all items will be read / Find out more.

Returns:

  • (Boolean)


220
221
222
# File 'lib/ruby_event_store/specification_result.rb', line 220

def all?
  attributes.read_as.equal?(:all)
end

#backward?Boolean

Read direction. True is reading backward / Find out more.

Returns:

  • (Boolean)


148
149
150
# File 'lib/ruby_event_store/specification_result.rb', line 148

def backward?
  get_direction.equal?(:backward)
end

#batch_sizeInteger

Size of batch to read (only for :batch read strategy) / Find out more.

Returns:

  • (Integer)


156
157
158
# File 'lib/ruby_event_store/specification_result.rb', line 156

def batch_size
  attributes.batch_size
end

#batched?Boolean

Read strategy. True if items will be read in batches / Find out more.

Returns:

  • (Boolean)


196
197
198
# File 'lib/ruby_event_store/specification_result.rb', line 196

def batched?
  attributes.read_as.equal?(:batch)
end

#dup {|new_attributes| ... } ⇒ SpecificationResult

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

Yields:

  • (new_attributes)

Returns:



244
245
246
247
248
# File 'lib/ruby_event_store/specification_result.rb', line 244

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.

Returns:

  • (Boolean)


204
205
206
# File 'lib/ruby_event_store/specification_result.rb', line 204

def first?
  attributes.read_as.equal?(:first)
end

#forward?Boolean

Read direction. True is reading forward / Find out more.

Returns:

  • (Boolean)


140
141
142
# File 'lib/ruby_event_store/specification_result.rb', line 140

def forward?
  get_direction.equal?(:forward)
end

#hashInteger

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

Returns:

  • (Integer)


285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/ruby_event_store/specification_result.rb', line 285

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.

Returns:

  • (Boolean)


212
213
214
# File 'lib/ruby_event_store/specification_result.rb', line 212

def last?
  attributes.read_as.equal?(:last)
end

#limitInteger|Infinity

Results limit or infinity if limit not defined / Find out more.

Returns:

  • (Integer|Infinity)


68
69
70
# File 'lib/ruby_event_store/specification_result.rb', line 68

def limit
  attributes.count || Float::INFINITY
end

#limit?Boolean

Limited results. True if number of read elements are limited / Find out more.

Returns:

  • (Boolean)


60
61
62
# File 'lib/ruby_event_store/specification_result.rb', line 60

def limit?
  !attributes.count.nil?
end

#newer_thanTime

Starting time. / Find out more.

Returns:

  • (Time)


116
117
118
# File 'lib/ruby_event_store/specification_result.rb', line 116

def newer_than
  attributes.newer_than
end

#newer_than_or_equalTime

Starting time. / Find out more.

Returns:

  • (Time)


124
125
126
# File 'lib/ruby_event_store/specification_result.rb', line 124

def newer_than_or_equal
  attributes.newer_than_or_equal
end

#older_thanTime

Ending time. / Find out more.

Returns:

  • (Time)


100
101
102
# File 'lib/ruby_event_store/specification_result.rb', line 100

def older_than
  attributes.older_than
end

#older_than_or_equalTime

Ending time. / Find out more.

Returns:

  • (Time)


108
109
110
# File 'lib/ruby_event_store/specification_result.rb', line 108

def older_than_or_equal
  attributes.older_than_or_equal
end

#startString

Starting position. Event id of starting event / Find out more.

Returns:

  • (String)


84
85
86
# File 'lib/ruby_event_store/specification_result.rb', line 84

def start
  attributes.start
end

#stopString|Symbol

Stop position. Event id of stopping event / Find out more.

Returns:

  • (String|Symbol)


92
93
94
# File 'lib/ruby_event_store/specification_result.rb', line 92

def stop
  attributes.stop
end

#streamStream|nil

Stream definition. Stream to be read or nil / Find out more.

Returns:



76
77
78
# File 'lib/ruby_event_store/specification_result.rb', line 76

def stream
  attributes.stream
end

#time_sort_bySymbol

Time sorting strategy. Nil when not specified. / Find out more.

Returns:

  • (Symbol)


132
133
134
# File 'lib/ruby_event_store/specification_result.rb', line 132

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.

Returns:

  • (Boolean)


228
229
230
# File 'lib/ruby_event_store/specification_result.rb', line 228

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.

Returns:

  • (Boolean)


236
237
238
# File 'lib/ruby_event_store/specification_result.rb', line 236

def time_sort_by_as_of?
  time_sort_by.equal?(:as_of)
end

#with_idsArray|nil

Ids of specified event to be read (if any given) / Find out more.

Returns:

  • (Array|nil)


164
165
166
# File 'lib/ruby_event_store/specification_result.rb', line 164

def with_ids
  attributes.with_ids
end

#with_ids?Boolean

Read by specified ids. True if event ids have been specified. / Find out more.

Returns:

  • (Boolean)


172
173
174
# File 'lib/ruby_event_store/specification_result.rb', line 172

def with_ids?
  !with_ids.nil?
end

#with_typesArray|nil

Event types to be read (if any given) / Find out more.

Returns:

  • (Array|nil)


180
181
182
# File 'lib/ruby_event_store/specification_result.rb', line 180

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.

Returns:

  • (Boolean)


188
189
190
# File 'lib/ruby_event_store/specification_result.rb', line 188

def with_types?
  !(with_types || []).empty?
end