Class: FlipperTrail::Storage::ActiveRecord
- Inherits:
-
Object
- Object
- FlipperTrail::Storage::ActiveRecord
- Defined in:
- lib/flipper_trail/storage/active_record.rb
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
- #query(feature: nil, actor_id: nil, since: nil, until_time: nil, limit: 100) ⇒ Object
- #record(entry) ⇒ Object
Instance Method Details
#query(feature: nil, actor_id: nil, since: nil, until_time: nil, limit: 100) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/flipper_trail/storage/active_record.rb', line 28 def query(feature: nil, actor_id: nil, since: nil, until_time: nil, limit: 100) scope = Entry.all scope = scope.where(feature_name: feature.to_s) if feature scope = scope.where(actor_id: actor_id.to_s) if actor_id scope = scope.where(arel_table[:created_at].gteq(since)) if since scope = scope.where(arel_table[:created_at].lteq(until_time)) if until_time # id DESC is a deterministic tiebreaker so bursts with equal created_at stay newest-first. scope.order(created_at: :desc, id: :desc).limit(limit).map { |row| to_entry(row) } end |
#record(entry) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/flipper_trail/storage/active_record.rb', line 14 def record(entry) Entry.create!( feature_name: entry.feature_name, operation: entry.operation.to_s, gate_name: entry.gate_name, before_state: entry.before, after_state: entry.after, actor_type: entry.actor&.type, actor_id: entry.actor&.id, actor_label: entry.actor&.label, created_at: entry.created_at ) end |