Exception: SplitIoClient::Condition

Inherits:
NoMethodError
  • Object
show all
Defined in:
lib/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) ⇒ Condition

Returns a new instance of Condition.



14
15
16
17
# File 'lib/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/engine/parser/condition.rb', line 12

def data
  @data
end

#partitions ⇒ object (readonly)

Returns the array of partitions for this condition.

Returns:

  • (object) —

    the array of partitions for this condition



168
169
170
# File 'lib/engine/parser/condition.rb', line 168

def partitions
  @partitions
end

Instance Method Details

#combiner ⇒ object

Returns the combiner value for this condition.

Returns:

  • (object) —

    the combiner value for this condition



25
26
27
# File 'lib/engine/parser/condition.rb', line 25

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

#create_condition_matcher(matchers) ⇒ Object



19
20
21
# File 'lib/engine/parser/condition.rb', line 19

def create_condition_matcher(matchers)
  CombiningMatcher.new(combiner, matchers) unless combiner.nil?
end

#empty? ⇒ boolean

Returns true if the condition is empty false otherwise.

Returns:

  • (boolean) —

    true if the condition is empty false otherwise



185
186
187
# File 'lib/engine/parser/condition.rb', line 185

def empty?
  @data.empty?
end

#matcher ⇒ object

Returns the matcher value for this condition.

Returns:

  • (object) —

    the matcher value for this condition



31
32
33
# File 'lib/engine/parser/condition.rb', line 31

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

#matcher_all_keys(_params) ⇒ Object



51
52
53
# File 'lib/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/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/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/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/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/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/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_set(params) ⇒ Object



111
112
113
114
115
116
# File 'lib/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/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



56
57
58
59
60
61
# File 'lib/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_less_than_or_equal_to(params) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/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_part_of_set(params) ⇒ Object



132
133
134
135
136
137
# File 'lib/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/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/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.

Returns:

  • (object) —

    the matchers array value for this condition



37
38
39
# File 'lib/engine/parser/condition.rb', line 37

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

#negate ⇒ object

Returns the negate value for this condition.

Returns:

  • (object) —

    the negate value for this condition



162
163
164
# File 'lib/engine/parser/condition.rb', line 162

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

#negation_matcher(matcher) ⇒ Object



47
48
49
# File 'lib/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



174
175
176
177
178
179
180
181
# File 'lib/engine/parser/condition.rb', line 174

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.

Returns:

  • (string) —

    condition type



43
44
45
# File 'lib/engine/parser/condition.rb', line 43

def type
  @data[:conditionType]
end