@@ -5,6 +5,32 @@ module Cache
55 module Repositories
66 class SplitsRepository < Repository
77 attr_reader :adapter
8+ DEFAULT_CONDITIONS_TEMPLATE = [ {
9+ conditionType : "ROLLOUT" ,
10+ matcherGroup : {
11+ combiner : "AND" ,
12+ matchers : [
13+ {
14+ keySelector : nil ,
15+ matcherType : "ALL_KEYS" ,
16+ negate : false ,
17+ userDefinedSegmentMatcherData : nil ,
18+ whitelistMatcherData : nil ,
19+ unaryNumericMatcherData : nil ,
20+ betweenMatcherData : nil ,
21+ dependencyMatcherData : nil ,
22+ booleanMatcherData : nil ,
23+ stringMatcherData : nil
24+ } ]
25+ } ,
26+ partitions : [
27+ {
28+ treatment : "control" ,
29+ size : 100
30+ }
31+ ] ,
32+ label : "targeting rule type unsupported by sdk"
33+ } ]
834
935 def initialize ( config , flag_sets_repository , flag_set_filter )
1036 super ( config )
@@ -155,6 +181,10 @@ def add_feature_flag(split)
155181 remove_from_flag_sets ( existing_split )
156182 end
157183
184+ if check_undefined_matcher ( split )
185+ @config . logger . warn ( "Feature Flag #{ split [ :name ] } has undefined matcher, setting conditions to default template." )
186+ split [ :conditions ] = SplitsRepository ::DEFAULT_CONDITIONS_TEMPLATE
187+ end
158188 if !split [ :sets ] . nil?
159189 for flag_set in split [ :sets ]
160190 if !@flag_sets . flag_set_exist? ( flag_set )
@@ -170,6 +200,18 @@ def add_feature_flag(split)
170200 @adapter . set_string ( namespace_key ( ".split.#{ split [ :name ] } " ) , split . to_json )
171201 end
172202
203+ def check_undefined_matcher ( split )
204+ for condition in split [ :conditions ]
205+ for matcher in condition [ :matcherGroup ] [ :matchers ]
206+ if !SplitIoClient ::Condition . instance_methods ( false ) . map ( &:to_s ) . include? ( "matcher_#{ matcher [ :matcherType ] . downcase } " )
207+ @config . logger . error ( "Detected undefined matcher #{ matcher [ :matcherType ] . downcase } in feature flag #{ split [ :name ] } " )
208+ return true
209+ end
210+ end
211+ end
212+ return false
213+ end
214+
173215 def remove_feature_flag ( split )
174216 decrease_tt_name_count ( split [ :trafficTypeName ] )
175217 remove_from_flag_sets ( split )
0 commit comments