Class: Flipper::Configuration
- Inherits:
-
Object
- Object
- Flipper::Configuration
- Defined in:
- lib/flipper/configuration.rb
Instance Method Summary collapse
-
#adapter(&block) ⇒ Object
The default adapter to use.
-
#default(&block) ⇒ Object
Controls the default instance for flipper.
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #statsd ⇒ Object
- #statsd=(client) ⇒ Object
- #use(klass, *args, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
3 4 5 6 |
# File 'lib/flipper/configuration.rb', line 3 def initialize( = {}) @builder = AdapterBuilder.new { store Flipper::Adapters::Memory } @default = -> { Flipper.new(@builder.to_adapter) } end |
Instance Method Details
#adapter(&block) ⇒ Object
The default adapter to use.
Pass a block to assign the adapter, and invoke without a block to return the configured adapter instance.
Flipper.configure do |config|
config.adapter # => instance of default Memory adapter
# Configure it to use the ActiveRecord adapter
config.adapter do
require "flipper/adapters/active_record"
Flipper::Adapters::ActiveRecord.new
end
config.adapter # => instance of ActiveRecord adapter
end
25 26 27 28 29 30 31 |
# File 'lib/flipper/configuration.rb', line 25 def adapter(&block) if block_given? @builder.store(block) else @builder.to_adapter end end |
#default(&block) ⇒ Object
Controls the default instance for flipper. When used with a block it assigns a new default block to use to generate an instance. When used without a block, it performs a block invocation and returns the result.
configuration = Flipper::Configuration.new
configuration.default # => Flipper::DSL instance using Memory adapter
# sets the default block to generate a new instance using ActiveRecord adapter
configuration.default do
require "flipper/adapters/active_record"
Flipper.new(Flipper::Adapters::ActiveRecord.new)
end
configuration.default # => Flipper::DSL instance using ActiveRecord adapter
Returns result of default block invocation if called without block. If called with block, assigns the default block.
61 62 63 64 65 66 67 |
# File 'lib/flipper/configuration.rb', line 61 def default(&block) if block_given? @default = block else @default.call end end |
#statsd ⇒ Object
69 70 71 72 |
# File 'lib/flipper/configuration.rb', line 69 def statsd require 'flipper/instrumentation/statsd_subscriber' Flipper::Instrumentation::StatsdSubscriber.client end |
#statsd=(client) ⇒ Object
74 75 76 77 |
# File 'lib/flipper/configuration.rb', line 74 def statsd=(client) require "flipper/instrumentation/statsd" Flipper::Instrumentation::StatsdSubscriber.client = client end |
#use(klass, *args, &block) ⇒ Object
35 36 37 |
# File 'lib/flipper/configuration.rb', line 35 def use(klass, *args, **kwargs, &block) @builder.use(klass, *args, **kwargs, &block) end |