Sha256: d1faab818c725a8283c695486441e3be45d457c541c3fb4f2237b168a15d2466

Contents?: true

Size: 1.51 KB

Versions: 45

Compression:

Stored size: 1.51 KB

Contents

module SplitIoClient

  #
  # class to implement the user defined matcher
  #
  class WhitelistMatcher < NoMethodError

    attr_reader :matcher_type

    # variable that contains the keys of the whitelist
    @whitelist = []

    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

    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

    #
    # evaluates if the given object equals the matcher
    #
    # @param obj [object] object to be evaluated
    #
    # @returns [boolean] true if obj equals the matcher
    def equals?(obj)
      if obj.nil?
        false
      elsif !obj.instance_of?(WhitelistMatcher)
        false
      elsif self.equal?(obj)
        true
      else
        false
      end
    end

    #
    # function to print string value for this matcher
    #
    # @reutrn [string] string value of this matcher
    def to_s
      'in segment ' + @whitelist.to_s
    end

  end

end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
splitclient-rb-4.1.0 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-4.1.0.pre.rc2 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-4.1.0.pre.rc1 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-4.0.0 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-4.0.0.pre.rc1 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.3.0 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.3.0.pre.rc1 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.2.4 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.2.4.pre.rc5 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.2.4.pre.rc4 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.2.4.pre.rc3 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.2.4.pre.rc2 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.2.4.pre.rc1 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.2.3 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.2.3.pre.rc1 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.2.2 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.2.1 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.2.0 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.1.3 lib/engine/matchers/whitelist_matcher.rb
splitclient-rb-3.1.3.pre.rc3 lib/engine/matchers/whitelist_matcher.rb