Exception: SplitIoClient::Condition

Inherits:
NoMethodError
  • Object
show all
Defined in:
lib/engine/parser/condition.rb

Overview

acts as dto for a condition structure

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

#dataObject

definition of the condition



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

def data
  @data
end

Instance Method Details

#combinerobject

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



128
129
130
# File 'lib/engine/parser/condition.rb', line 128

def empty?
  @data.empty?
end

#matcherobject

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



41
42
43
# File 'lib/engine/parser/condition.rb', line 41

def matcher_all_keys params
  AllKeysMatcher.new
end

#matcher_between(params) ⇒ Object



92
93
94
95
96
97
98
99
# File 'lib/engine/parser/condition.rb', line 92

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_equal_to(params) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/engine/parser/condition.rb', line 68

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_greater_than_or_equal_to(params) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/engine/parser/condition.rb', line 76

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



46
47
48
49
50
51
# File 'lib/engine/parser/condition.rb', line 46

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



84
85
86
87
88
89
90
# File 'lib/engine/parser/condition.rb', line 84

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_whitelist(params) ⇒ Object

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



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/engine/parser/condition.rb', line 54

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

#matchersobject

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

#negateobject

Returns the negate value for this condition.

Returns:

  • (object)

    the negate value for this condition



103
104
105
# File 'lib/engine/parser/condition.rb', line 103

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

#partitionsobject

Returns the array of partitions for this condition.

Returns:

  • (object)

    the array of partitions for this condition



109
110
111
# File 'lib/engine/parser/condition.rb', line 109

def partitions
  @partitions
end

#set_partitionsvoid

This method returns an undefined value.

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



117
118
119
120
121
122
123
124
# File 'lib/engine/parser/condition.rb', line 117

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