Class: SplitIoClient::CombiningMatcher
- Defined in:
- lib/splitclient-rb/engine/matchers/combining_matcher.rb
Overview
class to implement the combining matcher
Constant Summary collapse
- MATCHER_TYPE =
'COMBINING_MATCHER'
Instance Method Summary collapse
-
#eval_and(args) ⇒ boolean
auxiliary method to evaluate each of the matchers within the combiner.
-
#initialize(logger, combiner = '', matchers = []) ⇒ CombiningMatcher
constructor
A new instance of CombiningMatcher.
-
#match?(args) ⇒ boolean
evaluates if the key matches the matchers within the combiner.
- #match_with_key?(matcher) ⇒ Boolean
-
#to_s ⇒ string
function to print string value for this matcher.
Methods inherited from Matcher
Constructor Details
#initialize(logger, combiner = '', matchers = []) ⇒ CombiningMatcher
Returns a new instance of CombiningMatcher.
10 11 12 13 14 |
# File 'lib/splitclient-rb/engine/matchers/combining_matcher.rb', line 10 def initialize(logger, combiner = '', matchers = []) super(logger) @combiner = combiner @matchers = matchers end |
Instance Method Details
#eval_and(args) ⇒ boolean
auxiliary method to evaluate each of the matchers within the combiner
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/splitclient-rb/engine/matchers/combining_matcher.rb', line 53 def eval_and(args) # Convert all keys to symbols args[:attributes] = args[:attributes].each_with_object({}) { |(k, v), memo| memo[k.to_sym] = v } if args && args[:attributes] @matchers.all? do |matcher| if match_with_key?(matcher) matcher.match?(value: args[:matching_key]) else matcher.match?(args) end end end |
#match?(args) ⇒ boolean
evaluates if the key matches the matchers within the combiner
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/splitclient-rb/engine/matchers/combining_matcher.rb', line 25 def match?(args) if @matchers.empty? @logger.log_if_debug('[CombiningMatcher] Matchers Empty') return false end case @combiner when Combiners::AND matches = eval_and(args) @logger.log_if_debug("[CombiningMatcher] Combiner AND result -> #{matches}") return matches else @logger.log_if_debug("[CombiningMatcher] Invalid Combiner Type - Combiner -> #{@combiner}") @logger.error('Invalid combiner type') end false end |
#match_with_key?(matcher) ⇒ Boolean
66 67 68 |
# File 'lib/splitclient-rb/engine/matchers/combining_matcher.rb', line 66 def match_with_key?(matcher) matcher.respond_to?(:attribute) && matcher.attribute.nil? && matcher.string_type? end |
#to_s ⇒ string
function to print string value for this matcher
74 75 76 |
# File 'lib/splitclient-rb/engine/matchers/combining_matcher.rb', line 74 def to_s @matcher_list.map(&:to_s).join("#{@combiner} ") end |