Class: Unleash::Constraint
- Inherits:
-
Object
- Object
- Unleash::Constraint
- Defined in:
- lib/unleash/constraint.rb
Constant Summary collapse
- VALID_OPERATORS =
['IN', 'NOT_IN'].freeze
Instance Attribute Summary collapse
-
#context_name ⇒ Object
Returns the value of attribute context_name.
-
#operator ⇒ Object
Returns the value of attribute operator.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
-
#initialize(context_name, operator, values = []) ⇒ Constraint
constructor
A new instance of Constraint.
- #matches_context?(context) ⇒ Boolean
Constructor Details
#initialize(context_name, operator, values = []) ⇒ Constraint
Returns a new instance of Constraint.
7 8 9 10 11 12 13 14 15 |
# File 'lib/unleash/constraint.rb', line 7 def initialize(context_name, operator, values = []) raise ArgumentError, "context_name is not a String" unless context_name.is_a?(String) raise ArgumentError, "operator does not hold a valid value:" + VALID_OPERATORS unless VALID_OPERATORS.include? operator raise ArgumentError, "values does not hold an Array" unless values.is_a?(Array) self.context_name = context_name self.operator = operator self.values = values end |
Instance Attribute Details
#context_name ⇒ Object
Returns the value of attribute context_name.
3 4 5 |
# File 'lib/unleash/constraint.rb', line 3 def context_name @context_name end |
#operator ⇒ Object
Returns the value of attribute operator.
3 4 5 |
# File 'lib/unleash/constraint.rb', line 3 def operator @operator end |
#values ⇒ Object
Returns the value of attribute values.
3 4 5 |
# File 'lib/unleash/constraint.rb', line 3 def values @values end |
Instance Method Details
#matches_context?(context) ⇒ Boolean
17 18 19 20 21 22 23 24 |
# File 'lib/unleash/constraint.rb', line 17 def matches_context?(context) Unleash.logger.debug "Unleash::Constraint matches_context? values: #{self.values} context.get_by_name(#{self.context_name})" \ " #{context.get_by_name(self.context_name)} " is_included = self.values.include? context.get_by_name(self.context_name) operator == 'IN' ? is_included : !is_included end |