Sha256: f7f995f01dfea48dee249f50c4aeb1ab246a4e160888cca79dbd05e8be0c055a

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module SplitIoClient
  class BetweenSemverMatcher < Matcher
    MATCHER_TYPE = 'BETWEEN_SEMVER'

    attr_reader :attribute

    def initialize(attribute, start_value, end_value, logger, validator)
      super(logger)
      @validator = validator
      @attribute = attribute
      @semver_start = SplitIoClient::Semver.build(start_value, logger)
      @semver_end = SplitIoClient::Semver.build(end_value, logger)
      @logger = logger
    end

    def match?(args)
      return false unless verify_semver_arg?(args, 'BetweenSemverMatcher')

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

      end
      matches = ([0, -1].include?(@semver_start.compare(value_to_match)) &&
                 [0, 1].include?(@semver_end.compare(value_to_match)))
      @logger.debug("[BetweenMatcher] #{value_to_match} matches -> #{matches}")
      matches
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
splitclient-rb-8.4.0-java lib/splitclient-rb/engine/matchers/between_semver_matcher.rb
splitclient-rb-8.4.0 lib/splitclient-rb/engine/matchers/between_semver_matcher.rb
splitclient-rb-8.4.0.pre.rc1-java lib/splitclient-rb/engine/matchers/between_semver_matcher.rb
splitclient-rb-8.4.0.pre.rc1 lib/splitclient-rb/engine/matchers/between_semver_matcher.rb
splitclient-rb-8.4.0.rc.1-java lib/splitclient-rb/engine/matchers/between_semver_matcher.rb
splitclient-rb-8.4.0.rc.1 lib/splitclient-rb/engine/matchers/between_semver_matcher.rb