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) ⇒ WhitelistMatcher

Returns a new instance of WhitelistMatcher.



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

def initialize(whitelist_data)
  @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

#attribute ⇒ Object (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)


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

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

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

  return false unless SplitIoClient::Validators.valid_matcher_arguments(args)

  matches_attr_whitelist(args)
end

#string_type? ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/splitclient-rb/engine/matchers/whitelist_matcher.rb', line 36

def string_type?
  true
end

#to_s ⇒ string

function to print string value for this matcher

Returns:

  • (string) —

    string value of this matcher



44
45
46
# File 'lib/splitclient-rb/engine/matchers/whitelist_matcher.rb', line 44

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