lib/flipper/configuration.rb in flipper-1.0.0 vs lib/flipper/configuration.rb in flipper-1.1.0

- old
+ new

@@ -1,10 +1,10 @@ module Flipper class Configuration def initialize(options = {}) - @default = -> { Flipper.new(adapter) } - @adapter = -> { Flipper::Adapters::Memory.new } + @builder = AdapterBuilder.new { store Flipper::Adapters::Memory } + @default = -> { Flipper.new(@builder.to_adapter) } end # The default adapter to use. # # Pass a block to assign the adapter, and invoke without a block to @@ -22,16 +22,27 @@ # config.adapter # => instance of ActiveRecord adapter # end # def adapter(&block) if block_given? - @adapter = block + @builder.store(block) else - @adapter.call + @builder.to_adapter end end + # An adapter to use to augment the primary storage adapter. See `AdapterBuilder#use` + if RUBY_VERSION >= '3.0' + def use(klass, *args, **kwargs, &block) + @builder.use(klass, *args, **kwargs, &block) + end + else + def use(klass, *args, &block) + @builder.use(klass, *args, &block) + end + end + # 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 @@ -51,8 +62,18 @@ if block_given? @default = block else @default.call end + end + + def statsd + require 'flipper/instrumentation/statsd_subscriber' + Flipper::Instrumentation::StatsdSubscriber.client + end + + def statsd=(client) + require "flipper/instrumentation/statsd" + Flipper::Instrumentation::StatsdSubscriber.client = client end end end