Skip to content

Commit fe3c9f7

Browse files
committed
adjust requires and implementations
1 parent fc751ab commit fe3c9f7

24 files changed

+130
-129
lines changed

lib/ldclient-rb.rb

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,14 @@
55
module LaunchDarkly
66
end
77

8-
require "ldclient-rb/version"
9-
require "ldclient-rb/interfaces"
10-
require "ldclient-rb/util"
11-
require "ldclient-rb/flags_state"
12-
require "ldclient-rb/migrations"
13-
require "ldclient-rb/ldclient"
14-
require "ldclient-rb/cache_store"
15-
require "ldclient-rb/expiring_cache"
16-
require "ldclient-rb/memoized_value"
17-
require "ldclient-rb/in_memory_store"
8+
# Public APIs - these define the main interfaces users interact with
189
require "ldclient-rb/config"
1910
require "ldclient-rb/context"
20-
require "ldclient-rb/reference"
21-
require "ldclient-rb/stream"
22-
require "ldclient-rb/polling"
23-
require "ldclient-rb/simple_lru_cache"
24-
require "ldclient-rb/non_blocking_thread_pool"
25-
require "ldclient-rb/events"
26-
require "ldclient-rb/requestor"
11+
require "ldclient-rb/flags_state"
2712
require "ldclient-rb/integrations"
13+
require "ldclient-rb/interfaces"
14+
require "ldclient-rb/ldclient"
15+
require "ldclient-rb/migrations"
16+
require "ldclient-rb/reference"
17+
require "ldclient-rb/util"
18+
require "ldclient-rb/version"

lib/ldclient-rb/config.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "logger"
2+
require "ldclient-rb/impl/cache_store"
23

34
module LaunchDarkly
45
#
@@ -477,7 +478,7 @@ def self.default_events_uri
477478
# @return [Object] the Rails cache if in Rails, or a simple in-memory implementation otherwise
478479
#
479480
def self.default_cache_store
480-
defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : ThreadSafeMemoryStore.new
481+
defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : Impl::ThreadSafeMemoryStore.new
481482
end
482483

483484
#

lib/ldclient-rb/events.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require "ldclient-rb/impl/event_sender"
44
require "ldclient-rb/impl/event_summarizer"
55
require "ldclient-rb/impl/event_types"
6+
require "ldclient-rb/impl/non_blocking_thread_pool"
7+
require "ldclient-rb/impl/simple_lru_cache"
68
require "ldclient-rb/impl/util"
79

