Skip to content

Commit 0fc71a8

Browse files
authored
Merge pull request #88 from launchdarkly/eb/data-source
change name of "update processor" to "data source"
2 parents 216a1e8 + 414af99 commit 0fc71a8

File tree

6 files changed

+40
-42
lines changed

6 files changed

+40
-42
lines changed

lib/ldclient-rb/config.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ class Config
3434
# @option opts [Integer] :user_keys_capacity (1000) See {#user_keys_capacity}.
3535
# @option opts [Float] :user_keys_flush_interval (300) See {#user_keys_flush_interval}.
3636
# @option opts [Boolean] :inline_users_in_events (false) See {#inline_users_in_events}.
37-
# @option opts [Object] :update_processor See {#update_processor}.
38-
# @option opts [Object] :update_processor_factory See {#update_processor_factory}.
37+
# @option opts [Object] :data_source See {#data_source}.
38+
# @option opts [Object] :update_processor Obsolete synonym for `data_source`.
39+
# @option opts [Object] :update_processor_factory Obsolete synonym for `data_source`.
3940
#
4041
def initialize(opts = {})
4142
@base_uri = (opts[:base_uri] || Config.default_base_uri).chomp("/")
@@ -59,6 +60,7 @@ def initialize(opts = {})
5960
@user_keys_capacity = opts[:user_keys_capacity] || Config.default_user_keys_capacity
6061
@user_keys_flush_interval = opts[:user_keys_flush_interval] || Config.default_user_keys_flush_interval
6162
@inline_users_in_events = opts[:inline_users_in_events] || false
63+
@data_source = opts[:data_source] || opts[:update_processor] || opts[:update_processor_factory]
6264
@update_processor = opts[:update_processor]
6365
@update_processor_factory = opts[:update_processor_factory]
6466
end
@@ -245,22 +247,20 @@ def offline?
245247
# An object that is responsible for receiving feature flag data from LaunchDarkly. By default,
246248
# the client uses its standard polling or streaming implementation; this is customizable for
247249
# testing purposes.
248-
# @return [LaunchDarkly::Interfaces::UpdateProcessor]
249-
# @deprecated The preferred way to set this is now with {#update_processor_factory}.
250250
#
251-
attr_reader :update_processor
252-
253-
#
254-
# Factory for an object that is responsible for receiving feature flag data from LaunchDarkly
255-
# By default, the client uses its standard polling or streaming implementation; this is
256-
# customizable for testing purposes.
257-
#
258-
# The factory is a lambda or Proc that takes two parameters: the SDK key and the {Config}. It
259-
# must return an object that conforms to {LaunchDarkly::Interfaces::UpdateProcessor}.
251+
# This may be set to either an object that conforms to {LaunchDarkly::Interfaces::DataSource},
252+
# or a lambda (or Proc) that takes two parameters-- SDK key and {Config}-- and returns such an
253+
# object.
260254
#
261-
# @return [lambda]
255+
# @return [LaunchDarkly::Interfaces::DataSource|lambda]
262256
# @see FileDataSource
263257
#
258+
attr_reader :data_source
259+
260+
# @deprecated This is replaced by {#data_source}.
261+
attr_reader :update_processor
262+
263+
# @deprecated This is replaced by {#data_source}.
264264
attr_reader :update_processor_factory
265265

266266
#

lib/ldclient-rb/file_data_source.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ def self.have_listen?
2626
# actual LaunchDarkly connection.
2727
#
2828
# To use this component, call {FileDataSource#factory}, and store its return value in the
29-
# {Config#update_processor_factory} property of your LaunchDarkly client configuration. In the options
29+
# {Config#data_source} property of your LaunchDarkly client configuration. In the options
3030
# to `factory`, set `paths` to the file path(s) of your data file(s):
3131
#
32-
# factory = FileDataSource.factory(paths: [ myFilePath ])
33-
# config = LaunchDarkly::Config.new(update_processor_factory: factory)
32+
# file_source = FileDataSource.factory(paths: [ myFilePath ])
33+
# config = LaunchDarkly::Config.new(data_source: file_source)
3434
#
3535
# This will cause the client not to connect to LaunchDarkly to get feature flags. The
3636
# client may still make network connections to send analytics events, unless you have disabled
@@ -113,12 +113,10 @@ class FileDataSource
113113
# @option options [Float] :poll_interval The minimum interval, in seconds, between checks for
114114
# file modifications - used only if auto_update is true, and if the native file-watching
115115
# mechanism from 'listen' is not being used. The default value is 1 second.
116-
# @return an object that can be stored in {Config#update_processor_factory}
116+
# @return an object that can be stored in {Config#data_source}
117117
#
118118
def self.factory(options={})
119-
return Proc.new do |sdk_key, config|
120-
FileDataSourceImpl.new(config.feature_store, config.logger, options)
121-
end
119+
return lambda { |sdk_key, config| FileDataSourceImpl.new(config.feature_store, config.logger, options) }
122120
end
123121
end
124122

lib/ldclient-rb/interfaces.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,17 @@ def stop
108108
end
109109

110110
#
111-
# Mixin that defines the required methods of an update processor implementation. This is
112-
# the component that delivers feature flag data from LaunchDarkly to the LDClient by putting
111+
# Mixin that defines the required methods of a data source implementation. This is the
112+
# component that delivers feature flag data from LaunchDarkly to the LDClient by putting
113113
# the data in the {FeatureStore}. It is expected to run concurrently on its own thread.
114114
#
115115
# The client has its own standard implementation, which uses either a streaming connection or
116116
# polling depending on your configuration. Normally you will not need to use another one
117117
# except for testing purposes. {FileDataSource} provides one such test fixture.
118118
#
119-
module UpdateProcessor
119+
module DataSource
120120
#
121-
# Checks whether the processor has finished initializing. Initialization is considered done
121+
# Checks whether the data source has finished initializing. Initialization is considered done
122122
# once it has received one complete data set from LaunchDarkly.
123123
#
124124
# @return [Boolean] true if initialization is complete
@@ -127,7 +127,7 @@ def initialized?
127127
end
128128

