Module: Flipflop::Configurable
- Defined in:
- lib/flipflop/configurable.rb
Instance Attribute Summary collapse
-
#current_group ⇒ Object
Returns the value of attribute current_group.
Instance Method Summary collapse
- #feature(feature, **options) ⇒ Object
- #group(group) ⇒ Object
- #strategy(strategy = nil, **options) ⇒ Object
Instance Attribute Details
#current_group ⇒ Object
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, **) = .merge(group: current_group) feature = FeatureDefinition.new(feature, **) 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, **) if block_given? [:name] = strategy.to_s [: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(**) 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 |