Class: Flipper::Feature
- Inherits:
-
Object
- Object
- Flipper::Feature
- Defined in:
- lib/flipper/feature.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #disable(thing = Types::Boolean.new) ⇒ Object
- #disabled?(actor = nil) ⇒ Boolean
- #enable(thing = Types::Boolean.new) ⇒ Object
- #enabled?(actor = nil) ⇒ Boolean
-
#gate_for(thing) ⇒ Object
Internal: Returns gate that protects thing.
-
#gates ⇒ Object
Internal: Gates to check to see if feature is enabled/disabled.
-
#initialize(name, adapter) ⇒ Feature
constructor
A new instance of Feature.
Constructor Details
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
10 11 12 |
# File 'lib/flipper/feature.rb', line 10 def adapter @adapter end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/flipper/feature.rb', line 9 def name @name end |
Instance Method Details
#disable(thing = Types::Boolean.new) ⇒ Object
21 22 23 |
# File 'lib/flipper/feature.rb', line 21 def disable(thing = Types::Boolean.new) gate_for(thing).disable(thing) end |
#disabled?(actor = nil) ⇒ Boolean
29 30 31 |
# File 'lib/flipper/feature.rb', line 29 def disabled?(actor = nil) !enabled?(actor) end |
#enable(thing = Types::Boolean.new) ⇒ Object
17 18 19 |
# File 'lib/flipper/feature.rb', line 17 def enable(thing = Types::Boolean.new) gate_for(thing).enable(thing) end |
#enabled?(actor = nil) ⇒ Boolean
25 26 27 |
# File 'lib/flipper/feature.rb', line 25 def enabled?(actor = nil) !! catch(:short_circuit) { gates.detect { |gate| gate.open?(actor) } } end |
#gate_for(thing) ⇒ Object
Internal: Returns gate that protects thing
thing - The object for which you would like to find a gate
Raises Flipper::GateNotFound if no gate found for thing
51 52 53 |
# File 'lib/flipper/feature.rb', line 51 def gate_for(thing) find_gate(thing) || raise(GateNotFound.new(thing)) end |
#gates ⇒ Object
Internal: Gates to check to see if feature is enabled/disabled
Returns an array of gates
36 37 38 39 40 41 42 43 44 |
# File 'lib/flipper/feature.rb', line 36 def gates @gates ||= [ Gates::Boolean.new(self), Gates::Group.new(self), Gates::Actor.new(self), Gates::PercentageOfActors.new(self), Gates::PercentageOfRandom.new(self), ] end |