129129
#
130-
# Puts the processor into an active state. Normally this means it will make its first
130+
# Puts the data source into an active state. Normally this means it will make its first
131131
# connection attempt to LaunchDarkly. If `start` has already been called, calling it again
132132
# should simply return the same value as the first call.
133133
#
@@ -137,7 +137,7 @@ def start
137137
end
138138

139139
#
140-
# Puts the processor into an inactive state and releases all of its resources.
140+
# Puts the data source into an inactive state and releases all of its resources.
141141
# This state should be considered permanent (`start` does not have to work after `stop`).
142142
#
143143
def stop

lib/ldclient-rb/ldclient.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ def initialize(sdk_key, config = Config.default, wait_for_sec = 5)
3737
return # requestor and update processor are not used in this mode
3838
end
3939

40-
if @config.update_processor
41-
@update_processor = @config.update_processor
40+
data_source_or_factory = @config.data_source || self.method(:create_default_data_source)
41+
if data_source_or_factory.respond_to? :call
42+
@data_source = data_source_or_factory.call(sdk_key, config)
4243
else
43-
factory = @config.update_processor_factory || self.method(:create_default_update_processor)
44-
@update_processor = factory.call(sdk_key, config)
44+
@data_source = data_source_or_factory
4545
end
4646

47-
ready = @update_processor.start
47+
ready = @data_source.start
4848
if wait_for_sec > 0
4949
ok = ready.wait(wait_for_sec)
5050
if !ok
5151
@config.logger.error { "[LDClient] Timeout encountered waiting for LaunchDarkly client initialization" }
52-
elsif !@update_processor.initialized?
52+
elsif !@data_source.initialized?
5353
@config.logger.error { "[LDClient] LaunchDarkly client initialization failed" }
5454
end
5555
end
@@ -97,7 +97,7 @@ def secure_mode_hash(user)
9797
# Returns whether the client has been initialized and is ready to serve feature flag requests
9898
# @return [Boolean] true if the client has been initialized
9999
def initialized?
100-
@config.offline? || @config.use_ldd? || @update_processor.initialized?
100+
@config.offline? || @config.use_ldd? || @data_source.initialized?
101101
end
102102

103103
#
@@ -270,14 +270,14 @@ def all_flags_state(user, options={})
270270
# @return [void]
271271
def close
272272
@config.logger.info { "[LDClient] Closing LaunchDarkly client..." }
273-
@update_processor.stop
273+
@data_source.stop
274274
@event_processor.stop
275275
@store.stop
276276
end
277277

278278
private
279279

280-
def create_default_update_processor(sdk_key, config)
280+
def create_default_data_source(sdk_key, config)
281281
if config.offline?
282282
return NullUpdateProcessor.new
283283
end

spec/file_data_source_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def test_auto_reload(options)
219219
it "evaluates simplified flag with client as expected" do
220220
file = make_temp_file(all_properties_json)
221221
factory = LaunchDarkly::FileDataSource.factory({ paths: file.path })
222-
config = LaunchDarkly::Config.new(send_events: false, update_processor_factory: factory)
222+
config = LaunchDarkly::Config.new(send_events: false, data_source: factory)
223223
client = LaunchDarkly::LDClient.new('sdkKey', config)
224224

225225
begin
@@ -233,7 +233,7 @@ def test_auto_reload(options)
233233
it "evaluates full flag with client as expected" do
234234
file = make_temp_file(all_properties_json)
235235
factory = LaunchDarkly::FileDataSource.factory({ paths: file.path })
236-
config = LaunchDarkly::Config.new(send_events: false, update_processor_factory: factory)
236+
config = LaunchDarkly::Config.new(send_events: false, data_source: factory)
237237
client = LaunchDarkly::LDClient.new('sdkKey', config)
238238

239239
begin

spec/ldclient_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
let(:offline_client) do
88
subject.new("secret", offline_config)
99
end
10-
let(:update_processor) { LaunchDarkly::NullUpdateProcessor.new }
11-
let(:config) { LaunchDarkly::Config.new({send_events: false, update_processor: update_processor}) }
10+
let(:null_data) { LaunchDarkly::NullUpdateProcessor.new }
11+
let(:config) { LaunchDarkly::Config.new({send_events: false, data_source: null_data}) }
1212
let(:client) do
1313
subject.new("secret", config)
1414
end
@@ -357,7 +357,7 @@ def event_processor
357357
end
358358

359359
describe 'with send_events: false' do
360-
let(:config) { LaunchDarkly::Config.new({offline: true, send_events: false, update_processor: update_processor}) }
360+
let(:config) { LaunchDarkly::Config.new({offline: true, send_events: false, data_source: null_data}) }
361361
let(:client) { subject.new("secret", config) }
362362

363363
it "uses a NullEventProcessor" do
@@ -367,7 +367,7 @@ def event_processor
367367
end
368368

369369
describe 'with send_events: true' do
370-
let(:config_with_events) { LaunchDarkly::Config.new({offline: false, send_events: true, update_processor: update_processor}) }
370+
let(:config_with_events) { LaunchDarkly::Config.new({offline: false, send_events: true, data_source: null_data}) }
371371
let(:client_with_events) { subject.new("secret", config_with_events) }
372372

373373
it "does not use a NullEventProcessor" do

0 commit comments

Comments
 (0)