Class: Flipper::Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/flipper/feature.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, adapter) ⇒ Feature

Returns a new instance of Feature.



12
13
14
15
# File 'lib/flipper/feature.rb', line 12

def initialize(name, adapter)
  @name = name
  @adapter = Adapter.wrap(adapter)
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



10
11
12
# File 'lib/flipper/feature.rb', line 10

def adapter
  @adapter
end

#nameObject (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

Returns:

  • (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

Returns:

  • (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

#gatesObject

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