Skip to content

Commit

Permalink
polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilal Al committed May 1, 2024
1 parent 1bc71a5 commit abea9d2
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/splitclient-rb/engine/matchers/between_semver_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def initialize(attribute, start_value, end_value, logger, validator)
end

def match?(args)
@logger.debug('[BetweenSemverMatcher] evaluating value and attributes.')
return false unless @validator.valid_matcher_arguments(args)
return false if !verify_semver_arg?(args, "BetweenSemverMatcher")

value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
unless !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)))
Expand Down
9 changes: 3 additions & 6 deletions lib/splitclient-rb/engine/matchers/equal_to_semver_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ def initialize(attribute, string_value, logger, validator)
end

def match?(args)
@logger.debug('[EqualsToSemverMatcher] evaluating value and attributes.')
return false unless @validator.valid_matcher_arguments(args)
return false if !verify_semver_arg?(args, "EqualsToSemverMatcher")

value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
unless !value_to_match.nil? && !@semver.nil?
@logger.error('stringMatcherData is required for EQUAL_TO_SEMVER matcher type')
return false
end
return false if !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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ def initialize(attribute, string_value, logger, validator)
end

def match?(args)
@logger.debug('[GreaterThanOrEqualsToSemverMatcher] evaluating value and attributes.')
return false unless @validator.valid_matcher_arguments(args)
return false if !verify_semver_arg?(args, "GreaterThanOrEqualsToSemverMatcher")

value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
unless !value_to_match.nil? && !@semver.nil?
@logger.error('stringMatcherData is required for GREATER_THAN_OR_EQUAL_TO_SEMVER matcher type')
return false
end
return false if !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
Expand Down
3 changes: 1 addition & 2 deletions lib/splitclient-rb/engine/matchers/in_list_semver_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def initialize(attribute, list_value, logger, validator)
end

def match?(args)
@logger.debug('[InListSemverMatcher] evaluating value and attributes.')
return false unless @validator.valid_matcher_arguments(args) && args[:attributes][@attribute.to_sym].is_a?(String)
return false if !verify_semver_arg?(args, "InListSemverMatcher")

value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
unless !value_to_match.nil? && @semver_list.all? { |n| !n.nil? }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ def initialize(attribute, string_value, logger, validator)
end

def match?(args)
@logger.debug('[LessThanOrEqualsToSemverMatcher] evaluating value and attributes.')
return false unless @validator.valid_matcher_arguments(args)
return false if !verify_semver_arg?(args, "LessThanOrEqualsToSemverMatcher")

value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
unless !value_to_match.nil? && !@semver.nil?
@logger.error('stringMatcherData is required for LESS_THAN_OR_EQUAL_TO_SEMVER matcher type')
return false
end
return false if !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
Expand Down
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)
unless !value_to_match.nil? && !@semver.nil?
@logger.error("stringMatcherData is required for #{matcher_spec_name} matcher type")
return false

end
true
end
end
end

0 comments on commit abea9d2

Please sign in to comment.