Class: Flipper::Gates::PercentageOfActors
- Inherits:
-
Flipper::Gate
- Object
- Flipper::Gate
- Flipper::Gates::PercentageOfActors
- Defined in:
- lib/flipper/gates/percentage_of_actors.rb
Instance Method Summary collapse
- #data_type ⇒ Object
- #enabled?(value) ⇒ Boolean
-
#key ⇒ Object
Internal: Name converted to value safe for adapter.
-
#name ⇒ Object
Internal: The name of the gate.
-
#open?(context) ⇒ Boolean
Internal: Checks if the gate is open for one or more actors.
- #protects?(thing) ⇒ Boolean
Methods inherited from Flipper::Gate
Constructor Details
This class inherits a constructor from Flipper::Gate
Instance Method Details
#data_type ⇒ Object
16 17 18 |
# File 'lib/flipper/gates/percentage_of_actors.rb', line 16 def data_type :integer end |
#enabled?(value) ⇒ Boolean
20 21 22 |
# File 'lib/flipper/gates/percentage_of_actors.rb', line 20 def enabled?(value) value > 0 end |
#key ⇒ Object
Internal: Name converted to value safe for adapter.
12 13 14 |
# File 'lib/flipper/gates/percentage_of_actors.rb', line 12 def key :percentage_of_actors end |
#name ⇒ Object
Internal: The name of the gate. Used for instrumentation, etc.
7 8 9 |
# File 'lib/flipper/gates/percentage_of_actors.rb', line 7 def name :percentage_of_actors end |
#open?(context) ⇒ Boolean
Internal: Checks if the gate is open for one or more actors.
Returns true if gate open for any actors, false if not.
32 33 34 35 36 |
# File 'lib/flipper/gates/percentage_of_actors.rb', line 32 def open?(context) return false unless context.actors? id = "#{context.feature_name}#{context.actors.map(&:value).sort.join}" Zlib.crc32(id) % (100 * SCALING_FACTOR) < context.values.percentage_of_actors * SCALING_FACTOR end |
#protects?(thing) ⇒ Boolean
38 39 40 |
# File 'lib/flipper/gates/percentage_of_actors.rb', line 38 def protects?(thing) thing.is_a?(Types::PercentageOfActors) end |