Skip to content

Commit 5ac3978

Browse files
authored
Merge branch 'feature/rule-based-segments' into rbs-integrations-tests
2 parents 14cee73 + e370d95 commit 5ac3978

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

lib/splitclient-rb/cache/repositories/rule_based_segments_repository.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ class RuleBasedSegmentsRepository < Repository
2222
booleanMatcherData: nil,
2323
stringMatcherData: nil
2424
}]
25-
},
26-
label: "targeting rule type unsupported by sdk"
25+
}
2726
}]
2827

2928
def initialize(config)
3029
super(config)
31-
@tt_cache = {}
3230
@adapter = case @config.cache_adapter.class.to_s
3331
when 'SplitIoClient::Cache::Adapters::RedisAdapter'
3432
SplitIoClient::Cache::Adapters::CacheAdapter.new(@config)
@@ -79,8 +77,6 @@ def exists?(name)
7977
end
8078

8179
def clear
82-
@tt_cache.clear
83-
8480
@adapter.clear(namespace_key)
8581
end
8682

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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ def match?(args)
4444
rule_based_segment[:conditions].each do |c|
4545
condition = SplitIoClient::Condition.new(c, @config)
4646
next if condition.empty?
47-
4847
matches = Helpers::EvaluatorHelper.matcher_type(condition, @segments_repository, @rule_based_segments_repository).match?(args)
4948
end
5049
@logger.debug("[InRuleSegmentMatcher] #{@segment_name} is in rule based segment -> #{matches}")
51-
5250
matches
5351
end
5452

spec/engine/matchers/rule_based_segment_matcher_spec.rb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,28 @@
3232
expect(matcher.match?(value: 'key2')).to be false
3333
end
3434

35-
it 'return true if excluded rb segment is matched' do
35+
it 'return false 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+
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: '[email protected]', attributes: {'email': '[email protected]'})).to be true
64-
expect(matcher.match?(value: 'bilal', attributes: {'email': 'bilal'})).to be false
82+
expect(matcher.match?(value: '[email protected]', attributes: {'email': '[email protected]'})).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)