launchdarkly-server-sdk 8.4.2 → 8.5.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: c04f38ba70b95c1446fc0aaffd2f3020e208501e9ede2313b559848792c1bf81
4
- data.tar.gz: 6dd37514e2588d78c995702af1d66d6f00cdc3762ce4908690a2a4e13ab5c46d
3
+ metadata.gz: b1774083dedfc1cdc4e32a2c2855a91c1075cd22aeb1ec55ff68d305c3d82d11
4
+ data.tar.gz: a07b4851ed59e16271e5d32ad83027899846d8cc1dd18718ae2d3eed84ab27a2
5
5
  SHA512:
6
- metadata.gz: 40f20870dfa777687da11f7611255ee7f15dde800c7ac9860e5a673643c9d7d19841932162fcabef1d57e6a9ab7710fb3d06ea72567336a5c26ecb0cdd220f74
7
- data.tar.gz: bbf303fc081003f0a5e71f2fd38dc48f707958c5c33f6f450982db6c3fecb7076f287460d597414b52c8e4181d95c55babd599fca7877bebe4ff9d82d38e6dd5
6
+ metadata.gz: 8407bb6f129c50da2b93c43cc17c53383ad1e01e7bc11ce803d1743d89bc42dda73734dd055e097f7fe11224082125e46aa23f63284fa06753f7e51678b065f1
7
+ data.tar.gz: 313092bf41b6a3f82b603561f7fd3dd921318811ce542ac0c0d35d5d5677aba1060111b77dc810cf5caf7492c9e52161fbf54eac3bbd46709440eb4729abb055
@@ -334,6 +334,49 @@ module LaunchDarkly
334
334
  multi_kind? ? individual_context(key.to_s) : get_value(key)
335
335
  end
336
336
 
337
+ #
338
+ # Convert the LDContext to a JSON string.
339
+ #
340
+ # @param args [Array]
341
+ # @return [String]
342
+ #
343
+ def to_json(*args)
344
+ JSON.generate(to_h, *args)
345
+ end
346
+
347
+ #
348
+ # Convert the LDContext to a hash. If the LDContext is invalid, the hash will contain an error key with the error
349
+ # message.
350
+ #
351
+ # @return [Hash]
352
+ #
353
+ def to_h
354
+ return {error: error} unless valid?
355
+ return hash_single_kind unless multi_kind?
356
+
357
+ hash = {kind: 'multi'}
358
+ @contexts.each do |context|
359
+ single_kind_hash = context.to_h
360
+ kind = single_kind_hash.delete(:kind)
361
+ hash[kind] = single_kind_hash
362
+ end
363
+
364
+ hash
365
+ end
366
+
367
+ protected def hash_single_kind
368
+ hash = attributes.nil? ? {} : attributes.clone
369
+
370
+ hash[:kind] = kind
371
+ hash[:key] = key
372
+
373
+ hash[:name] = name unless name.nil?
374
+ hash[:anonymous] = anonymous if anonymous
375
+ hash[:_meta] = {privateAttributes: private_attributes} unless private_attributes.empty?
376
+
377
+ hash
378
+ end
379
+
337
380
  #
338
381
  # Retrieve the value of any top level, addressable attribute.
339
382
  #
@@ -36,18 +36,13 @@ module LaunchDarkly
36
36
  @paths = [ @paths ]
37
37
  end
38
38
  @auto_update = options[:auto_update]
39
- if @auto_update && @@have_listen && !options[:force_polling] # force_polling is used only for tests
40
- # We have seen unreliable behavior in the 'listen' gem in JRuby 9.1 (https://github.com/guard/listen/issues/449).
41
- # Therefore, on that platform we'll fall back to file polling instead.
42
- if defined?(JRUBY_VERSION) && JRUBY_VERSION.start_with?("9.1.")
43
- @use_listen = false
44
- else
45
- @use_listen = true
46
- end
47
- end
39
+ @use_listen = @auto_update && @@have_listen && !options[:force_polling]
48
40
  @poll_interval = options[:poll_interval] || 1
49
41
  @initialized = Concurrent::AtomicBoolean.new(false)
50
42
  @ready = Concurrent::Event.new
43
+
44
+ @version_lock = Mutex.new
45
+ @last_version = 1
51
46
  end
