kameleoon-client-ruby 3.23.0 → 3.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e99837e0d5fa905c2635ec24e42867b55d5fba98a68283b79b59ffb51d95312
4
- data.tar.gz: e0375cd6f8aca052dbb50cc839f41ce853d34bf48b0ee52ae92b841f24b5dc26
3
+ metadata.gz: 2b3f4672bef07e4a106968c72d6d8d7d1ba327231456d77ad4a7fadb549ee32f
4
+ data.tar.gz: 6a2d0262829d0183ed2bc2c44c01af747c25c73c8c9ea313054044b5d38fc332
5
5
  SHA512:
6
- metadata.gz: a432523e9510c65671d627f55250169b550feea3026004e908191828baccb6e75c43b345701041894aeaa180e2ff700dfe2b693e64e1236091620a15f5c4d572
7
- data.tar.gz: 9da0e374af6713aa7e15ae4e2e2e1f4726bcc7322a7a764143f05e0e7c7bf8402c60fc8ef924b360532b738a4a66ff12560ebc023813d29f9c0694d5e0ae8918
6
+ metadata.gz: 50c3371e134ca0f31f7087b7ae00151b2957ebf848b4b7f25a6f33fcbee9b1db671ff223d76c112023da94ae2d7fc2beec3e2c793ae7d486ad91147c1050fdb7
7
+ data.tar.gz: 3f21a0ab83763c11a859554b0e5c0c62fc9ef56491c9651d4067f8119bf7d70ee45273ddafcb0f5f6a6434191fa91a0f717c227b3f7214ec58a43b480b9570b5
@@ -42,11 +42,41 @@ module Kameleoon
42
42
  LOWER = 'LOWER'
43
43
  EQUAL = 'EQUAL'
44
44
  GREATER = 'GREATER'
45
+ LOWER_OR_EQUAL = 'LOWER_OR_EQUAL'
46
+ GREATER_OR_EQUAL = 'GREATER_OR_EQUAL'
45
47
  IS_TRUE = 'TRUE'
46
48
  IS_FALSE = 'FALSE'
47
49
  AMONG_VALUES = 'AMONG_VALUES'
48
50
  ANY = 'ANY'
49
51
  UNKNOWN = 'UNKNOWN'
52
+
53
+ def self.comparison?(operator)
54
+ case operator
55
+ when LOWER, GREATER, EQUAL, LOWER_OR_EQUAL, GREATER_OR_EQUAL
56
+ true
57
+ else
58
+ false
59
+ end
60
+ end
61
+
62
+ # Checks `value <operator> condition_value`.
63
+ # Returns false if the operator is not a comparison one or any of the values is NaN.
64
+ def self.compare(operator, value, condition_value)
65
+ case operator
66
+ when LOWER
67
+ value < condition_value
68
+ when GREATER
69
+ value > condition_value
70
+ when EQUAL
71
+ value == condition_value
72
+ when LOWER_OR_EQUAL
73
+ value <= condition_value
74
+ when GREATER_OR_EQUAL
75
+ value >= condition_value
76
+ else
77
+ false
78
+ end
79
+ end
50
80
  end
51
81
 
52
82
  # Base class for all targeting conditions
@@ -36,17 +36,11 @@ module Kameleoon
36
36
  version_number = SemVersion.from_string(@version)&.to_f || Float::NAN
37
37
  return false if version_number.nan?
38
38
 
39
- case @version_match_type
40
- when Operator::EQUAL
41
- browser.version == version_number
42
- when Operator::GREATER
43
- browser.version > version_number
44
- when Operator::LOWER
45
- browser.version < version_number
46
- else
39
+ unless Operator.comparison?(@version_match_type)
47
40
  Logging::KameleoonLogger.error("Unexpected comparing operation for 'Browser' condition: '#{@version_match_type}'")
48
- false
41
+ return false
49
42
  end
43
+ Operator.compare(@version_match_type, browser.version, version_number)
50
44
  end
51
45
 
52
46
  def browser_index_from_name(name)
@@ -1,74 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'set'
4
3
  require 'json'
5
4
  require 'kameleoon/targeting/condition'
6
5
  require 'kameleoon/exceptions'
6
+ require 'kameleoon/logging/kameleoon_logger'
7
7
 
8
8
  module Kameleoon
9
9
  module Targeting
10
10
  # CustomDatum represents an instance of Custom Data condition from back office
11
11
  class CustomDatum < Condition
12
- include Kameleoon::Exception
13
-
14
- class << self
15
- def op_undefined(values, value)
16
- false
17
- end
18
-
19
- def op_match(values, value)
20
- re = Regexp.new(value.to_s)
21
- values.any? { |v| re.match(v) }
22
- end
23
-
24
- def op_contains(values, value)
25
- values.any? { |v| v.to_s.include? value.to_s }
26
- end
27
-
28
- def op_exact(values, value)
29
- values.include? value.to_s
30
- end
31
-
32
- def op_equal(values, value)
33
- epsilon = 1e-9
34
- values.any? { |v| (v.to_f - value.to_f).abs < epsilon }
35
- end
36
-
37
- def op_greater(values, value)
38
- values.any? { |v| v.to_f > value.to_f }
39
- end
40
-
41
- def op_lower(values, value)
42
- values.any? { |v| v.to_f < value.to_f }
43
- end
44
-
45
- def op_is_true(values, _value)
46
- values.any? { |v| v.to_s == 'true' }
47
- end
48
-
49
- def op_is_false(values, _value)
50
- values.any? { |v| v.to_s == 'false' }
51
- end
52
-
53
- def op_among_values(values, value)
54
- all_matches = JSON.parse(value.to_s).map(&:to_s).to_set
55
- values.any? { |v| all_matches.include?(v) }
56
- end
57
- end
58
-
59
- @@op = {
60
- Operator::UNDEFINED => method(:op_undefined),
61
- Operator::REGULAR_EXPRESSION => method(:op_match),
62
- Operator::CONTAINS => method(:op_contains),
63
- Operator::EXACT => method(:op_exact),
64
- Operator::EQUAL => method(:op_equal),
65
- Operator::GREATER => method(:op_greater),
66
- Operator::LOWER => method(:op_lower),
67
- Operator::IS_TRUE => method(:op_is_true),
68
- Operator::IS_FALSE => method(:op_is_false),
69
- Operator::AMONG_VALUES => method(:op_among_values)
70
- }
71
-
72
12
  def initialize(json_condition)
