Exception: SplitIoClient::WhitelistMatcher

Inherits:
NoMethodError
  • Object
show all
Defined in:
lib/engine/matchers/whitelist_matcher.rb

Overview

class to implement the user defined matcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(whitelist_data) ⇒ WhitelistMatcher

Returns a new instance of WhitelistMatcher.



13
14
15
16
17
18
19
20
21
# File 'lib/engine/matchers/whitelist_matcher.rb', line 13

def initialize(whitelist_data)
  if whitelist_data.instance_of? Array
    @whitelist = whitelist_data unless whitelist_data.nil?
  elsif whitelist_data.instance_of? Hash
    @matcher_type = "ATTR_WHITELIST"
    @attribute = whitelist_data[:attribute]
    @whitelist = whitelist_data[:value] unless whitelist_data[:value].nil?
  end
end

Instance Attribute Details

#matcher_typeObject (readonly)

Returns the value of attribute matcher_type.



8
9
10
# File 'lib/engine/matchers/whitelist_matcher.rb', line 8

def matcher_type
  @matcher_type
end

Instance Method Details

#equals?(obj) ⇒ Boolean

evaluates if the given object equals the matcher

Parameters:

  • obj (object)

    object to be evaluated

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/engine/matchers/whitelist_matcher.rb', line 42

def equals?(obj)
  if obj.nil?
    false
  elsif !obj.instance_of?(WhitelistMatcher)
    false
  elsif self.equal?(obj)
    true
  else
    false
  end
end

#match?(key, whitelist_data) ⇒ Boolean

Returns:

  • (Boolean)


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

def match?(key, whitelist_data)
  matches = false
  if !(@matcher_type == "ATTR_WHITELIST")
    matches = @whitelist.include?(key)
  else
    if (!whitelist_data.nil? && whitelist_data.key?(@attribute.to_sym))
      value = whitelist_data[@attribute.to_sym]
      matches = @whitelist.include?(value)
    end
  end
  matches
end

#to_sObject

function to print string value for this matcher



58
59
60
# File 'lib/engine/matchers/whitelist_matcher.rb', line 58

def to_s
  'in segment ' + @whitelist.to_s
end