eppo-server-sdk 0.2.3 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eppo_client/configuration_store.rb +7 -1
- data/lib/eppo_client/lru_cache.rb +1 -1
- data/lib/eppo_client/rules.rb +34 -2
- data/lib/eppo_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c75a17999fe2f903a2bef17b02bfefd74a3668249f5b67254c8e0b41d21f27d8
|
4
|
+
data.tar.gz: 18e358b1910d97839d8d20653506aecc7db9986a6b3dee80c50065a27059c7a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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)
|
data/lib/eppo_client/rules.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/eppo_client/version.rb
CHANGED
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.
|
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:
|
11
|
+
date: 2024-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|