Class: Flipper::Gate
- Inherits:
-
Object
- Object
- Flipper::Gate
- Extended by:
- Forwardable
- Defined in:
- lib/flipper/gate.rb
Direct Known Subclasses
Flipper::Gates::Actor, Flipper::Gates::Boolean, Flipper::Gates::Group, Flipper::Gates::PercentageOfActors, Flipper::Gates::PercentageOfRandom
Constant Summary collapse
- InstrumentationName =
Private: The name of instrumentation events.
"gate_operation.#{InstrumentationNamespace}"
Instance Attribute Summary collapse
-
#feature ⇒ Object
readonly
Private.
-
#instrumenter ⇒ Object
readonly
Private: What is used to instrument all the things.
Instance Method Summary collapse
-
#adapter_key ⇒ Object
Internal: The key where details about this gate can be retrieved from the adapter.
-
#disable(thing) ⇒ Object
Internal: Disable this gate for a thing.
-
#enable(thing) ⇒ Object
Internal: Enable this gate for a thing.
- #enabled? ⇒ Boolean
-
#initialize(feature, options = {}) ⇒ Gate
constructor
Public.
-
#inspect ⇒ Object
Public: Pretty string version for debugging.
-
#instrument(operation, thing) ⇒ Object
Private.
-
#key ⇒ Object
Private: The piece of the adapter key that is unique to the gate class.
-
#name ⇒ Object
Public: The name of the gate.
-
#open?(thing) ⇒ Boolean
Internal: Check if a gate is open for a thing.
-
#protects?(thing) ⇒ Boolean
Internal: Check if a gate is protects a thing.
-
#toggle ⇒ Object
Internal: The toggle to use to enable/disable this gate.
-
#toggle_class ⇒ Object
Internal: The toggle class to use for this gate.
Constructor Details
#initialize(feature, options = {}) ⇒ Gate
Public
21 22 23 24 |
# File 'lib/flipper/gate.rb', line 21 def initialize(feature, = {}) @feature = feature @instrumenter = .fetch(:instrumenter, Flipper::Instrumenters::Noop) end |
Instance Attribute Details
#feature ⇒ Object (readonly)
Private
13 14 15 |
# File 'lib/flipper/gate.rb', line 13 def feature @feature end |
#instrumenter ⇒ Object (readonly)
Private: What is used to instrument all the things.
16 17 18 |
# File 'lib/flipper/gate.rb', line 16 def instrumenter @instrumenter end |
Instance Method Details
#adapter_key ⇒ Object
Internal: The key where details about this gate can be retrieved from the adapter.
39 40 41 |
# File 'lib/flipper/gate.rb', line 39 def adapter_key @key ||= Key.new(@feature.name, key) end |
#disable(thing) ⇒ Object
Internal: Disable this gate for a thing.
Returns the result of Flipper::Toggle#disable.
77 78 79 |
# File 'lib/flipper/gate.rb', line 77 def disable(thing) toggle.disable(thing) end |
#enable(thing) ⇒ Object
Internal: Enable this gate for a thing.
Returns the result of Flipper::Toggle#enable.
70 71 72 |
# File 'lib/flipper/gate.rb', line 70 def enable(thing) toggle.enable(thing) end |
#enabled? ⇒ Boolean
81 82 83 |
# File 'lib/flipper/gate.rb', line 81 def enabled? toggle.enabled? end |
#inspect ⇒ Object
Public: Pretty string version for debugging.
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/flipper/gate.rb', line 86 def inspect attributes = [ "feature=#{feature.name.inspect}", "description=#{description.inspect}", "adapter=#{adapter.name.inspect}", "adapter_key=#{adapter_key.inspect}", "toggle_class=#{toggle_class.inspect}", "toggle_value=#{toggle.value.inspect}", ] "#<#{self.class.name}:#{object_id} #{attributes.join(', ')}>" end |
#instrument(operation, thing) ⇒ Object
Private
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/flipper/gate.rb', line 99 def instrument(operation, thing) payload = { :thing => thing, :operation => operation, :gate_name => name, :feature_name => @feature.name, } @instrumenter.instrument(InstrumentationName, payload) { payload[:result] = yield(payload) if block_given? } end |
#key ⇒ Object
Private: The piece of the adapter key that is unique to the gate class. Implemented in subclass.
33 34 35 |
# File 'lib/flipper/gate.rb', line 33 def key raise 'Not implemented' end |
#name ⇒ Object
Public: The name of the gate. Implemented in subclass.
27 28 29 |
# File 'lib/flipper/gate.rb', line 27 def name raise 'Not implemented' end |
#open?(thing) ⇒ Boolean
Internal: Check if a gate is open for a thing. Implemented in subclass.
Returns true if gate open for thing, false if not.
56 57 58 |
# File 'lib/flipper/gate.rb', line 56 def open?(thing) false end |
#protects?(thing) ⇒ Boolean
Internal: Check if a gate is protects a thing. Implemented in subclass.
Returns true if gate protects thing, false if not.
63 64 65 |
# File 'lib/flipper/gate.rb', line 63 def protects?(thing) false end |
#toggle ⇒ Object
Internal: The toggle to use to enable/disable this gate.
49 50 51 |
# File 'lib/flipper/gate.rb', line 49 def toggle @toggle ||= toggle_class.new(self) end |