52
47
 
53
48
  def initialized?
@@ -101,14 +96,22 @@ module LaunchDarkly
101
96
  end
102
97
 
103
98
  def load_file(path, all_data)
99
+ version = 1
100
+ @version_lock.synchronize {
101
+ version = @last_version
102
+ @last_version += 1
103
+ }
104
+
104
105
  parsed = parse_content(IO.read(path))
105
106
  (parsed[:flags] || {}).each do |key, flag|
107
+ flag[:version] = version
106
108
  add_item(all_data, FEATURES, flag)
107
109
  end
108
110
  (parsed[:flagValues] || {}).each do |key, value|
109
- add_item(all_data, FEATURES, make_flag_with_value(key.to_s, value))
111
+ add_item(all_data, FEATURES, make_flag_with_value(key.to_s, value, version))
110
112
  end
111
113
  (parsed[:segments] || {}).each do |key, segment|
114
+ segment[:version] = version
112
115
  add_item(all_data, SEGMENTS, segment)
113
116
  end
114
117
  end
@@ -142,10 +145,11 @@ module LaunchDarkly
142
145
  items[key] = Model.deserialize(kind, item)
143
146
  end
144
147
 
145
- def make_flag_with_value(key, value)
148
+ def make_flag_with_value(key, value, version)
146
149
  {
147
150
  key: key,
148
151
  on: true,
152
+ version: version,
149
153
  fallthrough: { variation: 0 },
150
154
  variations: [ value ],
151
155
  }
@@ -93,7 +93,7 @@ module LaunchDarkly
93
93
  # Note that the default implementation of this feature is based on polling the filesystem,
94
94
  # which may not perform well. If you install the 'listen' gem (not included by default, to
95
95
  # avoid adding unwanted dependencies to the SDK), its native file watching mechanism will be
96
- # used instead. However, 'listen' will not be used in JRuby 9.1 due to a known instability.
96
+ # used instead.
97
97
  # @option options [Float] :poll_interval The minimum interval, in seconds, between checks for
98
98
  # file modifications - used only if auto_update is true, and if the native file-watching
99
99
  # mechanism from 'listen' is not being used. The default value is 1 second.
@@ -124,13 +124,18 @@ module LaunchDarkly
124
124
  end
125
125
 
126
126
  ready = @data_source.start
127
- if wait_for_sec > 0
128
- ok = ready.wait(wait_for_sec)
129
- if !ok
130
- @config.logger.error { "[LDClient] Timeout encountered waiting for LaunchDarkly client initialization" }
131
- elsif !@data_source.initialized?
132
- @config.logger.error { "[LDClient] LaunchDarkly client initialization failed" }
133
- end
127
+
128
+ return unless wait_for_sec > 0
129
+
130
+ if wait_for_sec > 60
131
+ @config.logger.warn { "[LDClient] Client was configured to block for up to #{wait_for_sec} seconds when initializing. We recommend blocking no longer than 60." }
132
+ end
133
+
134
+ ok = ready.wait(wait_for_sec)
135
+ if !ok
136
+ @config.logger.error { "[LDClient] Timeout encountered waiting for LaunchDarkly client initialization" }
137
+ elsif !@data_source.initialized?
138
+ @config.logger.error { "[LDClient] LaunchDarkly client initialization failed" }
134
139
  end
135
140
  end
136
141
 
@@ -238,6 +238,16 @@ module LaunchDarkly
238
238
  ([error] + components).hash
239
239
  end
240
240
 
241
+ #
242
+ # Convert the Reference to a JSON string.
243
+ #
244
+ # @param args [Array]
245
+ # @return [String]
246
+ #
247
+ def to_json(*args)
248
+ JSON.generate(@raw_path, *args)
249
+ end
250
+
241
251
  #
242
252
  # Performs unescaping of attribute reference path components:
243
253
  #
@@ -1,3 +1,3 @@
1
1
  module LaunchDarkly
2
- VERSION = "8.4.2" # x-release-please-version
2
+ VERSION = "8.5.0" # x-release-please-version
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: launchdarkly-server-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.4.2
4
+ version: 8.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LaunchDarkly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-03 00:00:00.000000000 Z
11
+ date: 2024-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-dynamodb