Class: FlipperTrail::Configuration

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

Overview

Holds the global settings for the gem. Mutate it through configure.

Constant Summary collapse

INFERRED_STORAGE =

Maps a wrapped Flipper adapter’s class name to the audit store it implies.

{
  'Flipper::Adapters::ActiveRecord' => :active_record,
  'Flipper::Adapters::Mongo' => :mongoid
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



41
42
43
44
45
46
47
48
49
# File 'lib/flipper_trail/configuration.rb', line 41

def initialize
  @storage = :auto
  @actor_resolver = nil
  @system_actor = { type: 'system', id: nil, label: 'system' }
  @ignored_features = []
  @on_error = nil
  @raise_on_audit_error = false
  @inferred_storage = nil
end

Instance Attribute Details

#actor_resolver#call?

A zero-arity callable returning the current actor when none is set on FlipperTrail::Current. It must take no arguments because it is also invoked off-request (console, background jobs) where there is no Rack env.

Returns:

  • (#call, nil)


38
39
# File 'lib/flipper_trail/configuration.rb', line 38

attr_accessor :storage, :actor_resolver, :system_actor, :ignored_features,
:on_error, :raise_on_audit_error

#ignored_featuresArray<String, Symbol>

Feature keys whose changes are never recorded.

Returns:

  • (Array<String, Symbol>)


38
39
# File 'lib/flipper_trail/configuration.rb', line 38

attr_accessor :storage, :actor_resolver, :system_actor, :ignored_features,
:on_error, :raise_on_audit_error

#on_error#call?

A callable ‘->(error, entry)` invoked when persisting an audit entry fails (unless #raise_on_audit_error is set). Defaults to warning on stderr.

Returns:

  • (#call, nil)


38
39
# File 'lib/flipper_trail/configuration.rb', line 38

attr_accessor :storage, :actor_resolver, :system_actor, :ignored_features,
:on_error, :raise_on_audit_error

#raise_on_audit_errorBoolean

When ‘true`, a failed audit write re-raises instead of being swallowed, so the originating flag write fails too (fail-closed).

Returns:

  • (Boolean)


38
39
# File 'lib/flipper_trail/configuration.rb', line 38

attr_accessor :storage, :actor_resolver, :system_actor, :ignored_features,
:on_error, :raise_on_audit_error

#storageSymbol, #record

The audit store. Defaults to ‘:auto`, which is inferred from the Flipper adapter you wrap (`ActiveRecord` → `:active_record`, `Mongo` → `:mongoid`). Set it to `:active_record`, `:mongoid`, or any object responding to `#record`/`#query` to override the inference.

Returns:

  • (Symbol, #record)


38
39
40
# File 'lib/flipper_trail/configuration.rb', line 38

def storage
  @storage
end

#system_actorHash

The actor attributed to changes when no other actor can be resolved.

Returns:

  • (Hash)


38
39
# File 'lib/flipper_trail/configuration.rb', line 38

attr_accessor :storage, :actor_resolver, :system_actor, :ignored_features,
:on_error, :raise_on_audit_error

Instance Method Details

#infer_storage_from(adapter) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Records the audit store implied by a wrapped Flipper adapter. Used only when ‘storage` is left as :auto; an explicit `storage` always takes precedence.



54
55
56
57
58
# File 'lib/flipper_trail/configuration.rb', line 54

def infer_storage_from(adapter)
  return unless storage == :auto

  @inferred_storage = INFERRED_STORAGE.fetch(adapter.class.name, :unknown)
end

#storage_backendObject



60
61
62
# File 'lib/flipper_trail/configuration.rb', line 60

def storage_backend
  @storage_backend ||= build_storage_backend(resolved_storage)
end