810
require "concurrent"
@@ -141,7 +143,7 @@ def initialize(sdk_key, config, client = nil, diagnostic_accumulator = nil, test
141143
@inbox_full = Concurrent::AtomicBoolean.new(false)
142144

143145
event_sender = (test_properties || {})[:event_sender] ||
144-
Impl::EventSender.new(sdk_key, config, client || Util.new_http_client(config.events_uri, config))
146+
Impl::EventSender.new(sdk_key, config, client || Impl::Util.new_http_client(config.events_uri, config))
145147

146148
@timestamp_fn = (test_properties || {})[:timestamp_fn] || proc { Impl::Util.current_time_millis }
147149
@omit_anonymous_contexts = config.omit_anonymous_contexts
@@ -235,18 +237,18 @@ def initialize(inbox, sdk_key, config, diagnostic_accumulator, event_sender)
235237
@event_sender = event_sender
236238
@sampler = LaunchDarkly::Impl::Sampler.new(Random.new)
237239

238-
@context_keys = SimpleLRUCacheSet.new(config.context_keys_capacity)
240+
@context_keys = Impl::SimpleLRUCacheSet.new(config.context_keys_capacity)
239241
@formatter = EventOutputFormatter.new(config)
240242
@disabled = Concurrent::AtomicBoolean.new(false)
241243
@last_known_past_time = Concurrent::AtomicReference.new(0)
242244
@deduplicated_contexts = 0
243245
@events_in_last_batch = 0
244246

245247
outbox = EventBuffer.new(config.capacity, config.logger)
246-
flush_workers = NonBlockingThreadPool.new(MAX_FLUSH_WORKERS, 'LD/EventDispatcher/FlushWorkers')
248+
flush_workers = Impl::NonBlockingThreadPool.new(MAX_FLUSH_WORKERS, 'LD/EventDispatcher/FlushWorkers')
247249

248250
if !@diagnostic_accumulator.nil?
249-
diagnostic_event_workers = NonBlockingThreadPool.new(1, 'LD/EventDispatcher/DiagnosticEventWorkers')
251+
diagnostic_event_workers = Impl::NonBlockingThreadPool.new(1, 'LD/EventDispatcher/DiagnosticEventWorkers')
250252
init_event = @diagnostic_accumulator.create_init_event(config)
251253
send_diagnostic_event(init_event, diagnostic_event_workers)
252254
else
@@ -383,7 +385,7 @@ def trigger_flush(outbox, flush_workers)
383385
@last_known_past_time.value = (result.time_from_server.to_f * 1000).to_i
384386
end
385387
rescue => e
386-
Util.log_exception(@config.logger, "Unexpected error in event processor", e)
388+
Impl::Util.log_exception(@config.logger, "Unexpected error in event processor", e)
387389
end
388390
end
389391
outbox.clear if success # Reset our internal state, these events now belong to the flush worker

lib/ldclient-rb/impl/big_segments.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
require "ldclient-rb/config"
2-
require "ldclient-rb/expiring_cache"
2+
require "ldclient-rb/impl/expiring_cache"
33
require "ldclient-rb/impl/repeating_task"
4+
require "ldclient-rb/impl/util"
45
require "ldclient-rb/interfaces"
5-
require "ldclient-rb/util"
66

77
require "digest"
88

@@ -45,7 +45,7 @@ def get_context_membership(context_key)
4545
membership = EMPTY_MEMBERSHIP if membership.nil?
4646
@cache[context_key] = membership
4747
rescue => e
48-
LaunchDarkly::Util.log_exception(@logger, "Big Segment store membership query returned error", e)
48+
Impl::Util.log_exception(@logger, "Big Segment store membership query returned error", e)
4949
return BigSegmentMembershipResult.new(nil, BigSegmentsStatus::STORE_ERROR)
5050
end
5151
end
@@ -67,7 +67,7 @@ def poll_store_and_update_status
6767
metadata = @store.get_metadata
6868
new_status = Interfaces::BigSegmentStoreStatus.new(true, !metadata || stale?(metadata.last_up_to_date))
6969
rescue => e
70-
LaunchDarkly::Util.log_exception(@logger, "Big Segment store status query returned error", e)
70+
Impl::Util.log_exception(@logger, "Big Segment store status query returned error", e)
7171
end
7272
end
7373
@last_status = new_status

lib/ldclient-rb/impl/data_source/requestor.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "ldclient-rb/impl/model/serialization"
2+
require "ldclient-rb/impl/util"
23

34
require "concurrent/atomics"
45
require "json"
@@ -27,7 +28,7 @@ class Requestor
2728
def initialize(sdk_key, config)
2829
@sdk_key = sdk_key
2930
@config = config
30-
@http_client = LaunchDarkly::Util.new_http_client(config.base_uri, config)
31+
@http_client = Impl::Util.new_http_client(config.base_uri, config)
3132
.use(:auto_inflate)
3233
.headers("Accept-Encoding" => "gzip")
3334
@cache = @config.cache_store

lib/ldclient-rb/impl/data_store.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
module LaunchDarkly
55
module Impl
66
module DataStore
7-
87
class DataKind
98
FEATURES = "features".freeze
109
SEGMENTS = "segments".freeze

lib/ldclient-rb/impl/evaluator.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require "ldclient-rb/impl/evaluator_operators"
55
require "ldclient-rb/impl/model/feature_flag"
66
require "ldclient-rb/impl/model/segment"
7+
require "ldclient-rb/impl/util"
78

89
module LaunchDarkly
910
module Impl
@@ -152,11 +153,11 @@ def evaluate(flag, context)
152153
begin
153154
detail = eval_internal(flag, context, result, state)
154155
rescue EvaluationException => exn
155-
LaunchDarkly::Util.log_exception(@logger, "Unexpected error when evaluating flag #{flag.key}", exn)
156+
Impl::Util.log_exception(@logger, "Unexpected error when evaluating flag #{flag.key}", exn)
156157
result.detail = EvaluationDetail.new(nil, nil, EvaluationReason::error(exn.error_kind))
157158
return result, state
158159
rescue => exn
159-
LaunchDarkly::Util.log_exception(@logger, "Unexpected error when evaluating flag #{flag.key}", exn)
160+
Impl::Util.log_exception(@logger, "Unexpected error when evaluating flag #{flag.key}", exn)
160161
result.detail = EvaluationDetail.new(nil, nil, EvaluationReason::error(EvaluationReason::ERROR_EXCEPTION))
161162
return result, state
162163
end

lib/ldclient-rb/impl/event_sender.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "ldclient-rb/impl/unbounded_pool"
2+
require "ldclient-rb/impl/util"
23

34
require "securerandom"
45
require "http"
@@ -21,7 +22,7 @@ def initialize(sdk_key, config, http_client = nil, retry_interval = DEFAULT_RETR
2122
@logger = config.logger
2223
@retry_interval = retry_interval
2324
@http_client_pool = UnboundedPool.new(
24-
lambda { LaunchDarkly::Util.new_http_client(@config.events_uri, @config) },
25+
lambda { Impl::Util.new_http_client(@config.events_uri, @config) },
2526
lambda { |client| client.close })
2627
end
2728

@@ -81,9 +82,9 @@ def send_event_data(event_data, description, is_diagnostic)
8182
end
8283
return EventSenderResult.new(true, false, res_time)
8384
end
84-
must_shutdown = !LaunchDarkly::Util.http_error_recoverable?(status)
85+
must_shutdown = !Impl::Util.http_error_recoverable?(status)
8586
can_retry = !must_shutdown && attempt == 0
86-
message = LaunchDarkly::Util.http_error_message(status, "event delivery", can_retry ? "will retry" : "some events were dropped")
87+
message = Impl::Util.http_error_message(status, "event delivery", can_retry ? "will retry" : "some events were dropped")
8788
@logger.error { "[LDClient] #{message}" }
8889
if must_shutdown
8990
return EventSenderResult.new(false, true, nil)

lib/ldclient-rb/impl/integrations/file_data_source.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'ldclient-rb/in_memory_store'
2-
require 'ldclient-rb/util'
2+
require 'ldclient-rb/impl/util'
33

44
require 'concurrent/atomics'
55
require 'json'
@@ -82,7 +82,7 @@ def load_all
8282
begin
8383
load_file(path, all_data)
8484
rescue => exn
85-
LaunchDarkly::Util.log_exception(@logger, "Unable to load flag data from \"#{path}\"", exn)
85+
Impl::Util.log_exception(@logger, "Unable to load flag data from \"#{path}\"", exn)
8686
@data_source_update_sink&.update_status(
8787
LaunchDarkly::Interfaces::DataSource::Status::INTERRUPTED,
8888
LaunchDarkly::Interfaces::DataSource::ErrorInfo.new(LaunchDarkly::Interfaces::DataSource::ErrorInfo::INVALID_DATA, 0, exn.to_s, Time.now)
@@ -212,7 +212,7 @@ def initialize(resolved_paths, interval, reloader, logger)
212212
end
213213
reloader.call if changed
214214
rescue => exn
215-
LaunchDarkly::Util.log_exception(logger, "Unexpected exception in FileDataSourcePoller", exn)
215+
Impl::Util.log_exception(logger, "Unexpected exception in FileDataSourcePoller", exn)
216216
end
217217
end
218218
end

lib/ldclient-rb/impl/migrations/migrator.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'thread'
2+
require 'ldclient-rb/impl/util'
23

34
module LaunchDarkly
45
module Impl
@@ -274,7 +275,7 @@ def run()
274275
begin
275276
result = @fn.call(@payload)
276277
rescue => e
277-
LaunchDarkly::Util.log_exception(@logger, "Unexpected error running method for '#{origin}' origin", e)
278+
Impl::Util.log_exception(@logger, "Unexpected error running method for '#{origin}' origin", e)
278279
result = LaunchDarkly::Result.fail("'#{origin}' operation raised an exception", e)
279280
end
280281

0 commit comments

Comments
 (0)