configcat 3.0.0 → 3.1.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 +4 -4
- data/lib/configcat/configcatclient.rb +54 -1
- data/lib/configcat/rolloutevaluator.rb +21 -16
- data/lib/configcat/user.rb +5 -5
- data/lib/configcat/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b842d2ff2f62e6a6c3dbe2ddab53c561e4b1db93f3928ce805044127cd2d7819
|
4
|
+
data.tar.gz: 6d64d084c4a732d26d54879d914f4e9ce1722b9e73fee2aa4161cc5503e152d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83a7d19dc642e492bb5443a1fc42f0f35db8f5278f02582848e8677133f4450faa41a1a30b158ccdca58bc5396cad109b914fa4851e4db74dcf03df1f5129d00
|
7
|
+
data.tar.gz: 2e79ed9965f3c9da2f8afd9fed4636b6d349b0bda09fdfb0d8398b6e4334a458713114d23083fc5f611878ea02801c5e8ea1e73fad54f6e580ef1c098e8f9d7c
|
@@ -7,6 +7,7 @@ require 'configcat/lazyloadingcachepolicy'
|
|
7
7
|
require 'configcat/rolloutevaluator'
|
8
8
|
|
9
9
|
module ConfigCat
|
10
|
+
KeyValue = Struct.new(:key, :value)
|
10
11
|
class ConfigCatClient
|
11
12
|
def initialize(sdk_key,
|
12
13
|
poll_interval_seconds:60,
|
@@ -49,7 +50,8 @@ module ConfigCat
|
|
49
50
|
if config === nil
|
50
51
|
return default_value
|
51
52
|
end
|
52
|
-
|
53
|
+
value, variation_id = RolloutEvaluator.evaluate(key, user, default_value, nil, config)
|
54
|
+
return value
|
53
55
|
end
|
54
56
|
|
55
57
|
def get_all_keys()
|
@@ -60,6 +62,57 @@ module ConfigCat
|
|
60
62
|
return config.keys
|
61
63
|
end
|
62
64
|
|
65
|
+
def get_variation_id(key, default_variation_id, user=nil)
|
66
|
+
config = @_cache_policy.get()
|
67
|
+
if config === nil
|
68
|
+
ConfigCat.logger.warn("Evaluating get_variation_id('%s') failed. Cache is empty. "\
|
69
|
+
"Returning default_variation_id in your get_variation_id call: [%s]." %
|
70
|
+
[key, default_variation_id.to_s])
|
71
|
+
return default_variation_id
|
72
|
+
end
|
73
|
+
value, variation_id = RolloutEvaluator.evaluate(key, user, nil, default_variation_id, config)
|
74
|
+
return variation_id
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_all_variation_ids(user: nil)
|
78
|
+
keys = get_all_keys()
|
79
|
+
variation_ids = []
|
80
|
+
for key in keys
|
81
|
+
variation_id = get_variation_id(key, nil, user)
|
82
|
+
if !variation_id.equal?(nil)
|
83
|
+
variation_ids.push(variation_id)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
return variation_ids
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_key_and_value(variation_id)
|
90
|
+
config = @_cache_policy.get()
|
91
|
+
if config === nil
|
92
|
+
ConfigCat.logger.warn("Evaluating get_variation_id('%s') failed. Cache is empty. Returning nil." % variation_id)
|
93
|
+
return nil
|
94
|
+
end
|
95
|
+
for key, value in config
|
96
|
+
if variation_id == value.fetch(RolloutEvaluator::VARIATION_ID, nil)
|
97
|
+
return KeyValue.new(key, value[RolloutEvaluator::VALUE])
|
98
|
+
end
|
99
|
+
|
100
|
+
rollout_rules = value.fetch(RolloutEvaluator::ROLLOUT_RULES, [])
|
101
|
+
for rollout_rule in rollout_rules
|
102
|
+
if variation_id == rollout_rule.fetch(RolloutEvaluator::VARIATION_ID, nil)
|
103
|
+
return KeyValue.new(key, rollout_rule[RolloutEvaluator::VALUE])
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
rollout_percentage_items = value.fetch(RolloutEvaluator::ROLLOUT_PERCENTAGE_ITEMS, [])
|
108
|
+
for rollout_percentage_item in rollout_percentage_items
|
109
|
+
if variation_id == rollout_percentage_item.fetch(RolloutEvaluator::VARIATION_ID, nil)
|
110
|
+
return KeyValue.new(key, rollout_percentage_item[RolloutEvaluator::VALUE])
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
63
116
|
def force_refresh()
|
64
117
|
@_cache_policy.force_refresh()
|
65
118
|
end
|
@@ -13,14 +13,15 @@ module ConfigCat
|
|
13
13
|
ROLLOUT_PERCENTAGE_ITEMS = "p"
|
14
14
|
PERCENTAGE = "p"
|
15
15
|
ROLLOUT_RULES = "r"
|
16
|
+
VARIATION_ID = "i"
|
16
17
|
|
17
|
-
def self.evaluate(key, user, default_value, config)
|
18
|
+
def self.evaluate(key, user, default_value, default_variation_id, config)
|
18
19
|
ConfigCat.logger.info("Evaluating get_value('%s')." % key)
|
19
20
|
|
20
21
|
setting_descriptor = config.fetch(key, nil)
|
21
22
|
if setting_descriptor === nil
|
22
23
|
ConfigCat.logger.error("Evaluating get_value('%s') failed. Value not found for key '%s'. Returning default_value: [%s]. Here are the available keys: %s" % [key, key, default_value.to_s, config.keys.join(", ")])
|
23
|
-
return default_value
|
24
|
+
return default_value, default_variation_id
|
24
25
|
end
|
25
26
|
|
26
27
|
rollout_rules = setting_descriptor.fetch(ROLLOUT_RULES, [])
|
@@ -35,8 +36,9 @@ module ConfigCat
|
|
35
36
|
ConfigCat.logger.warn("Evaluating get_value('%s'). UserObject missing! You should pass a UserObject to get_value(), in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/" % key)
|
36
37
|
end
|
37
38
|
return_value = setting_descriptor.fetch(VALUE, default_value)
|
39
|
+
return_variation_id = setting_descriptor.fetch(VARIATION_ID, default_variation_id)
|
38
40
|
ConfigCat.logger.info("Returning [%s]" % return_value.to_s)
|
39
|
-
return return_value
|
41
|
+
return return_value, return_variation_id
|
40
42
|
end
|
41
43
|
|
42
44
|
ConfigCat.logger.info("User object:\n%s" % user.to_s)
|
@@ -54,30 +56,31 @@ module ConfigCat
|
|
54
56
|
end
|
55
57
|
|
56
58
|
value = rollout_rule.fetch(VALUE, nil)
|
59
|
+
variation_id = rollout_rule.fetch(VARIATION_ID, default_variation_id)
|
57
60
|
|
58
61
|
# IS ONE OF
|
59
62
|
if comparator == 0
|
60
63
|
if comparison_value.to_s.split(",").map { |x| x.strip() }.include?(user_value.to_s)
|
61
64
|
ConfigCat.logger.info(format_match_rule(comparison_attribute, user_value, comparator, comparison_value, value))
|
62
|
-
return value
|
65
|
+
return value, variation_id
|
63
66
|
end
|
64
67
|
# IS NOT ONE OF
|
65
68
|
elsif comparator == 1
|
66
69
|
if !comparison_value.to_s.split(",").map { |x| x.strip() }.include?(user_value.to_s)
|
67
70
|
ConfigCat.logger.info(format_match_rule(comparison_attribute, user_value, comparator, comparison_value, value))
|
68
|
-
return value
|
71
|
+
return value, variation_id
|
69
72
|
end
|
70
73
|
# CONTAINS
|
71
74
|
elsif comparator == 2
|
72
75
|
if user_value.to_s.include?(comparison_value.to_s)
|
73
76
|
ConfigCat.logger.info(format_match_rule(comparison_attribute, user_value, comparator, comparison_value, value))
|
74
|
-
return value
|
77
|
+
return value, variation_id
|
75
78
|
end
|
76
79
|
# DOES NOT CONTAIN
|
77
80
|
elsif comparator == 3
|
78
81
|
if !user_value.to_s.include?(comparison_value.to_s)
|
79
82
|
ConfigCat.logger.info(format_match_rule(comparison_attribute, user_value, comparator, comparison_value, value))
|
80
|
-
return value
|
83
|
+
return value, variation_id
|
81
84
|
end
|
82
85
|
# IS ONE OF, IS NOT ONE OF (Semantic version)
|
83
86
|
elsif (4 <= comparator) && (comparator <= 5)
|
@@ -90,7 +93,7 @@ module ConfigCat
|
|
90
93
|
}
|
91
94
|
if match && comparator == 4 || !match && comparator == 5
|
92
95
|
ConfigCat.logger.info(format_match_rule(comparison_attribute, user_value, comparator, comparison_value, value))
|
93
|
-
return value
|
96
|
+
return value, variation_id
|
94
97
|
end
|
95
98
|
rescue ArgumentError => e
|
96
99
|
ConfigCat.logger.warn(format_validation_error_rule(comparison_attribute, user_value, comparator, comparison_value, e.to_s))
|
@@ -106,7 +109,7 @@ module ConfigCat
|
|
106
109
|
(comparator == 8 && user_value_version > comparison_value_version) ||
|
107
110
|
(comparator == 9 && user_value_version >= comparison_value_version)
|
108
111
|
ConfigCat.logger.info(format_match_rule(comparison_attribute, user_value, comparator, comparison_value, value))
|
109
|
-
return value
|
112
|
+
return value, variation_id
|
110
113
|
end
|
111
114
|
rescue ArgumentError => e
|
112
115
|
ConfigCat.logger.warn(format_validation_error_rule(comparison_attribute, user_value, comparator, comparison_value, e.to_s))
|
@@ -123,7 +126,7 @@ module ConfigCat
|
|
123
126
|
(comparator == 14 && user_value_float > comparison_value_float) ||
|
124
127
|
(comparator == 15 && user_value_float >= comparison_value_float)
|
125
128
|
ConfigCat.logger.info(format_match_rule(comparison_attribute, user_value, comparator, comparison_value, value))
|
126
|
-
return value
|
129
|
+
return value, variation_id
|
127
130
|
end
|
128
131
|
rescue Exception => e
|
129
132
|
ConfigCat.logger.warn(format_validation_error_rule(comparison_attribute, user_value, comparator, comparison_value, e.to_s))
|
@@ -133,13 +136,13 @@ module ConfigCat
|
|
133
136
|
elsif comparator == 16
|
134
137
|
if comparison_value.to_s.split(",").map { |x| x.strip() }.include?(Digest::SHA1.hexdigest(user_value).to_s)
|
135
138
|
ConfigCat.logger.info(format_match_rule(comparison_attribute, user_value, comparator, comparison_value, value))
|
136
|
-
return value
|
139
|
+
return value, variation_id
|
137
140
|
end
|
138
141
|
# IS NOT ONE OF (Sensitive)
|
139
142
|
elsif comparator == 17
|
140
143
|
if !comparison_value.to_s.split(",").map { |x| x.strip() }.include?(Digest::SHA1.hexdigest(user_value).to_s)
|
141
144
|
ConfigCat.logger.info(format_match_rule(comparison_attribute, user_value, comparator, comparison_value, value))
|
142
|
-
return value
|
145
|
+
return value, variation_id
|
143
146
|
end
|
144
147
|
end
|
145
148
|
ConfigCat.logger.info(format_no_match_rule(comparison_attribute, user_value, comparator, comparison_value))
|
@@ -154,14 +157,16 @@ module ConfigCat
|
|
154
157
|
bucket += rollout_percentage_item.fetch(PERCENTAGE, 0)
|
155
158
|
if hash_val < bucket
|
156
159
|
percentage_value = rollout_percentage_item.fetch(VALUE, nil)
|
160
|
+
variation_id = rollout_percentage_item.fetch(VARIATION_ID, default_variation_id)
|
157
161
|
ConfigCat.logger.info("Evaluating %% options. Returning %s" % percentage_value)
|
158
|
-
return percentage_value
|
162
|
+
return percentage_value, variation_id
|
159
163
|
end
|
160
164
|
end
|
161
165
|
end
|
162
|
-
|
163
|
-
|
164
|
-
|
166
|
+
return_value = setting_descriptor.fetch(VALUE, default_value)
|
167
|
+
return_variation_id = setting_descriptor.fetch(VARIATION_ID, default_variation_id)
|
168
|
+
ConfigCat.logger.info("Returning %s" % return_value)
|
169
|
+
return return_value, return_variation_id
|
165
170
|
end
|
166
171
|
|
167
172
|
private
|
data/lib/configcat/user.rb
CHANGED
@@ -5,11 +5,11 @@ module ConfigCat
|
|
5
5
|
# The user object for variation evaluation
|
6
6
|
#
|
7
7
|
|
8
|
-
PREDEFINED = ["
|
8
|
+
PREDEFINED = ["Identifier", "Email", "Country"]
|
9
9
|
|
10
10
|
def initialize(identifier, email: nil, country: nil, custom: nil)
|
11
|
-
@__identifier = identifier
|
12
|
-
@__data = {"
|
11
|
+
@__identifier = (!identifier.equal?(nil)) ? identifier : ""
|
12
|
+
@__data = {"Identifier" => identifier, "Email" => email, "Country" => country}
|
13
13
|
@__custom = custom
|
14
14
|
end
|
15
15
|
|
@@ -18,14 +18,14 @@ module ConfigCat
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def get_attribute(attribute)
|
21
|
-
attribute = attribute.to_s
|
21
|
+
attribute = attribute.to_s
|
22
22
|
if PREDEFINED.include?(attribute)
|
23
23
|
return @__data[attribute]
|
24
24
|
end
|
25
25
|
|
26
26
|
if !@__custom.equal?(nil)
|
27
27
|
@__custom.each do |customField, customValue|
|
28
|
-
if customField.to_s
|
28
|
+
if customField.to_s == attribute
|
29
29
|
return customValue
|
30
30
|
end
|
31
31
|
end
|
data/lib/configcat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configcat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ConfigCat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -135,8 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
|
-
|
139
|
-
rubygems_version: 2.7.7
|
138
|
+
rubygems_version: 3.0.8
|
140
139
|
signing_key:
|
141
140
|
specification_version: 4
|
142
141
|
summary: ConfigCat SDK for Ruby.
|