eppo-server-sdk 0.2.3 → 0.2.5

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: d9c570d34608a7d3037d80c5aa161c383e2d7b618eef75383f53d002e772204a
4
- data.tar.gz: 6fd21d3000781bada11f2f43b49fce0871fc74b1929387bddf277a1cb3c5db7f
3
+ metadata.gz: c75a17999fe2f903a2bef17b02bfefd74a3668249f5b67254c8e0b41d21f27d8
4
+ data.tar.gz: 18e358b1910d97839d8d20653506aecc7db9986a6b3dee80c50065a27059c7a7
5
5
  SHA512:
6
- metadata.gz: 27fbeb76e52adcce05cffa3a41e92b09790db53e76dafa4ded3d5d7df4d6b4cce37cb7c79056153d6965ec01d579a42a3140b88626c26c0eebe3874cde49dee4
7
- data.tar.gz: 3a1f20881a19c385e4c37c141045d8e870d85fc81f650d07a736b4c8f39b8ebba0a24380231da334c40a51c8b49b3431a2096746d3e9d4f2fdaaa8d382e568c4
6
+ metadata.gz: aa31863564c84dd92d515b493b2aa7e31604e409987d51556bc85868d642a09396c6f61b297302e92d0a6dd411e3b1403efbd56bc055478c94b7ed593f370285
7
+ data.tar.gz: b9b26bdca34234ce0c1a19c1b633bc78739a6115f752e900ceaeb3a9c91f0a2acaef13998cd0c0e9d6ee9cf4f66ad23424f96fa7ca40df573550d2a1c51ae364
@@ -20,9 +20,15 @@ module EppoClient
20
20
 
21
21
  def assign_configurations(configs)
22
22
  @lock.with_write_lock do
23
+ # Create a temporary new cache and populate it.
24
+ new_cache = EppoClient::LRUCache.new(@cache.size)
23
25
  configs.each do |key, config|
24
- @cache[key] = config
26
+ new_cache[key] = config
25
27
  end
28
+
29
+ # Replace the old cache with the new one.
30
+ # Performs an atomic swap.
31
+ @cache = new_cache
26
32
  end
27
33
  end
28
34
  end
@@ -5,7 +5,7 @@ module EppoClient
5
5
  # and re-inserting a key-value pair on access moves the key to the last position. When an
6
6
  # entry is added and the cache is full, the first entry is removed.
7
7
  class LRUCache
8
- attr_reader :cache
8
+ attr_reader :cache, :size
9
9
 
10
10
  # Creates a new LRUCache that can hold +size+ entries.
11
11
  def initialize(size)
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'semver'
4
+
3
5
  # The helper module for rules
4
6
  module EppoClient
5
7
  module OperatorType
@@ -60,7 +62,12 @@ module EppoClient
60
62
  when OperatorType::NOT_ONE_OF
61
63
  !condition.value.map(&:downcase).include?(subject_value.to_s.downcase)
62
64
  else
63
- subject_value.is_a?(Numeric) && evaluate_numeric_condition(subject_value, condition)
65
+ # Numeric operator: value could be numeric or semver.
66
+ if subject_value.is_a?(Numeric)
67
+ evaluate_numeric_condition(subject_value, condition)
68
+ elsif valid_semver?(subject_value)
69
+ compare_semver(subject_value, condition.value, condition.operator)
70
+ end
64
71
  end
65
72
  end
66
73
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
@@ -82,6 +89,31 @@ module EppoClient
82
89
  end
83
90
  # rubocop:enable Metrics/MethodLength
84
91
 
92
+ # rubocop:disable Metrics/MethodLength
93
+ def compare_semver(attribute_value, condition_value, operator)
94
+ unless valid_semver?(attribute_value) && valid_semver?(condition_value)
95
+ return false
96
+ end
97
+
98
+ case operator
99
+ when OperatorType::GT
100
+ SemVer.parse(attribute_value) > SemVer.parse(condition_value)
101
+ when OperatorType::GTE
102
+ SemVer.parse(attribute_value) >= SemVer.parse(condition_value)
103
+ when OperatorType::LT
104
+ SemVer.parse(attribute_value) < SemVer.parse(condition_value)
105
+ when OperatorType::LTE
106
+ SemVer.parse(attribute_value) <= SemVer.parse(condition_value)
107
+ else
108
+ false
109
+ end
110
+ end
111
+ # rubocop:enable Metrics/MethodLength
112
+
113
+ def valid_semver?(string)
114
+ !SemVer.parse(string).nil?
115
+ end
116
+
85
117
  module_function :find_matching_rule, :matches_rule, :evaluate_condition,
86
- :evaluate_numeric_condition
118
+ :evaluate_numeric_condition, :valid_semver?, :compare_semver
87
119
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EppoClient
4
- VERSION = '0.2.3'
4
+ VERSION = '0.2.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eppo-server-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eppo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-27 00:00:00.000000000 Z
11
+ date: 2024-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby