lib/flipper/configuration.rb in flipper-0.21.0.rc1 vs lib/flipper/configuration.rb in flipper-0.21.0.rc2
- old
+ new
@@ -1,8 +1,34 @@
module Flipper
class Configuration
- def initialize
- @default = -> { Flipper.new(Flipper::Adapters::Memory.new) }
+ def initialize(options = {})
+ @default = -> { Flipper.new(adapter) }
+ @adapter = -> { Flipper::Adapters::Memory.new }
+ end
+
+ # 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-active_record"
+ # Flipper::Adapters::ActiveRecord.new
+ # end
+ #
+ # config.adapter # => instance of ActiveRecord adapter
+ # end
+ #
+ def adapter(&block)
+ if block_given?
+ @adapter = block
+ else
+ @adapter.call
+ 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.