File: configuration.rb

package info (click to toggle)
ruby-flipper 0.13.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,824 kB
  • sloc: ruby: 13,183; sh: 54; makefile: 14
file content (32 lines) | stat: -rw-r--r-- 1,038 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Flipper
  class Configuration
    def initialize
      @default = -> { raise DefaultNotSet }
    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
    #   configuration.default # => raises DefaultNotSet error.
    #
    #   # sets the default block to generate a new instance using Memory adapter
    #   configuration.default do
    #     require "flipper/adapters/memory"
    #     Flipper.new(Flipper::Adapters::Memory.new)
    #   end
    #
    #   configuration.default # => Flipper::DSL instance using Memory adapter
    #
    # Returns result of default block invocation if called without block. If
    # called with block, assigns the default block.
    def default(&block)
      if block_given?
        @default = block
      else
        @default.call
      end
    end
  end
end