Skip to content

Commit 7e96729

Browse files
authored
fix: Fix flag tracker to properly match string keys (#370)
1 parent 83666b7 commit 7e96729

8 files changed

Lines changed: 28 additions & 28 deletions

File tree

lib/ldclient-rb/impl/data_source.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def update_status(new_state, new_error)
178178
private def send_change_events(affected_items)
179179
affected_items.each do |item|
180180
if item[:kind] == Impl::DataStore::FEATURES
181-
@flag_change_broadcaster.broadcast(LaunchDarkly::Interfaces::FlagChange.new(item[:key]))
181+
@flag_change_broadcaster.broadcast(LaunchDarkly::Interfaces::FlagChange.new(item[:key].to_s))
182182
end
183183
end
184184
end

lib/ldclient-rb/impl/data_store/in_memory_feature_store.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def initialized?
5858
#
5959
# Initializes the store with a full set of data, replacing any existing data.
6060
#
61-
# @param collections [Hash<LaunchDarkly::Impl::DataStore::DataKind, Hash<String, Hash>>] Hash of data kinds to collections of items
61+
# @param collections [Hash<LaunchDarkly::Impl::DataStore::DataKind, Hash<Symbol, Hash>>] Hash of data kinds to collections of items
6262
# @return [Boolean] true if successful, false otherwise
6363
#
6464
def set_basis(collections)
@@ -80,7 +80,7 @@ def set_basis(collections)
8080
#
8181
# Applies a delta update to the store.
8282
#
83-
# @param collections [Hash<LaunchDarkly::Impl::DataStore::DataKind, Hash<String, Hash>>] Hash of data kinds to collections with updates
83+
# @param collections [Hash<LaunchDarkly::Impl::DataStore::DataKind, Hash<Symbol, Hash>>] Hash of data kinds to collections with updates
8484
# @return [Boolean] true if successful, false otherwise
8585
#
8686
def apply_delta(collections)
@@ -105,7 +105,7 @@ def apply_delta(collections)
105105
#
106106
# Decodes a collection of items.
107107
#
108-
# @param collections [Hash<LaunchDarkly::Impl::DataStore::DataKind, Hash<String, Hash>>] Hash of data kinds to collections
108+
# @param collections [Hash<LaunchDarkly::Impl::DataStore::DataKind, Hash<Symbol, Hash>>] Hash of data kinds to collections
109109
# @return [Hash<LaunchDarkly::Impl::DataStore::DataKind, Hash<Symbol, Hash>>, nil] Decoded collection with symbol keys, or nil on error
110110
#
111111
private def decode_collection(collections)

lib/ldclient-rb/impl/data_store/store.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def get_data_store_status_provider
193193
#
194194
# Set the basis of the store. Any existing data is discarded.
195195
#
196-
# @param collections [Hash{Object => Hash{String => Hash}}] Hash of data kinds to collections of items
196+
# @param collections [Hash{Object => Hash{Symbol => Hash}}] Hash of data kinds to collections of items
197197
# @param selector [LaunchDarkly::Interfaces::DataSystem::Selector, nil] The selector
198198
# @param persist [Boolean] Whether to persist the data
199199
# @return [void]
@@ -234,7 +234,7 @@ def get_data_store_status_provider
234234
#
235235
# Apply a delta update to the store.
236236
#
237-
# @param collections [Hash{Object => Hash{String => Hash}}] Hash of data kinds to collections with updates
237+
# @param collections [Hash{Object => Hash{Symbol => Hash}}] Hash of data kinds to collections with updates
238238
# @param selector [LaunchDarkly::Interfaces::DataSystem::Selector, nil] The selector
239239
# @param persist [Boolean] Whether to persist the changes
240240
# @return [void]
@@ -328,16 +328,16 @@ def get_data_store_status_provider
328328
private def send_change_events(affected_items)
329329
affected_items.each do |item|
330330
if item[:kind] == FEATURES
331-
@flag_change_broadcaster.broadcast(LaunchDarkly::Interfaces::FlagChange.new(item[:key]))
331+
@flag_change_broadcaster.broadcast(LaunchDarkly::Interfaces::FlagChange.new(item[:key].to_s))
332332
end
333333
end
334334
end
335335

336336
#
337337
# Compute which items changed between old and new data sets.
338338
#
339-
# @param old_data [Hash{DataKind => Hash{String => Hash}}] Old data hash
340-
# @param new_data [Hash{DataKind => Hash{String => Hash}}] New data hash
339+
# @param old_data [Hash{DataKind => Hash{Symbol => Hash}}] Old data hash
340+
# @param new_data [Hash{DataKind => Hash{Symbol => Hash}}] New data hash
341341
# @return [Set<Hash>] Set of {kind:, key:} hashes
342342
#
343343
private def compute_changed_items_for_full_data_set(old_data, new_data)

lib/ldclient-rb/impl/dependency_tracker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def initialize(logger = nil)
1313
# Updates the dependency graph when an item has changed.
1414
#
1515
# @param from_kind [Object] the changed item's kind
16-
# @param from_key [String] the changed item's key
16+
# @param from_key [Symbol] the changed item's key
1717
# @param from_item [Object] the changed item (can be a Hash, model object, or nil)
1818
#
1919
def update_dependencies_from(from_kind, from_key, from_item)

lib/ldclient-rb/impl/flag_tracker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def add_flag_value_change_listener(key, context, listener)
2626
# An adapter which turns a normal flag change listener into a flag value change listener.
2727
#
2828
class FlagValueChangeAdapter
29-
# @param [Symbol] flag_key
29+
# @param [String] flag_key
3030
# @param [LaunchDarkly::LDContext] context
3131
# @param [#update] listener
3232
# @param [#call] eval_fn

lib/ldclient-rb/interfaces/flag_tracker.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def remove_listener(listener) end
6666
# The returned listener represents the subscription that was created by this method
6767
# call; to unsubscribe, pass that object (not your listener) to {#remove_listener}.
6868
#
69-
# @param key [Symbol]
69+
# @param key [String]
7070
# @param context [LaunchDarkly::LDContext]
7171
# @param listener [#update]
7272
#
@@ -79,7 +79,7 @@ def add_flag_value_change_listener(key, context, listener) end
7979
class FlagChange
8080
attr_accessor :key
8181

82-
# @param [Symbol] key
82+
# @param key [String]
8383
def initialize(key)
8484
@key = key
8585
end
@@ -93,9 +93,9 @@ class FlagValueChange
9393
attr_accessor :old_value
9494
attr_accessor :new_value
9595

96-
# @param [Symbol] key
97-
# @param [Object] old_value
98-
# @param [Object] new_value
96+
# @param key [String]
97+
# @param old_value [Object]
98+
# @param new_value [Object]
9999
def initialize(key, old_value, new_value)
100100
@key = key
101101
@old_value = old_value

spec/impl/data_system/fdv2_datasystem_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ def build(_sdk_key, _config)
6565
expect(modified.wait(1)).to be true
6666

6767
expect(changes.length).to eq(3)
68-
expect(changes[0].key).to eq(:flagkey)
69-
expect(changes[1].key).to eq(:flagkey)
70-
expect(changes[2].key).to eq(:flagkey)
68+
expect(changes[0].key).to eq("flagkey")
69+
expect(changes[1].key).to eq("flagkey")
70+
expect(changes[2].key).to eq("flagkey")
7171

7272
fdv2.stop
7373
end
@@ -166,8 +166,8 @@ def build(_sdk_key, _config)
166166
expect(changed.wait(2)).to be true
167167

168168
expect(changes.length).to eq(2)
169-
expect(changes[0].key).to eq(:flagkey)
170-
expect(changes[1].key).to eq(:flagkey)
169+
expect(changes[0].key).to eq("flagkey")
170+
expect(changes[1].key).to eq("flagkey")
171171

172172
fdv2.stop
173173
end
@@ -263,7 +263,7 @@ def build(_sdk_key, _config)
263263

264264
# Verify we got flag changes from FDv1
265265
expect(changes.length).to be > 0
266-
expect(changes.any? { |change| change.key == :fdv1flag }).to be true
266+
expect(changes.any? { |change| change.key == "fdv1flag" }).to be true
267267

268268
fdv2.stop
269269
end
@@ -318,7 +318,7 @@ def build(_sdk_key, _config)
318318

319319
# Verify FDv1 is active and we got both changes
320320
expect(changes.length).to eq(2)
321-
expect(changes.all? { |change| change.key == :fdv1fallbackflag }).to be true
321+
expect(changes.all? { |change| change.key == "fdv1fallbackflag" }).to be true
322322

323323
fdv2.stop
324324
end
@@ -369,8 +369,8 @@ def build(_sdk_key, _config)
369369

370370
# Verify we got changes for both flags
371371
flag_keys = changes.map { |change| change.key }
372-
expect(flag_keys).to include(:initialflag)
373-
expect(flag_keys).to include(:fdv1replacementflag)
372+
expect(flag_keys).to include("initialflag")
373+
expect(flag_keys).to include("fdv1replacementflag")
374374

375375
fdv2.stop
376376
end

spec/impl/data_system/fdv2_persistence_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def get_data_snapshot
147147
listener = Object.new
148148
listener.define_singleton_method(:update) do |flag_change|
149149
changes << flag_change
150-
flag_changed.set if flag_change.key == :newflag
150+
flag_changed.set if flag_change.key == "newflag"
151151
end
152152
fdv2.flag_change_broadcaster.add_listener(listener)
153153

@@ -326,7 +326,7 @@ def get_data_snapshot
326326
flag_changed = Concurrent::Event.new
327327
listener = Object.new
328328
listener.define_singleton_method(:update) do |flag_change|
329-
flag_changed.set if flag_change.key == :flagkey
329+
flag_changed.set if flag_change.key == "flagkey"
330330
end
331331

332332
fdv2.flag_change_broadcaster.add_listener(listener)
@@ -412,7 +412,7 @@ def get_data_snapshot
412412

413413
listener = Object.new
414414
listener.define_singleton_method(:update) do |flag_change|
415-
sync_flag_arrived.set if flag_change.key == :"sync-flag"
415+
sync_flag_arrived.set if flag_change.key == "sync-flag"
416416
end
417417

418418
fdv2.flag_change_broadcaster.add_listener(listener)

0 commit comments

Comments
 (0)