Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/semver #532

Merged
merged 47 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2968a19
added undefined matcher flow
Mar 5, 2024
5cbe5dc
polish
Mar 5, 2024
c770cff
Merge pull request #510 from splitio/undefined-matcher
chillaq Mar 5, 2024
75cc222
added semver class
Mar 26, 2024
21f408b
polish
Mar 26, 2024
6b83afc
added equalto semver matcher
Mar 28, 2024
93d73b0
polish
Mar 28, 2024
45fbd0b
polish
Mar 28, 2024
8aa6bb9
added greater than or equal to semver matcher
Mar 28, 2024
30232f8
added less than or equal semver matcher
Mar 29, 2024
2f95e4b
added semver between matcher
Mar 29, 2024
2749c65
added in list semver matcher
Mar 29, 2024
7fd6f34
polish
Mar 29, 2024
e9677d9
fixed matcher logic
Apr 1, 2024
dc0caa6
fixed matcher logic
Apr 1, 2024
9f1b7d9
semver matchers integrations spec
Apr 1, 2024
8a1d214
Used csv for spec and added builder for semver class
Apr 8, 2024
f12ee2a
added csv files
Apr 8, 2024
acad113
updated using build for semver class
Apr 9, 2024
1e4a238
used build for semver class
Apr 9, 2024
8bf838b
used build for semver class
Apr 9, 2024
cf60f11
used build for semver class
Apr 9, 2024
61b8c9e
fixed condition
Apr 9, 2024
8cc7ff5
Merge pull request #514 from splitio/semver-class
chillaq Apr 10, 2024
f875912
Merge pull request #516 from splitio/semver-equalto-matcher
chillaq Apr 10, 2024
608c259
Merge pull request #517 from splitio/semver-greater-or-equalto-matcher
chillaq Apr 10, 2024
229a9f7
Merge pull request #518 from splitio/semver-less-or-equalto-matcher
chillaq Apr 10, 2024
89826a3
Merge pull request #519 from splitio/semver-between-matcher
chillaq Apr 10, 2024
f76b944
Merge pull request #521 from splitio/semver-integration-spec
chillaq Apr 10, 2024
980c272
added version attribute and used it in compare
Apr 10, 2024
b9e8fd8
updated semver spec
Apr 10, 2024
b1529d2
Fixed compare logic in semver, equalto and inlist matchers.
Apr 10, 2024
a8761d7
Added nil check for all matchers and updated specs
Apr 11, 2024
5a084a8
polish
Apr 11, 2024
a302223
Merge branch 'Feature/Semver' into semver-inlist-matcher
chillaq Apr 11, 2024
7ec5da7
added version length check for compare
Apr 11, 2024
4ecad51
correcting specs and comparisons
Apr 11, 2024
a1cab94
Merge pull request #525 from splitio/semver-inlist-matcher
chillaq Apr 11, 2024
0f5ac2f
Merge branch 'development' into Feature/Semver
chillaq May 1, 2024
db9311a
updated query api order, fixed spec and added error to split logger
May 1, 2024
418e5d7
added debug to split logger
May 1, 2024
b7ecdd1
update debug logging in semver matchers
May 1, 2024
1bc71a5
fixed spec
May 1, 2024
abea9d2
polishing
May 1, 2024
581d6e3
polish
May 1, 2024
50fe596
polish
May 2, 2024
2a54d08
polish and test update
May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

chillaq marked this conversation as resolved.
Show resolved Hide resolved
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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure about the scope of @semver variable ?

@logger.error("stringMatcherData is required for #{matcher_spec_name} matcher type")
return false

end
true
end
end
end
Loading
Loading