Class: FlipperTrail::Recorder

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

Overview

Builds an Entry from a flag change and persists it through the configured storage backend. No-op changes (‘before == after`) and ignored features are dropped.

Instance Method Summary collapse

Instance Method Details

#current_actorActor?

Resolves the actor to attribute a change to, trying the per-request Current actor, then the configured ‘actor_resolver`, then the system actor.

Returns:

  • (Actor, nil)

    the wrapped actor, or nil when none resolves



43
44
45
46
# File 'lib/flipper_trail/recorder.rb', line 43

def current_actor
  raw = Current.actor || config.actor_resolver&.call || config.system_actor
  Actor.wrap(raw)
end

#record(feature_name:, operation:, gate_name:, before:, after:) ⇒ Entry?

Records a single flag change as an audit entry.

Parameters:

  • feature_name (String, Symbol)

    the feature key

  • operation (Symbol)

    the write performed (‘:add`, `:remove`, `:clear`, `:enable`, `:disable`)

  • gate_name (String, Symbol, nil)

    the gate affected, if any

  • before (Object)

    the feature’s gate state before the change

  • after (Object)

    the feature’s gate state after the change

Returns:

  • (Entry, nil)

    the persisted entry, or nil when the change was a no-op or the feature is ignored



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/flipper_trail/recorder.rb', line 21

def record(feature_name:, operation:, gate_name:, before:, after:)
  feature_name = feature_name.to_s
  return if config.ignored_features.map(&:to_s).include?(feature_name)
  return if before == after

  entry = Entry.new(
    feature_name: feature_name,
    operation: operation,
    gate_name: gate_name&.to_s,
    before: before,
    after: after,
    actor: current_actor,
    created_at: Time.now
  ).freeze
  persist(entry)
  entry
end