Exception: SplitIoClient::Condition
- Inherits:
-
NoMethodError
- Object
- NoMethodError
- SplitIoClient::Condition
- Defined in:
- lib/splitclient-rb/engine/parser/condition.rb
Overview
acts as dto for a condition structure
Constant Summary collapse
- TYPE_ROLLOUT =
'ROLLOUT'.freeze
- TYPE_WHITELIST =
'WHITELIST'.freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
definition of the condition.
-
#partitions ⇒ object
readonly
The array of partitions for this condition.
Instance Method Summary collapse
-
#combiner ⇒ object
The combiner value for this condition.
- #create_condition_matcher(matchers) ⇒ Object
-
#empty? ⇒ boolean
True if the condition is empty false otherwise.
-
#initialize(condition) ⇒ Condition
constructor
A new instance of Condition.
-
#matcher ⇒ object
The matcher value for this condition.
- #matcher_all_keys(_params) ⇒ Object
- #matcher_between(params) ⇒ Object
- #matcher_contains_all_of_set(params) ⇒ Object
- #matcher_contains_any_of_set(params) ⇒ Object
- #matcher_contains_string(params) ⇒ Object
- #matcher_ends_with(params) ⇒ Object
- #matcher_equal_to(params) ⇒ Object
- #matcher_equal_to_boolean(params) ⇒ Object
- #matcher_equal_to_set(params) ⇒ Object
- #matcher_greater_than_or_equal_to(params) ⇒ Object
-
#matcher_in_segment(params) ⇒ Object
returns UserDefinedSegmentMatcher.
- #matcher_in_split_treatment(params) ⇒ Object
- #matcher_less_than_or_equal_to(params) ⇒ Object
- #matcher_matches_string(params) ⇒ Object
- #matcher_part_of_set(params) ⇒ Object
- #matcher_starts_with(params) ⇒ Object
-
#matcher_whitelist(params) ⇒ Object
returns WhitelistMatcher the whitelist for this condition in case it has a whitelist matcher.
-
#matchers ⇒ object
The matchers array value for this condition.
-
#negate ⇒ object
The negate value for this condition.
- #negation_matcher(matcher) ⇒ Object
-
#set_partitions ⇒ void
converts the partitions hash for this condition into an array of partition objects.
-
#type ⇒ string
Condition type.
Constructor Details
#initialize(condition) ⇒ Condition
Returns a new instance of Condition.
14 15 16 17 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 14 def initialize(condition) @data = condition @partitions = set_partitions end |
Instance Attribute Details
#data ⇒ Object
definition of the condition
12 13 14 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 12 def data @data end |
#partitions ⇒ object (readonly)
Returns the array of partitions for this condition.
189 190 191 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 189 def partitions @partitions end |
Instance Method Details
#combiner ⇒ object
Returns the combiner value for this condition.
25 26 27 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 25 def combiner @data[:matcherGroup][:combiner] end |
#create_condition_matcher(matchers) ⇒ Object
19 20 21 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 19 def create_condition_matcher(matchers) CombiningMatcher.new(combiner, matchers) if combiner end |
#empty? ⇒ boolean
Returns true if the condition is empty false otherwise.
206 207 208 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 206 def empty? @data.empty? end |
#matcher ⇒ object
Returns the matcher value for this condition.
31 32 33 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 31 def matcher @data[:matcherGroup][:matchers].first[:matcherType] end |
#matcher_all_keys(_params) ⇒ Object
51 52 53 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 51 def matcher_all_keys(_params) @matcher_all_keys ||= AllKeysMatcher.new end |
#matcher_between(params) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 102 def matcher_between(params) matcher = params[:matcher] attribute = (matcher[:keySelector])[:attribute] start_value = (matcher[:betweenMatcherData])[:start] end_value = (matcher[:betweenMatcherData])[:end] data_type = (matcher[:betweenMatcherData])[:dataType] BetweenMatcher.new(attribute: attribute, start_value: start_value, end_value: end_value, data_type: data_type) end |
#matcher_contains_all_of_set(params) ⇒ Object
125 126 127 128 129 130 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 125 def matcher_contains_all_of_set(params) ContainsAllMatcher.new( params[:matcher][:keySelector][:attribute], params[:matcher][:whitelistMatcherData][:whitelist] ) end |
#matcher_contains_any_of_set(params) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 118 def matcher_contains_any_of_set(params) ContainsAnyMatcher.new( params[:matcher][:keySelector][:attribute], params[:matcher][:whitelistMatcherData][:whitelist] ) end |
#matcher_contains_string(params) ⇒ Object
153 154 155 156 157 158 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 153 def matcher_contains_string(params) ContainsMatcher.new( params[:matcher][:keySelector][:attribute], params[:matcher][:whitelistMatcherData][:whitelist] ) end |
#matcher_ends_with(params) ⇒ Object
146 147 148 149 150 151 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 146 def matcher_ends_with(params) EndsWithMatcher.new( params[:matcher][:keySelector][:attribute], params[:matcher][:whitelistMatcherData][:whitelist] ) end |
#matcher_equal_to(params) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 78 def matcher_equal_to(params) matcher = params[:matcher] attribute = (matcher[:keySelector])[:attribute] value = (matcher[:unaryNumericMatcherData])[:value] data_type = (matcher[:unaryNumericMatcherData])[:dataType] EqualToMatcher.new(attribute: attribute, value: value, data_type: data_type) end |
#matcher_equal_to_boolean(params) ⇒ Object
167 168 169 170 171 172 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 167 def matcher_equal_to_boolean(params) EqualToBooleanMatcher.new( params[:matcher][:keySelector][:attribute], params[:matcher][:booleanMatcherData] ) end |
#matcher_equal_to_set(params) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 111 def matcher_equal_to_set(params) EqualToSetMatcher.new( params[:matcher][:keySelector][:attribute], params[:matcher][:whitelistMatcherData][:whitelist] ) end |
#matcher_greater_than_or_equal_to(params) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 86 def matcher_greater_than_or_equal_to(params) matcher = params[:matcher] attribute = (matcher[:keySelector])[:attribute] value = (matcher[:unaryNumericMatcherData])[:value] data_type = (matcher[:unaryNumericMatcherData])[:dataType] GreaterThanOrEqualToMatcher.new(attribute: attribute, value: value, data_type: data_type) end |
#matcher_in_segment(params) ⇒ Object
returns UserDefinedSegmentMatcher
56 57 58 59 60 61 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 56 def matcher_in_segment(params) matcher = params[:matcher] segment_name = matcher[:userDefinedSegmentMatcherData] && matcher[:userDefinedSegmentMatcherData][:segmentName] UserDefinedSegmentMatcher.new(params[:segments_repository], segment_name) end |
#matcher_in_split_treatment(params) ⇒ Object
160 161 162 163 164 165 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 160 def matcher_in_split_treatment(params) DependencyMatcher.new( params[:matcher][:dependencyMatcherData][:split], params[:matcher][:dependencyMatcherData][:treatments] ) end |
#matcher_less_than_or_equal_to(params) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 94 def matcher_less_than_or_equal_to(params) matcher = params[:matcher] attribute = (matcher[:keySelector])[:attribute] value = (matcher[:unaryNumericMatcherData])[:value] data_type = (matcher[:unaryNumericMatcherData])[:dataType] LessThanOrEqualToMatcher.new(attribute: attribute, value: value, data_type: data_type) end |
#matcher_matches_string(params) ⇒ Object
174 175 176 177 178 179 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 174 def matcher_matches_string(params) MatchesStringMatcher.new( params[:matcher][:keySelector][:attribute], params[:matcher][:stringMatcherData] ) end |
#matcher_part_of_set(params) ⇒ Object
132 133 134 135 136 137 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 132 def matcher_part_of_set(params) PartOfSetMatcher.new( params[:matcher][:keySelector][:attribute], params[:matcher][:whitelistMatcherData][:whitelist] ) end |
#matcher_starts_with(params) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 139 def matcher_starts_with(params) StartsWithMatcher.new( params[:matcher][:keySelector][:attribute], params[:matcher][:whitelistMatcherData][:whitelist] ) end |
#matcher_whitelist(params) ⇒ Object
returns WhitelistMatcher the whitelist for this condition in case it has a whitelist matcher
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 64 def matcher_whitelist(params) result = nil matcher = params[:matcher] is_user_whitelist = ((matcher[:keySelector]).nil? || (matcher[:keySelector])[:attribute].nil?) if is_user_whitelist result = (matcher[:whitelistMatcherData])[:whitelist] else attribute = (matcher[:keySelector])[:attribute] white_list = (matcher[:whitelistMatcherData])[:whitelist] result = { attribute: attribute, value: white_list } end WhitelistMatcher.new(result) end |
#matchers ⇒ object
Returns the matchers array value for this condition.
37 38 39 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 37 def matchers @data[:matcherGroup][:matchers] end |
#negate ⇒ object
Returns the negate value for this condition.
183 184 185 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 183 def negate @data[:matcherGroup][:matchers].first[:negate] end |
#negation_matcher(matcher) ⇒ Object
47 48 49 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 47 def negation_matcher(matcher) NegationMatcher.new(matcher) end |
#set_partitions ⇒ void
This method returns an undefined value.
converts the partitions hash for this condition into an array of partition objects
195 196 197 198 199 200 201 202 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 195 def set_partitions partitions_list = [] @data[:partitions].each do |p| partition = SplitIoClient::Partition.new(p) partitions_list << partition end partitions_list end |
#type ⇒ string
Returns condition type.
43 44 45 |
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 43 def type @data[:conditionType] end |