Module: LaunchDarkly::Impl::EvaluatorOperators
- Defined in:
- lib/ldclient-rb/impl/evaluator_operators.rb
Overview
Defines the behavior of all operators that can be used in feature flag rules and segment rules.
Class Method Summary collapse
-
.apply(op, context_value, clause_value) ⇒ Boolean
Applies an operator to produce a boolean result.
Class Method Details
.apply(op, context_value, clause_value) ⇒ Boolean
Applies an operator to produce a boolean result.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ldclient-rb/impl/evaluator_operators.rb', line 18 def self.apply(op, context_value, clause_value) case op when :in context_value == clause_value when :startsWith string_op(context_value, clause_value, lambda { |a, b| a.start_with? b }) when :endsWith string_op(context_value, clause_value, lambda { |a, b| a.end_with? b }) when :contains string_op(context_value, clause_value, lambda { |a, b| a.include? b }) when :matches string_op(context_value, clause_value, lambda { |a, b| begin re = Regexp.new b !re.match(a).nil? rescue false end }) when :lessThan numeric_op(context_value, clause_value, lambda { |a, b| a < b }) when :lessThanOrEqual numeric_op(context_value, clause_value, lambda { |a, b| a <= b }) when :greaterThan numeric_op(context_value, clause_value, lambda { |a, b| a > b }) when :greaterThanOrEqual numeric_op(context_value, clause_value, lambda { |a, b| a >= b }) when :before date_op(context_value, clause_value, lambda { |a, b| a < b }) when :after date_op(context_value, clause_value, lambda { |a, b| a > b }) when :semVerEqual semver_op(context_value, clause_value, lambda { |a, b| a == b }) when :semVerLessThan semver_op(context_value, clause_value, lambda { |a, b| a < b }) when :semVerGreaterThan semver_op(context_value, clause_value, lambda { |a, b| a > b }) when :segmentMatch # We should never reach this; it can't be evaluated based on just two parameters, because it requires # looking up the segment from the data store. Instead, we special-case this operator in clause_match_context. false else false end end |