Class: FlipperTrail::Storage::Mongoid

Inherits:
Object
  • Object
show all
Defined in:
lib/flipper_trail/storage/mongoid.rb

Defined Under Namespace

Classes: Entry

Instance Method Summary collapse

Instance Method Details

#query(feature: nil, actor_id: nil, since: nil, until_time: nil, limit: 100) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/flipper_trail/storage/mongoid.rb', line 44

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.gte(created_at: since) if since
  scope = scope.lte(created_at: until_time) if until_time
  # _id DESC is a deterministic tiebreaker (BSON ObjectId is creation-ordered)
  # so equal-timestamp bursts stay newest-first.
  scope.order_by(created_at: :desc, _id: :desc).limit(limit).map { |doc| to_entry(doc) }
end

#record(entry) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/flipper_trail/storage/mongoid.rb', line 30

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