Class: SplitIoClient::RuleBasedSegmentMatcher

Inherits:
Matcher
  • Object
show all
Defined in:
lib/splitclient-rb/engine/matchers/rule_based_segment_matcher.rb

Overview

class to implement the user defined matcher

Constant Summary collapse

MATCHER_TYPE =
'IN_RULE_BASED_SEGMENT'

Instance Method Summary collapse

Methods inherited from Matcher

#equals?, #string_type?

Constructor Details

#initialize(segments_repository, rule_based_segments_repository, segment_name, config) ⇒ RuleBasedSegmentMatcher

Returns a new instance of RuleBasedSegmentMatcher.



10
11
12
13
14
15
16
# File 'lib/splitclient-rb/engine/matchers/rule_based_segment_matcher.rb', line 10

def initialize(segments_repository, rule_based_segments_repository, segment_name, config)
  super(config.logger)
  @rule_based_segments_repository = rule_based_segments_repository
  @segments_repository = segments_repository
  @segment_name = segment_name
  @config = config
end

Instance Method Details

#match?(args) ⇒ boolean

evaluates if the key matches the matcher

Parameters:

  • key (string)

    key value to be matched

Returns:

  • (boolean)

    evaluation of the key against the segment



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/splitclient-rb/engine/matchers/rule_based_segment_matcher.rb', line 24

def match?(args)
  rule_based_segment = @rule_based_segments_repository.get_rule_based_segment(@segment_name)
  return false if rule_based_segment.nil?

  key = update_key(args)
  return false if rule_based_segment[:excluded][:keys].include?(key)

  return false unless check_excluded_segments(rule_based_segment, key, args)

  matches = false
  rule_based_segment[:conditions].each do |c|
    condition = SplitIoClient::Condition.new(c, @config)
    next if condition.empty?

    matches = Helpers::EvaluatorHelper.matcher_type(condition, @segments_repository, @rule_based_segments_repository).match?(args)
  end
  @logger.debug("[InRuleSegmentMatcher] #{@segment_name} is in rule based segment -> #{matches}")
  matches
end