73
13
  super(json_condition)
74
14
 
@@ -79,24 +19,54 @@ module Kameleoon
79
19
  @type = ConditionType::CUSTOM_DATUM
80
20
  @index = json_condition['customDataIndex'].to_i
81
21
  @operator = json_condition['valueMatchType']
82
- @operation = @@op[@operator]
83
22
  @value = json_condition['value']
23
+ @regexp = nil # Compiled from @value on first use
24
+ @among_values = nil # Parsed from @value on first use
84
25
  end
85
26
 
86
27
  def check(custom_data_storage)
87
28
  is_targeted = nil
88
29
  if custom_data_storage.is_a?(Kameleoon::DataManager::DataMapStorage)
89
30
  custom_data = custom_data_storage.get(@index)
90
- if custom_data.is_a?(Kameleoon::CustomData)
91
- unless @operation
92
- raise KameleoonError.new("Undefined operator #{@operator}"), "Undefined operator #{@operator}"
93
- end
94
- is_targeted = @operation.call(custom_data.values, @value)
95
- end
31
+ is_targeted = check_targeting(custom_data.values) if custom_data.is_a?(Kameleoon::CustomData)
96
32
  end
97
33
  is_targeted = (@operator == Operator::UNDEFINED.to_s) if is_targeted.nil?
98
34
  is_targeted
99
35
  end
36
+
37
+ private
38
+
39
+ def check_targeting(values)
40
+ return compare_number_values(values) if Operator.comparison?(@operator)
41
+
42
+ case @operator
43
+ when Operator::CONTAINS
44
+ values.any? { |v| v.to_s.include? @value.to_s }
45
+ when Operator::EXACT
46
+ values.include? @value.to_s
47
+ when Operator::REGULAR_EXPRESSION
48
+ @regexp ||= Regexp.new(@value.to_s)
49
+ values.any? { |v| @regexp.match?(v) }
50
+ when Operator::IS_TRUE
51
+ values.any? { |v| v.to_s == 'true' }
52
+ when Operator::IS_FALSE
53
+ values.any? { |v| v.to_s == 'false' }
54
+ when Operator::AMONG_VALUES
55
+ @among_values ||= JSON.parse(@value.to_s).map(&:to_s)
56
+ values.any? { |v| @among_values.include?(v) }
57
+ when Operator::UNDEFINED
58
+ # The custom data is defined, so the condition is not met
59
+ false
60
+ else
61
+ Logging::KameleoonLogger.error("Unexpected comparing operation for '#{@type}' condition: '#{@operator}'")
62
+ false
63
+ end
64
+ end
65
+
66
+ def compare_number_values(values)
67
+ number = @value.to_f
68
+ values.any? { |value| Operator.compare(@operator, value.to_f, number) }
69
+ end
100
70
  end
101
71
  end
102
72
  end
@@ -21,17 +21,12 @@ module Kameleoon
21
21
  protected
22
22
 
23
23
  def check_targeting(value)
24
- case @match_type
25
- when Kameleoon::Targeting::Operator::EQUAL
26
- return value == @condition_value
27
- when Kameleoon::Targeting::Operator::GREATER
28
- return !@condition_value.nil? && value > @condition_value
29
- when Kameleoon::Targeting::Operator::LOWER
30
- return !@condition_value.nil? && value < @condition_value
31
- else
24
+ unless Operator.comparison?(@match_type)
32
25
  Logging::KameleoonLogger.error("Unexpected comparing operation for '#{@type}' condition: '#{@match_type}'")
26
+ return false
33
27
  end
34
- false
28
+ # A condition without a value never matches
29
+ !@condition_value.nil? && Operator.compare(@match_type, value, @condition_value)
35
30
  end
36
31
  end
37
32
  end
@@ -35,20 +35,14 @@ module Kameleoon
35
35
  return false
36
36
  end
37
37
 
38
- case @version_match_type
39
- when Operator::EQUAL
40
- version_compare == @cached_version_condition
41
- when Operator::GREATER
42
- version_compare > @cached_version_condition
43
- when Operator::LOWER
44
- version_compare < @cached_version_condition
45
- else
38
+ unless Operator.comparison?(@version_match_type)
46
39
  Logging::KameleoonLogger.error(
47
40
  "Unexpected comparing operation for '%s' condition: '%s'",
48
41
  type, @version_match_type
49
42
  )
50
- false
43
+ return false
51
44
  end
45
+ Operator.compare(@version_match_type, version_compare, @cached_version_condition)
52
46
  end
53
47
  end
54
48
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kameleoon
4
- SDK_VERSION = '3.23.0'
4
+ SDK_VERSION = '3.24.0'
5
5
  SDK_NAME = 'RUBY'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kameleoon-client-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.23.0
4
+ version: 3.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kameleoon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-19 00:00:00.000000000 Z
11
+ date: 2026-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby