Class: Dbwatcher::Storage::SessionQuery
- Inherits:
-
Object
- Object
- Dbwatcher::Storage::SessionQuery
- Defined in:
- lib/dbwatcher/storage/session_query.rb
Instance Method Summary collapse
- #all ⇒ Object
- #create(session) ⇒ Object
- #find(id) ⇒ Object
-
#initialize(storage) ⇒ SessionQuery
constructor
A new instance of SessionQuery.
- #limit(count) ⇒ Object
- #recent(days: 7) ⇒ Object
- #where(conditions) ⇒ Object
- #with_changes ⇒ Object
Constructor Details
#initialize(storage) ⇒ SessionQuery
Returns a new instance of SessionQuery.
8 9 10 11 12 |
# File 'lib/dbwatcher/storage/session_query.rb', line 8 def initialize(storage) @storage = storage @conditions = {} @limit_value = nil end |
Instance Method Details
#all ⇒ Object
18 19 20 |
# File 'lib/dbwatcher/storage/session_query.rb', line 18 def all apply_filters(@storage.all) end |
#create(session) ⇒ Object
37 38 39 |
# File 'lib/dbwatcher/storage/session_query.rb', line 37 def create(session) @storage.save(session) end |
#find(id) ⇒ Object
14 15 16 |
# File 'lib/dbwatcher/storage/session_query.rb', line 14 def find(id) @storage.load(id) end |
#limit(count) ⇒ Object
27 28 29 30 |
# File 'lib/dbwatcher/storage/session_query.rb', line 27 def limit(count) @limit_value = count self end |
#recent(days: 7) ⇒ Object
32 33 34 35 |
# File 'lib/dbwatcher/storage/session_query.rb', line 32 def recent(days: 7) cutoff = Time.now - (days * 24 * 60 * 60) where(started_after: cutoff) end |
#where(conditions) ⇒ Object
22 23 24 25 |
# File 'lib/dbwatcher/storage/session_query.rb', line 22 def where(conditions) @conditions.merge!(conditions) self end |
#with_changes ⇒ Object
41 42 43 |
# File 'lib/dbwatcher/storage/session_query.rb', line 41 def with_changes all.select { |s| @storage.load(s[:id])&.changes&.any? } end |