Class: SplitIoClient::WhitelistMatcher

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

Overview

class to implement the user defined matcher

Constant Summary collapse

MATCHER_TYPE =
'WHITELIST_MATCHER'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Matcher

#equals?

Constructor Details

#initialize(whitelist_data, logger, validator) ⇒ WhitelistMatcher

Returns a new instance of WhitelistMatcher.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/splitclient-rb/engine/matchers/whitelist_matcher.rb', line 12

def initialize(whitelist_data, logger, validator)
  super(logger)
  @validator = validator
  @whitelist = case whitelist_data
               when Array
                 whitelist_data
               when Hash
                 @matcher_type = 'ATTR_WHITELIST'
                 @attribute = whitelist_data[:attribute]

                 whitelist_data[:value]
               else
                 []
               end
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



10
11
12
# File 'lib/splitclient-rb/engine/matchers/whitelist_matcher.rb', line 10

def attribute
  @attribute
end

Instance Method Details

#match?(args) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
# File 'lib/splitclient-rb/engine/matchers/whitelist_matcher.rb', line 28

def match?(args)
  return matches_user_whitelist(args) unless @matcher_type == 'ATTR_WHITELIST'

  @logger.log_if_debug('[WhitelistMatcher] evaluating value and attributes.')

  return false unless @validator.valid_matcher_arguments(args)

  matches_attr_whitelist(args)
end

#string_type?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/splitclient-rb/engine/matchers/whitelist_matcher.rb', line 38

def string_type?
  true
end

#to_sstring

function to print string value for this matcher

Returns:

  • (string)

    string value of this matcher



46
47
48
# File 'lib/splitclient-rb/engine/matchers/whitelist_matcher.rb', line 46

def to_s
  "in segment #{@whitelist}"
end