-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #532 from splitio/Feature/Semver
Feature/semver
- Loading branch information
Showing
29 changed files
with
1,378 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
lib/splitclient-rb/engine/matchers/between_semver_matcher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
lib/splitclient-rb/engine/matchers/equal_to_semver_matcher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
28 changes: 28 additions & 0 deletions
28
lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_semver_matcher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
lib/splitclient-rb/engine/matchers/in_list_semver_matcher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
28 changes: 28 additions & 0 deletions
28
lib/splitclient-rb/engine/matchers/less_than_or_equal_to_semver_matcher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.