Class: Flipper::Gates::PercentageOfActors
- Inherits:
-
Flipper::Gate
- Object
- Flipper::Gate
- Flipper::Gates::PercentageOfActors
- Defined in:
- lib/flipper/gates/percentage_of_actors.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
37 38 39 40 41 42 43 |
# File 'lib/flipper/gates/percentage_of_actors.rb', line 37 def description if enabled? "#{toggle.value}% of actors" else 'disabled' end end |
#key ⇒ Object
Internal: The piece of the adapter key that is unique to the gate class.
12 13 14 |
# File 'lib/flipper/gates/percentage_of_actors.rb', line 12 def key :perc_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?(thing) ⇒ Boolean
Internal: Checks if the gate is open for a thing.
Returns true if gate open for thing, false if not.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/flipper/gates/percentage_of_actors.rb', line 19 def open?(thing) instrument(:open?, thing) { |payload| percentage = toggle.value.to_i if Types::Actor.wrappable?(thing) actor = Types::Actor.wrap(thing) key = "#{@feature.name}#{actor.value}" Zlib.crc32(key) % 100 < percentage else false end } end |
#protects?(thing) ⇒ Boolean
33 34 35 |
# File 'lib/flipper/gates/percentage_of_actors.rb', line 33 def protects?(thing) thing.is_a?(Flipper::Types::PercentageOfActors) end |