Class: Acta::EventsQuery
- Inherits:
-
Object
- Object
- Acta::EventsQuery
- Includes:
- Enumerable
- Defined in:
- lib/acta/events_query.rb
Instance Method Summary collapse
- #all ⇒ Object
- #count ⇒ Object
- #each ⇒ Object
- #find_by_uuid(uuid) ⇒ Object
- #first ⇒ Object
- #for_stream(type:, key:) ⇒ Object
-
#initialize(scope) ⇒ EventsQuery
constructor
A new instance of EventsQuery.
- #last ⇒ Object
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
#all ⇒ Object
21 22 23 |
# File 'lib/acta/events_query.rb', line 21 def all @scope.map { |record| hydrate(record) } end |
#count ⇒ Object
25 26 27 |
# File 'lib/acta/events_query.rb', line 25 def count @scope.count end |
#each ⇒ Object
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 |
#first ⇒ Object
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 |
#last ⇒ Object
9 10 11 |
# File 'lib/acta/events_query.rb', line 9 def last hydrate(@scope.last) end |