Class: Flipper::Gates::Boolean

Inherits:
Flipper::Gate show all
Defined in:
lib/flipper/gates/boolean.rb

Constant Summary collapse

TruthMap =
{
  true    => true,
  false   => false,
  'true'  => true,
  'false' => false,
}

Constants inherited from Flipper::Gate

Flipper::Gate::InstrumentationName

Instance Attribute Summary

Attributes inherited from Flipper::Gate

#feature_name, #instrumenter

Instance Method Summary collapse

Methods inherited from Flipper::Gate

#disable, #enable, #initialize, #inspect, #instrument, #wrap

Constructor Details

This class inherits a constructor from Flipper::Gate

Instance Method Details

#data_typeObject



21
22
23
# File 'lib/flipper/gates/boolean.rb', line 21

def data_type
  :boolean
end

#description(value) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/flipper/gates/boolean.rb', line 25

def description(value)
  if enabled?(value)
    'Enabled'
  else
    'Disabled'
  end
end

#enabled?(value) ⇒ Boolean

Returns:



33
34
35
# File 'lib/flipper/gates/boolean.rb', line 33

def enabled?(value)
  !!TruthMap[value]
end

#keyObject

Internal: Name converted to value safe for adapter.



17
18
19
# File 'lib/flipper/gates/boolean.rb', line 17

def key
  :boolean
end

#nameObject

Internal: The name of the gate. Used for instrumentation, etc.



12
13
14
# File 'lib/flipper/gates/boolean.rb', line 12

def name
  :boolean
end

#open?(thing, value) ⇒ Boolean

Internal: Checks if the gate is open for a thing.

Returns true if explicitly set to true, false if explicitly set to false or nil if not explicitly set.

Returns:



41
42
43
44
45
# File 'lib/flipper/gates/boolean.rb', line 41

def open?(thing, value)
  instrument(:open?, thing) { |payload|
    !!TruthMap[value]
  }
end

#protects?(thing) ⇒ Boolean

Returns:



47
48
49
# File 'lib/flipper/gates/boolean.rb', line 47

def protects?(thing)
  thing.is_a?(Flipper::Types::Boolean)
end