Exception: SplitIoClient::Condition

Inherits:
NoMethodError
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(condition, config) ⇒ Condition

Returns a new instance of Condition.



14
15
16
17
18
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 14

def initialize(condition, config)
  @data = condition
  @partitions = set_partitions
  @config = config
end

Instance Attribute Details

#dataObject

definition of the condition



12
13
14
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 12

def data
  @data
end

#partitionsobject (readonly)

Returns the array of partitions for this condition.

Returns:

  • (object)

    the array of partitions for this condition



200
201
202
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 200

def partitions
  @partitions
end

Instance Method Details

#combinerobject

Returns the combiner value for this condition.

Returns:

  • (object)

    the combiner value for this condition



26
27
28
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 26

def combiner
  @data[:matcherGroup][:combiner]
end

#create_condition_matcher(matchers) ⇒ Object



20
21
22
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 20

def create_condition_matcher(matchers)
  CombiningMatcher.new(@config.split_logger, combiner, matchers) if combiner
end

#empty?boolean

Returns true if the condition is empty false otherwise.

Returns:

  • (boolean)

    true if the condition is empty false otherwise



217
218
219
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 217

def empty?
  @data.empty?
end

#matcherobject

Returns the matcher value for this condition.

Returns:

  • (object)

    the matcher value for this condition



32
33
34
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 32

def matcher
  @data[:matcherGroup][:matchers].first[:matcherType]
end

#matcher_all_keys(_params) ⇒ Object



52
53
54
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 52

def matcher_all_keys(_params)
  @matcher_all_keys ||= AllKeysMatcher.new(@config.split_logger)
end

#matcher_between(params) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 103

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}, @config.split_logger, @config.split_validator)
end

#matcher_contains_all_of_set(params) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 128

def matcher_contains_all_of_set(params)
  ContainsAllMatcher.new(
    params[:matcher][:keySelector][:attribute],
    params[:matcher][:whitelistMatcherData][:whitelist],
    @config.split_logger
  )
end

#matcher_contains_any_of_set(params) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 120

def matcher_contains_any_of_set(params)
  ContainsAnyMatcher.new(
    params[:matcher][:keySelector][:attribute],
    params[:matcher][:whitelistMatcherData][:whitelist],
    @config.split_logger
  )
end

#matcher_contains_string(params) ⇒ Object



160
161
162
163
164
165
166
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 160

def matcher_contains_string(params)
  ContainsMatcher.new(
    params[:matcher][:keySelector][:attribute],
    params[:matcher][:whitelistMatcherData][:whitelist],
    @config.split_logger, @config.split_validator
  )
end

#matcher_ends_with(params) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 152

def matcher_ends_with(params)
  EndsWithMatcher.new(
    params[:matcher][:keySelector][:attribute],
    params[:matcher][:whitelistMatcherData][:whitelist],
    @config.split_logger
  )
end

#matcher_equal_to(params) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 79

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}, @config.split_logger, @config.split_validator)
end

#matcher_equal_to_boolean(params) ⇒ Object



176
177
178
179
180
181
182
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 176

def matcher_equal_to_boolean(params)
  EqualToBooleanMatcher.new(
    params[:matcher][:keySelector][:attribute],
    params[:matcher][:booleanMatcherData],
    @config.split_logger
  )
end

#matcher_equal_to_set(params) ⇒ Object



112
113
114
115
116
117
118
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 112

def matcher_equal_to_set(params)
  EqualToSetMatcher.new(
    params[:matcher][:keySelector][:attribute],
    params[:matcher][:whitelistMatcherData][:whitelist],
    @config.split_logger
  )
end

#matcher_greater_than_or_equal_to(params) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 87

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}, @config.split_logger, @config.split_validator)
end

#matcher_in_segment(params) ⇒ Object



57
58
59
60
61
62
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 57

def matcher_in_segment(params)
  matcher = params[:matcher]
  segment_name = matcher[:userDefinedSegmentMatcherData] && matcher[:userDefinedSegmentMatcherData][:segmentName]

  UserDefinedSegmentMatcher.new(params[:segments_repository], segment_name, @config.split_logger)
end

#matcher_in_split_treatment(params) ⇒ Object



168
169
170
171
172
173
174
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 168

def matcher_in_split_treatment(params)
  DependencyMatcher.new(
    params[:matcher][:dependencyMatcherData][:split],
    params[:matcher][:dependencyMatcherData][:treatments],
    @config.split_logger
  )
end

#matcher_less_than_or_equal_to(params) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 95

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}, @config.split_logger, @config.split_validator)
end

#matcher_matches_string(params) ⇒ Object



184
185
186
187
188
189
190
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 184

def matcher_matches_string(params)
  MatchesStringMatcher.new(
    params[:matcher][:keySelector][:attribute],
    params[:matcher][:stringMatcherData],
    @config.split_logger
  )
end

#matcher_part_of_set(params) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 136

def matcher_part_of_set(params)
  PartOfSetMatcher.new(
    params[:matcher][:keySelector][:attribute],
    params[:matcher][:whitelistMatcherData][:whitelist],
    @config.split_logger
  )
end

#matcher_starts_with(params) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 144

def matcher_starts_with(params)
  StartsWithMatcher.new(
    params[:matcher][:keySelector][:attribute],
    params[:matcher][:whitelistMatcherData][:whitelist],
    @config.split_logger
  )
end

#matcher_whitelist(params) ⇒ Object

returns WhitelistMatcher the whitelist for this condition in case it has a whitelist matcher



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 65

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, @config.split_logger, @config.split_validator)
end

#matchersobject

Returns the matchers array value for this condition.

Returns:

  • (object)

    the matchers array value for this condition



38
39
40
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 38

def matchers
  @data[:matcherGroup][:matchers]
end

#negateobject

Returns the negate value for this condition.

Returns:

  • (object)

    the negate value for this condition



194
195
196
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 194

def negate
  @data[:matcherGroup][:matchers].first[:negate]
end

#negation_matcher(matcher) ⇒ Object



48
49
50
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 48

def negation_matcher(matcher)
  NegationMatcher.new(@config.split_logger, matcher)
end

#set_partitionsvoid

This method returns an undefined value.

converts the partitions hash for this condition into an array of partition objects



206
207
208
209
210
211
212
213
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 206

def set_partitions
  partitions_list = []
  @data[:partitions].each do |p|
    partition = SplitIoClient::Partition.new(p)
    partitions_list << partition
  end
  partitions_list
end

#typestring

Returns condition type.

Returns:

  • (string)

    condition type



44
45
46
# File 'lib/splitclient-rb/engine/parser/condition.rb', line 44

def type
  @data[:conditionType]
end