configcat 7.0.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,45 @@
1
1
  module ConfigCat
2
- # The user object for variation evaluation
2
+ # User Object. Contains user attributes which are used for evaluating targeting rules and percentage options.
3
3
  class User
4
4
  PREDEFINED = ["Identifier", "Email", "Country"]
5
5
 
6
6
  attr_reader :identifier
7
7
 
8
+ # Initialize a User object.
9
+ # Args:
10
+ # identifier: The unique identifier of the user or session (e.g. email address, primary key, session ID, etc.)
11
+ # email: Email address of the user.
12
+ # country: Country of the user.
13
+ # custom: Custom attributes of the user for advanced targeting rule definitions (e.g. role, subscription type, etc.)
14
+ # All comparators support string values as User Object attribute (in some cases they need to be provided in a
15
+ # specific format though, see below), but some of them also support other types of values. It depends on the
16
+ # comparator how the values will be handled. The following rules apply:
17
+ # Text-based comparators (EQUALS, IS_ONE_OF, etc.)
18
+ # * accept string values,
19
+ # * all other values are automatically converted to string
20
+ # (a warning will be logged but evaluation will continue as normal).
21
+ # SemVer-based comparators (IS_ONE_OF_SEMVER, LESS_THAN_SEMVER, GREATER_THAN_SEMVER, etc.)
22
+ # * accept string values containing a properly formatted, valid semver value,
23
+ # * all other values are considered invalid
24
+ # (a warning will be logged and the currently evaluated targeting rule will be skipped).
25
+ # Number-based comparators (EQUALS_NUMBER, LESS_THAN_NUMBER, GREATER_THAN_OR_EQUAL_NUMBER, etc.)
26
+ # * accept float values and all other numeric values which can safely be converted to float,
27
+ # * accept string values containing a properly formatted, valid float value,
28
+ # * all other values are considered invalid
29
+ # (a warning will be logged and the currently evaluated targeting rule will be skipped).
30
+ # Date time-based comparators (BEFORE_DATETIME / AFTER_DATETIME)
31
+ # * accept datetime values, which are automatically converted to a second-based Unix timestamp
32
+ # (datetime values with naive timezone are considered to be in UTC),
33
+ # * accept float values representing a second-based Unix timestamp
34
+ # and all other numeric values which can safely be converted to float,
35
+ # * accept string values containing a properly formatted, valid float value,
36
+ # * all other values are considered invalid
37
+ # (a warning will be logged and the currently evaluated targeting rule will be skipped).
38
+ # String array-based comparators (ARRAY_CONTAINS_ANY_OF / ARRAY_NOT_CONTAINS_ANY_OF)
39
+ # * accept arrays of strings,
40
+ # * accept string values containing a valid JSON string which can be deserialized to an array of strings,
41
+ # * all other values are considered invalid
42
+ # (a warning will be logged and the currently evaluated targeting rule will be skipped).
8
43
  def initialize(identifier, email: nil, country: nil, custom: nil)
9
44
  @identifier = (!identifier.equal?(nil)) ? identifier : ""
10
45
  @data = { "Identifier" => identifier, "Email" => email, "Country" => country }
@@ -26,10 +61,14 @@ module ConfigCat
26
61
  dump = {
27
62
  'Identifier': @identifier,
28
63
  'Email': @data['Email'],
29
- 'Country': @data['Country'],
30
- 'Custom': @custom,
64
+ 'Country': @data['Country']
31
65
  }
32
- return dump.to_json
66
+ dump.merge!(@custom) if @custom
67
+ filtered_dump = dump.reject { |_, v| v.nil? }
68
+ formatted_dump = filtered_dump.transform_values do |value|
69
+ value.is_a?(DateTime) ? value.strftime('%Y-%m-%dT%H:%M:%S.%L%z') : value
70
+ end
71
+ return JSON.generate(formatted_dump, ascii_only: false, separators: %w[, :])
33
72
  end
34
73
  end
35
74
  end
@@ -3,8 +3,28 @@ module ConfigCat
3
3
  DISTANT_FUTURE = Float::INFINITY
4
4
  DISTANT_PAST = 0
5
5
 
6
+ def self.get_date_time(seconds_since_epoch)
7
+ Time.at(seconds_since_epoch).utc
8
+ end
9
+
6
10
  def self.get_utc_now_seconds_since_epoch
7
- return Time.now.utc.to_f
11
+ Time.now.utc.to_f
12
+ end
13
+
14
+ def self.get_seconds_since_epoch(date_time)
15
+ date_time.to_time.to_f
16
+ end
17
+
18
+ def self.is_string_list(value)
19
+ # Check if the value is an Array
20
+ return false unless value.is_a?(Array)
21
+
22
+ # Check if all elements in the Array are Strings
23
+ value.each do |item|
24
+ return false unless item.is_a?(String)
25
+ end
26
+
27
+ return true
8
28
  end
9
29
  end
10
30
  end
@@ -1,3 +1,3 @@
1
1
  module ConfigCat
2
- VERSION = "7.0.0"
2
+ VERSION = "8.0.0"
3
3
  end
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: 7.0.0
4
+ version: 8.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ConfigCat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-17 00:00:00.000000000 Z
11
+ date: 2024-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -120,6 +120,7 @@ extensions: []
120
120
  extra_rdoc_files: []
121
121
  files:
122
122
  - lib/configcat.rb
123
+ - lib/configcat/config.rb
123
124
  - lib/configcat/configcache.rb
124
125
  - lib/configcat/configcatclient.rb
125
126
  - lib/configcat/configcatlogger.rb
@@ -127,9 +128,10 @@ files:
127
128
  - lib/configcat/configentry.rb
128
129
  - lib/configcat/configfetcher.rb
129
130
  - lib/configcat/configservice.rb
130
- - lib/configcat/constants.rb
131
131
  - lib/configcat/datagovernance.rb
132
+ - lib/configcat/evaluationcontext.rb
132
133
  - lib/configcat/evaluationdetails.rb
134
+ - lib/configcat/evaluationlogbuilder.rb
133
135
  - lib/configcat/interfaces.rb
134
136
  - lib/configcat/localdictionarydatasource.rb
135
137
  - lib/configcat/localfiledatasource.rb
@@ -1,18 +0,0 @@
1
- module ConfigCat
2
- CONFIG_FILE_NAME = "config_v5"
3
- SERIALIZATION_FORMAT_VERSION = "v2"
4
-
5
- PREFERENCES = "p"
6
- BASE_URL = "u"
7
- REDIRECT = "r"
8
-
9
- FEATURE_FLAGS = "f"
10
- VALUE = "v"
11
- COMPARATOR = "t"
12
- COMPARISON_ATTRIBUTE = "a"
13
- COMPARISON_VALUE = "c"
14
- ROLLOUT_PERCENTAGE_ITEMS = "p"
15
- PERCENTAGE = "p"
16
- ROLLOUT_RULES = "r"
17
- VARIATION_ID = "i"
18
- end