Class: SplitIoClient::InListSemverMatcher

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

Constant Summary collapse

MATCHER_TYPE =
'IN_LIST_SEMVER'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Matcher

#equals?, #string_type?

Constructor Details

#initialize(attribute, list_value, logger, validator) ⇒ InListSemverMatcher

Returns a new instance of InListSemverMatcher.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/splitclient-rb/engine/matchers/in_list_semver_matcher.rb', line 9

def initialize(attribute, list_value, logger, validator)
  super(logger)
  @validator = validator
  @attribute = attribute
  @semver_list = []

  list_value.map do |item|
    version = SplitIoClient::Semver.build(item, logger)
    @semver_list << version unless version.nil?
  end
  @logger = logger
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



7
8
9
# File 'lib/splitclient-rb/engine/matchers/in_list_semver_matcher.rb', line 7

def attribute
  @attribute
end

Instance Method Details

#match?(args) ⇒ Boolean

Returns:

  • (Boolean)


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

def match?(args)
  return false if @semver_list.empty? || !verify_semver_arg?(args, 'InListSemverMatcher')

  value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
  if value_to_match.nil?
    @logger.error('whitelistMatcherData is required for IN_LIST_SEMVER matcher type')
    return false

  end
  matches = (@semver_list.map { |item| item.version == value_to_match.version }).any? { |item| item == true }
  @logger.debug("[InListSemverMatcher] #{value_to_match} matches -> #{matches}")
  matches
end