Class: FlipperTrail::Configuration
- Inherits:
-
Object
- Object
- FlipperTrail::Configuration
- 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
-
#actor_resolver ⇒ #call?
A zero-arity callable returning the current actor when none is set on Current.
-
#ignored_features ⇒ Array<String, Symbol>
Feature keys whose changes are never recorded.
-
#on_error ⇒ #call?
A callable ‘->(error, entry)` invoked when persisting an audit entry fails (unless #raise_on_audit_error is set).
-
#raise_on_audit_error ⇒ Boolean
When ‘true`, a failed audit write re-raises instead of being swallowed, so the originating flag write fails too (fail-closed).
-
#storage ⇒ Symbol, #record
The audit store.
-
#system_actor ⇒ Hash
The actor attributed to changes when no other actor can be resolved.
Instance Method Summary collapse
-
#infer_storage_from(adapter) ⇒ Object
private
Records the audit store implied by a wrapped Flipper adapter.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #storage_backend ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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.
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_features ⇒ Array<String, Symbol>
Feature keys whose changes are never recorded.
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.
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_error ⇒ Boolean
When ‘true`, a failed audit write re-raises instead of being swallowed, so the originating flag write fails too (fail-closed).
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 |
#storage ⇒ Symbol, #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.
38 39 40 |
# File 'lib/flipper_trail/configuration.rb', line 38 def storage @storage end |
#system_actor ⇒ Hash
The actor attributed to changes when no other actor can be resolved.
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_backend ⇒ Object
60 61 62 |
# File 'lib/flipper_trail/configuration.rb', line 60 def storage_backend @storage_backend ||= build_storage_backend(resolved_storage) end |