Exception: SplitIoClient::WhitelistMatcher
- Inherits:
-
NoMethodError
- Object
- NoMethodError
- SplitIoClient::WhitelistMatcher
- 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
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
Instance Method Summary collapse
-
#equals?(obj) ⇒ Boolean
evaluates if the given object equals the matcher.
-
#initialize(whitelist_data) ⇒ WhitelistMatcher
constructor
A new instance of WhitelistMatcher.
- #match?(args) ⇒ Boolean
- #string_type? ⇒ Boolean
-
#to_s ⇒ Object
function to print string value for this matcher.
Constructor Details
#initialize(whitelist_data) ⇒ WhitelistMatcher
Returns a new instance of WhitelistMatcher.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/splitclient-rb/engine/matchers/whitelist_matcher.rb', line 10 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.
8 9 10 |
# File 'lib/splitclient-rb/engine/matchers/whitelist_matcher.rb', line 8 def attribute @attribute end |
Instance Method Details
#equals?(obj) ⇒ Boolean
evaluates if the given object equals the matcher
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/splitclient-rb/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?(args) ⇒ Boolean
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/splitclient-rb/engine/matchers/whitelist_matcher.rb', line 24 def match?(args) return @whitelist.include?(args[:value] || args[:matching_key]) unless @matcher_type == 'ATTR_WHITELIST' return false if !args.key?(:attributes) && !args.key?(:value) return false if args.key?(:value) && args[:value].nil? return false if args.key?(:attributes) && args[:attributes].nil? return @whitelist.include?(args[:value] || args[:attributes][@attribute.to_sym]) false end |
#string_type? ⇒ Boolean
54 55 56 |
# File 'lib/splitclient-rb/engine/matchers/whitelist_matcher.rb', line 54 def string_type? true end |
#to_s ⇒ Object
function to print string value for this matcher
62 63 64 |
# File 'lib/splitclient-rb/engine/matchers/whitelist_matcher.rb', line 62 def to_s "in segment #{@whitelist}" end |