Class: Acta::EventsQuery

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/acta/events_query.rb

Instance Method Summary collapse

Constructor Details

#initialize(scope) ⇒ EventsQuery

Returns a new instance of EventsQuery.



5
6
7
# File 'lib/acta/events_query.rb', line 5

def initialize(scope)
  @scope = scope
end

Instance Method Details

#allObject



21
22
23
# File 'lib/acta/events_query.rb', line 21

def all
  @scope.map { |record| hydrate(record) }
end

#countObject



25
26
27
# File 'lib/acta/events_query.rb', line 25

def count
  @scope.count
end

#eachObject



29
30
31
# File 'lib/acta/events_query.rb', line 29

def each(&)
  all.each(&)
end

#find_by_uuid(uuid) ⇒ Object



17
18
19
# File 'lib/acta/events_query.rb', line 17

def find_by_uuid(uuid)
  hydrate(@scope.find_by(uuid:))
end

#firstObject



13
14
15
# File 'lib/acta/events_query.rb', line 13

def first
  hydrate(@scope.first)
end

#for_stream(type:, key:) ⇒ Object



35
36
37
38
39
40
# File 'lib/acta/events_query.rb', line 35

def for_stream(type:, key:)
  filtered = @scope
               .where(stream_type: type.to_s, stream_key: key)
               .reorder(:stream_sequence)
  self.class.new(filtered)
end

#lastObject



9
10
11
# File 'lib/acta/events_query.rb', line 9

def last
  hydrate(@scope.last)
end