Module: Flipflop::Configurable

Defined in:
lib/flipflop/configurable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_groupObject

Returns the value of attribute current_group.



3
4
5
# File 'lib/flipflop/configurable.rb', line 3

def current_group
  @current_group
end

Instance Method Details

#feature(feature, **options) ⇒ Object



12
13
14
15
16
# File 'lib/flipflop/configurable.rb', line 12

def feature(feature, **options)
  options = options.merge(group: current_group)
  feature = FeatureDefinition.new(feature, **options)
  FeatureSet.current.add(feature)
end

#group(group) ⇒ Object



5
6
7
8
9
10
# File 'lib/flipflop/configurable.rb', line 5

def group(group)
  self.current_group = GroupDefinition.new(group)
  yield
ensure
  self.current_group = nil
end

#strategy(strategy = nil, **options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/flipflop/configurable.rb', line 18

def strategy(strategy = nil, **options)
  if block_given?
    options[:name] = strategy.to_s
    options[:lambda] = Proc.new
    strategy = Strategies::LambdaStrategy
  end

  if strategy.kind_of?(Symbol)
    name = ActiveSupport::Inflector.camelize(strategy) + "Strategy"
    strategy = Strategies.const_get(name)
  end

  if strategy.kind_of?(Class)
    strategy = strategy.new(**options)
  end

  FeatureSet.current.use(strategy)
rescue StandardError => err
  if FeatureSet.current.raise_strategy_errors
    raise err
  else
    warn "WARNING: Unable to load Flipflop strategy #{strategy}: #{err}"
  end
end