Class: Flipper::Gates::PercentageOfRandom
- Inherits:
-
Flipper::Gate
- Object
- Flipper::Gate
- Flipper::Gates::PercentageOfRandom
- Defined in:
- lib/flipper/gates/percentage_of_random.rb
Constant Summary
Constants inherited from Flipper::Gate
Flipper::Gate::InstrumentationName
Instance Attribute Summary
Attributes inherited from Flipper::Gate
Instance Method Summary collapse
- #data_type ⇒ Object
- #description(value) ⇒ Object
- #enabled?(value) ⇒ Boolean
-
#key ⇒ Object
Internal: Name converted to value safe for adapter.
-
#name ⇒ Object
Internal: The name of the gate.
-
#open?(thing, value) ⇒ Boolean
Internal: Checks if the gate is open for a thing.
- #protects?(thing) ⇒ Boolean
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_type ⇒ Object
14 15 16 |
# File 'lib/flipper/gates/percentage_of_random.rb', line 14 def data_type :integer end |
#description(value) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/flipper/gates/percentage_of_random.rb', line 18 def description(value) if enabled?(value) "#{value}% of the time" else 'disabled' end end |
#enabled?(value) ⇒ Boolean
26 27 28 |
# File 'lib/flipper/gates/percentage_of_random.rb', line 26 def enabled?(value) !value.nil? && value.to_i > 0 end |
#key ⇒ Object
Internal: Name converted to value safe for adapter.
10 11 12 |
# File 'lib/flipper/gates/percentage_of_random.rb', line 10 def key :percentage_of_random end |
#name ⇒ Object
Internal: The name of the gate. Used for instrumentation, etc.
5 6 7 |
# File 'lib/flipper/gates/percentage_of_random.rb', line 5 def name :percentage_of_random end |
#open?(thing, value) ⇒ Boolean
Internal: Checks if the gate is open for a thing.
Returns true if gate open for thing, false if not.
33 34 35 36 37 38 39 |
# File 'lib/flipper/gates/percentage_of_random.rb', line 33 def open?(thing, value) instrument(:open?, thing) { |payload| percentage = value.to_i rand < (percentage / 100.0) } end |
#protects?(thing) ⇒ Boolean
41 42 43 |
# File 'lib/flipper/gates/percentage_of_random.rb', line 41 def protects?(thing) thing.is_a?(Flipper::Types::PercentageOfRandom) end |