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
- #description ⇒ Object
-
#key ⇒ Object
Internal: The piece of the adapter key that is unique to the gate class.
-
#name ⇒ Object
Internal: The name of the gate.
-
#open?(thing) ⇒ Boolean
Internal: Checks if the gate is open for a thing.
- #protects?(thing) ⇒ Boolean
Methods inherited from Flipper::Gate
#adapter_key, #disable, #enable, #enabled?, #initialize, #inspect, #instrument, #toggle, #toggle_class
Constructor Details
This class inherits a constructor from Flipper::Gate
Instance Method Details
#description ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/flipper/gates/percentage_of_random.rb', line 29 def description if enabled? "#{toggle.value}% of the time" else 'disabled' end end |
#key ⇒ Object
Internal: The piece of the adapter key that is unique to the gate class.
10 11 12 |
# File 'lib/flipper/gates/percentage_of_random.rb', line 10 def key :perc_time 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) ⇒ Boolean
Internal: Checks if the gate is open for a thing.
Returns true if gate open for thing, false if not.
17 18 19 20 21 22 23 |
# File 'lib/flipper/gates/percentage_of_random.rb', line 17 def open?(thing) instrument(:open?, thing) { |payload| percentage = toggle.value.to_i rand < (percentage / 100.0) } end |
#protects?(thing) ⇒ Boolean
25 26 27 |
# File 'lib/flipper/gates/percentage_of_random.rb', line 25 def protects?(thing) thing.is_a?(Flipper::Types::PercentageOfRandom) end |