Class: Flipper::Gates::Expression
- Inherits:
-
Flipper::Gate
- Object
- Flipper::Gate
- Flipper::Gates::Expression
- Defined in:
- lib/flipper/gates/expression.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 a thing.
- #protects?(thing) ⇒ Boolean
- #wrap(thing) ⇒ Object
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/expression.rb', line 16 def data_type :json end |
#enabled?(value) ⇒ Boolean
20 21 22 |
# File 'lib/flipper/gates/expression.rb', line 20 def enabled?(value) !value.nil? && !value.empty? end |
#key ⇒ Object
Internal: Name converted to value safe for adapter.
12 13 14 |
# File 'lib/flipper/gates/expression.rb', line 12 def key :expression end |
#name ⇒ Object
Internal: The name of the gate. Used for instrumentation, etc.
7 8 9 |
# File 'lib/flipper/gates/expression.rb', line 7 def name :expression end |
#open?(context) ⇒ Boolean
Internal: Checks if the gate is open for a thing.
Returns true if gate open for thing, false if not.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/flipper/gates/expression.rb', line 27 def open?(context) data = context.values.expression return false if data.nil? || data.empty? expression = Flipper::Expression.build(data) if context.actors.nil? || context.actors.empty? !!expression.evaluate(feature_name: context.feature_name, properties: DEFAULT_PROPERTIES) else context.actors.any? do |actor| !!expression.evaluate(feature_name: context.feature_name, properties: properties(actor)) end end end |
#protects?(thing) ⇒ Boolean
41 42 43 |
# File 'lib/flipper/gates/expression.rb', line 41 def protects?(thing) thing.is_a?(Flipper::Expression) || thing.is_a?(Hash) end |
#wrap(thing) ⇒ Object
45 46 47 |
# File 'lib/flipper/gates/expression.rb', line 45 def wrap(thing) Flipper::Expression.build(thing) end |