Skip to content

Commit 0480e78

Browse files
committed
polish
1 parent 80c207f commit 0480e78

3 files changed

Lines changed: 28 additions & 25 deletions

File tree

lib/splitclient-rb/engine/matchers/combining_matcher.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ def eval_and(args)
5656

5757
@matchers.all? do |matcher|
5858
if match_with_key?(matcher)
59-
matcher.match?(value: args[:matching_key])
59+
key = args[:value]
60+
if args[:matching_key] != nil
61+
key = args[:matching_key]
62+
end
63+
matcher.match?(value: key)
6064
else
6165
matcher.match?(args)
6266
end

lib/splitclient-rb/engine/matchers/rule_based_segment_matcher.rb

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,17 @@ def match?(args)
3030
rule_based_segment[:excluded][:segments].each do |segment|
3131
return false if segment[:type] == 'standard' and @segments_repository.in_segment?(segment[:name], args[:value])
3232

33-
if segment[:type] == 'rule-based'
34-
return true if match_rbs(@rule_based_segments_repository.get_rule_based_segment(segment[:name])[:conditions], args)
35-
end
33+
return false if SplitIoClient::RuleBasedSegmentMatcher.new(@segments_repository, @rule_based_segments_repository, segment[:name], @config).match?(args)
3634
end
3735

3836
matches = false
3937
rule_based_segment[:conditions].each do |c|
4038
condition = SplitIoClient::Condition.new(c, @config)
4139
next if condition.empty?
42-
4340
matches = Helpers::EvaluatorHelper.matcher_type(condition, @segments_repository, @rule_based_segments_repository).match?(args)
4441
end
4542
@logger.debug("[InRuleSegmentMatcher] #{@segment_name} is in rule based segment -> #{matches}")
46-
4743
matches
4844
end
49-
50-
private
51-
52-
def match_rbs(conditions, args)
53-
conditions.each do |condition|
54-
next if condition.empty?
55-
56-
return true if Helpers::EvaluatorHelper::matcher_type(SplitIoClient::Condition.new(condition, @config),
57-
@segments_repository, @rule_based_segments_repository).match?(
58-
matching_key: args[:matching_key],
59-
bucketing_key: args[:value],
60-
attributes: args[:attributes]
61-
)
62-
end
63-
return false
64-
end
6545
end
6646
end

spec/engine/matchers/rule_based_segment_matcher_spec.rb

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,26 @@
3434

3535
it 'return true if excluded rb segment is matched' do
3636
rbs_repositoy = SplitIoClient::Cache::Repositories::RuleBasedSegmentsRepository.new(config)
37-
rbs = {:name => 'sample_rule_based_segment', :trafficTypeName => 'tt_name_1', :conditions => [], :excluded => {:keys => [], :segments => [{:name => 'no_excludes', :type => 'rule-based'}]}}
37+
rbs = {:name => 'sample_rule_based_segment', :trafficTypeName => 'tt_name_1', :conditions => [{
38+
:matcherGroup => {
39+
:combiner => "AND",
40+
:matchers => [
41+
{
42+
:matcherType => "WHITELIST",
43+
:negate => false,
44+
:userDefinedSegmentMatcherData => nil,
45+
:whitelistMatcherData => {
46+
:whitelist => [
47+
"bilal@split.io",
48+
"bilal"
49+
]
50+
},
51+
:unaryNumericMatcherData => nil,
52+
:betweenMatcherData => nil
53+
}
54+
]
55+
}
56+
}], :excluded => {:keys => [], :segments => [{:name => 'no_excludes', :type => 'rule-based'}]}}
3857
rbs2 = {:name => 'no_excludes', :trafficTypeName => 'tt_name_1',
3958
:conditions => [{
4059
:matcherGroup => {
@@ -60,8 +79,8 @@
6079

6180
rbs_repositoy.update([rbs, rbs2], [], -1)
6281
matcher = described_class.new(segments_repository, rbs_repositoy, 'sample_rule_based_segment', config)
63-
expect(matcher.match?(value: 'bilal@split.io', attributes: {'email': 'bilal@split.io'})).to be true
64-
expect(matcher.match?(value: 'bilal', attributes: {'email': 'bilal'})).to be false
82+
expect(matcher.match?(value: 'bilal@split.io', attributes: {'email': 'bilal@split.io'})).to be false
83+
expect(matcher.match?(value: 'bilal', attributes: {'email': 'bilal'})).to be true
6584
end
6685

6786
it 'return true if condition matches' do

0 commit comments

Comments
 (0)