Skip to content

Commit

Permalink
Merge pull request #532 from splitio/Feature/Semver
Browse files Browse the repository at this point in the history
Feature/semver
  • Loading branch information
chillaq authored May 2, 2024
2 parents 6eafede + 2a54d08 commit 91b9266
Show file tree
Hide file tree
Showing 29 changed files with 1,378 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/splitclient-rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
require 'splitclient-rb/engine/matchers/equal_to_boolean_matcher'
require 'splitclient-rb/engine/matchers/equal_to_matcher'
require 'splitclient-rb/engine/matchers/matches_string_matcher'
require 'splitclient-rb/engine/matchers/semver'
require 'splitclient-rb/engine/matchers/equal_to_semver_matcher'
require 'splitclient-rb/engine/matchers/greater_than_or_equal_to_semver_matcher'
require 'splitclient-rb/engine/matchers/less_than_or_equal_to_semver_matcher'
require 'splitclient-rb/engine/matchers/between_semver_matcher'
require 'splitclient-rb/engine/matchers/in_list_semver_matcher'
require 'splitclient-rb/engine/evaluator/splitter'
require 'splitclient-rb/engine/impressions/noop_unique_keys_tracker'
require 'splitclient-rb/engine/impressions/unique_keys_tracker'
Expand Down
5 changes: 3 additions & 2 deletions lib/splitclient-rb/cache/repositories/splits_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class SplitsRepository < Repository
size: 100
}
],
label: "unsupported matcher type"
}]
label: "targeting rule type unsupported by sdk"
}]

def initialize(config, flag_sets_repository, flag_set_filter)
super(config)
@tt_cache = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/splitclient-rb/engine/api/splits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def since(since, fetch_options = { cache_control_headers: false, till: nil, sets
start = Time.now

params = { s: SplitIoClient::Spec::FeatureFlags::SPEC_VERSION, since: since }
params[:till] = fetch_options[:till] unless fetch_options[:till].nil?
params[:sets] = @flag_sets_filter.join(",") unless @flag_sets_filter.empty?
params[:till] = fetch_options[:till] unless fetch_options[:till].nil?
@config.logger.debug("Fetching from splitChanges with #{params}: ")
response = get_api("#{@config.base_uri}/splitChanges", @api_key, params, fetch_options[:cache_control_headers])
if response.status == 414
Expand Down
33 changes: 33 additions & 0 deletions lib/splitclient-rb/engine/matchers/between_semver_matcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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
28 changes: 28 additions & 0 deletions lib/splitclient-rb/engine/matchers/equal_to_semver_matcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module SplitIoClient
class EqualToSemverMatcher < Matcher
MATCHER_TYPE = 'EQUAL_TO_SEMVER'

attr_reader :attribute

def initialize(attribute, string_value, logger, validator)
super(logger)
@validator = validator
@attribute = attribute
@semver = SplitIoClient::Semver.build(string_value, logger)
@logger = logger
end

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

value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
return false unless check_semver_value_to_match(value_to_match, MATCHER_TYPE)

matches = (@semver.version == value_to_match.version)
@logger.debug("[EqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
matches
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module SplitIoClient
class GreaterThanOrEqualToSemverMatcher < Matcher
MATCHER_TYPE = 'GREATER_THAN_OR_EQUAL_TO_SEMVER'

attr_reader :attribute

def initialize(attribute, string_value, logger, validator)
super(logger)
@validator = validator
@attribute = attribute
@semver = SplitIoClient::Semver.build(string_value, logger)
@logger = logger
end

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

value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
return false unless check_semver_value_to_match(value_to_match, MATCHER_TYPE)

matches = [0, 1].include?(value_to_match.compare(@semver))
@logger.debug("[GreaterThanOrEqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
matches
end
end
end
36 changes: 36 additions & 0 deletions lib/splitclient-rb/engine/matchers/in_list_semver_matcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module SplitIoClient
class InListSemverMatcher < Matcher
MATCHER_TYPE = 'IN_LIST_SEMVER'

attr_reader :attribute

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

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
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module SplitIoClient
class LessThanOrEqualToSemverMatcher < Matcher
MATCHER_TYPE = 'LESS_THAN_OR_EQUAL_TO_SEMVER'

attr_reader :attribute

def initialize(attribute, string_value, logger, validator)
super(logger)
@validator = validator
@attribute = attribute
@semver = SplitIoClient::Semver.build(string_value, logger)
@logger = logger
end

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

value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
return false unless check_semver_value_to_match(value_to_match, MATCHER_TYPE)

matches = [0, -1].include?(value_to_match.compare(@semver))
@logger.debug("[LessThanOrEqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
matches
end
end
end
18 changes: 18 additions & 0 deletions lib/splitclient-rb/engine/matchers/matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,23 @@ def equals?(obj)
def string_type?
false
end

private

def verify_semver_arg?(args, matcher_name)
@logger.debug("[#{matcher_name}] evaluating value and attributes.")
return false unless @validator.valid_matcher_arguments(args)

true
end

def check_semver_value_to_match(value_to_match, matcher_spec_name)
if value_to_match.nil? || @semver.nil?
@logger.error("stringMatcherData is required for #{matcher_spec_name} matcher type")
return false

end
true
end
end
end
Loading

0 comments on commit 91b9266

Please sign in to comment.