Class: Toggly::Evaluators::ContextualTargeting
- Defined in:
- lib/toggly/evaluators/contextual_targeting.rb
Overview
Evaluator for contextual targeting based on traits.
Supports various comparison operators on trait values.
Constant Summary collapse
- OPERATORS =
Supported operators
%w[ eq ne gt gte lt lte contains not_contains starts_with ends_with in not_in matches exists not_exists ].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#evaluate(rule, context, feature_key: nil) ⇒ Boolean?
Evaluate contextual targeting rule.
Methods inherited from Base
Class Method Details
.type ⇒ Object
19 20 21 |
# File 'lib/toggly/evaluators/contextual_targeting.rb', line 19 def self.type "contextual" end |
Instance Method Details
#evaluate(rule, context, feature_key: nil) ⇒ Boolean?
Evaluate contextual targeting rule
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/toggly/evaluators/contextual_targeting.rb', line 29 def evaluate(rule, context, feature_key: nil) conditions = Array(rule_value(rule, "conditions")) return nil if conditions.empty? return nil unless context match_type = rule_value(rule, "matchType") || rule_value(rule, "match_type") || "all" if match_type == "any" conditions.any? { |condition| evaluate_condition(condition, context) } else conditions.all? { |condition| evaluate_condition(condition, context) } end end |