splitclient-rb 6.4.1.pre.rc3-java → 7.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.txt +15 -1
- data/Detailed-README.md +9 -21
- data/NEWS +3 -0
- data/lib/splitclient-rb.rb +2 -1
- data/lib/splitclient-rb/cache/adapters/cache_adapter.rb +3 -3
- data/lib/splitclient-rb/cache/repositories/events/memory_repository.rb +5 -4
- data/lib/splitclient-rb/cache/repositories/events/redis_repository.rb +4 -3
- data/lib/splitclient-rb/cache/repositories/events_repository.rb +10 -9
- data/lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb +7 -6
- data/lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb +5 -4
- data/lib/splitclient-rb/cache/repositories/impressions_repository.rb +9 -8
- data/lib/splitclient-rb/cache/repositories/metrics/memory_repository.rb +3 -2
- data/lib/splitclient-rb/cache/repositories/metrics/redis_repository.rb +5 -4
- data/lib/splitclient-rb/cache/repositories/metrics_repository.rb +6 -4
- data/lib/splitclient-rb/cache/repositories/repository.rb +7 -2
- data/lib/splitclient-rb/cache/repositories/segments_repository.rb +6 -5
- data/lib/splitclient-rb/cache/repositories/splits_repository.rb +56 -14
- data/lib/splitclient-rb/cache/routers/impression_router.rb +5 -4
- data/lib/splitclient-rb/cache/senders/events_sender.rb +7 -6
- data/lib/splitclient-rb/cache/senders/impressions_sender.rb +10 -9
- data/lib/splitclient-rb/cache/senders/metrics_sender.rb +9 -8
- data/lib/splitclient-rb/cache/stores/sdk_blocker.rb +19 -10
- data/lib/splitclient-rb/cache/stores/segment_store.rb +15 -28
- data/lib/splitclient-rb/cache/stores/split_store.rb +13 -15
- data/lib/splitclient-rb/clients/localhost_split_client.rb +8 -7
- data/lib/splitclient-rb/clients/split_client.rb +65 -35
- data/lib/splitclient-rb/engine/api/client.rb +17 -13
- data/lib/splitclient-rb/engine/api/events.rb +7 -6
- data/lib/splitclient-rb/engine/api/impressions.rb +6 -5
- data/lib/splitclient-rb/engine/api/metrics.rb +8 -7
- data/lib/splitclient-rb/engine/api/segments.rb +11 -10
- data/lib/splitclient-rb/engine/api/splits.rb +6 -5
- data/lib/splitclient-rb/engine/matchers/all_keys_matcher.rb +1 -1
- data/lib/splitclient-rb/engine/matchers/between_matcher.rb +7 -5
- data/lib/splitclient-rb/engine/matchers/combining_matcher.rb +5 -4
- data/lib/splitclient-rb/engine/matchers/contains_all_matcher.rb +4 -4
- data/lib/splitclient-rb/engine/matchers/contains_any_matcher.rb +3 -3
- data/lib/splitclient-rb/engine/matchers/contains_matcher.rb +7 -5
- data/lib/splitclient-rb/engine/matchers/dependency_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/ends_with_matcher.rb +5 -4
- data/lib/splitclient-rb/engine/matchers/equal_to_boolean_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/equal_to_matcher.rb +6 -4
- data/lib/splitclient-rb/engine/matchers/equal_to_set_matcher.rb +3 -3
- data/lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_matcher.rb +6 -4
- data/lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb +6 -4
- data/lib/splitclient-rb/engine/matchers/matcher.rb +4 -0
- data/lib/splitclient-rb/engine/matchers/matches_string_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/negation_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/part_of_set_matcher.rb +4 -4
- data/lib/splitclient-rb/engine/matchers/set_matcher.rb +2 -1
- data/lib/splitclient-rb/engine/matchers/starts_with_matcher.rb +4 -3
- data/lib/splitclient-rb/engine/matchers/user_defined_segment_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/whitelist_matcher.rb +7 -5
- data/lib/splitclient-rb/engine/models/label.rb +2 -0
- data/lib/splitclient-rb/engine/parser/condition.rb +31 -20
- data/lib/splitclient-rb/engine/parser/evaluator.rb +3 -2
- data/lib/splitclient-rb/engine/parser/split_adapter.rb +9 -7
- data/lib/splitclient-rb/localhost_split_factory.rb +3 -2
- data/lib/splitclient-rb/managers/split_manager.rb +39 -5
- data/lib/splitclient-rb/redis_metrics_fixer.rb +5 -4
- data/lib/splitclient-rb/split_config.rb +35 -14
- data/lib/splitclient-rb/split_factory.rb +44 -32
- data/lib/splitclient-rb/split_factory_builder.rb +4 -5
- data/lib/splitclient-rb/split_factory_registry.rb +51 -0
- data/lib/splitclient-rb/split_logger.rb +5 -14
- data/lib/splitclient-rb/validators.rb +19 -16
- data/lib/splitclient-rb/version.rb +1 -1
- metadata +5 -4
@@ -6,10 +6,12 @@ module SplitIoClient
|
|
6
6
|
# @param api_key [String] the API key for your split account
|
7
7
|
#
|
8
8
|
# @return [SplitIoManager] split.io client instance
|
9
|
-
def initialize(api_key, adapter = nil, splits_repository = nil)
|
9
|
+
def initialize(api_key, adapter = nil, splits_repository = nil, sdk_blocker, config)
|
10
10
|
@localhost_mode_features = []
|
11
11
|
@splits_repository = splits_repository
|
12
12
|
@adapter = adapter
|
13
|
+
@sdk_blocker = sdk_blocker
|
14
|
+
@config = config
|
13
15
|
end
|
14
16
|
|
15
17
|
#
|
@@ -17,7 +19,12 @@ module SplitIoClient
|
|
17
19
|
#
|
18
20
|
# @returns [object] array of splits
|
19
21
|
def splits
|
20
|
-
return [] if
|
22
|
+
return [] if !@config.valid_mode || @splits_repository.nil?
|
23
|
+
|
24
|
+
if !ready?
|
25
|
+
@config.logger.error("splits: the SDK is not ready, the operation cannot be executed")
|
26
|
+
return []
|
27
|
+
end
|
21
28
|
|
22
29
|
@splits_repository.splits.each_with_object([]) do |(name, split), memo|
|
23
30
|
split_view = build_split_view(name, split)
|
@@ -33,7 +40,12 @@ module SplitIoClient
|
|
33
40
|
#
|
34
41
|
# @returns [object] array of split names (String)
|
35
42
|
def split_names
|
36
|
-
return [] if
|
43
|
+
return [] if !@config.valid_mode || @splits_repository.nil?
|
44
|
+
|
45
|
+
if !ready?
|
46
|
+
@config.logger.error("split_names: the SDK is not ready, the operation cannot be executed")
|
47
|
+
return []
|
48
|
+
end
|
37
49
|
|
38
50
|
@splits_repository.split_names
|
39
51
|
end
|
@@ -43,22 +55,38 @@ module SplitIoClient
|
|
43
55
|
#
|
44
56
|
# @returns a split view
|
45
57
|
def split(split_name)
|
46
|
-
return unless
|
58
|
+
return unless @config.valid_mode && @splits_repository && @config.split_validator.valid_split_parameters(split_name)
|
59
|
+
|
60
|
+
if !ready?
|
61
|
+
@config.logger.error("split: the SDK is not ready, the operation cannot be executed")
|
62
|
+
return
|
63
|
+
end
|
47
64
|
|
48
65
|
sanitized_split_name= split_name.to_s.strip
|
49
66
|
|
50
67
|
if split_name.to_s != sanitized_split_name
|
51
|
-
|
68
|
+
@config.logger.warn("split: split_name #{split_name} has extra whitespace, trimming")
|
52
69
|
split_name = sanitized_split_name
|
53
70
|
end
|
54
71
|
|
55
72
|
split = @splits_repository.get_split(split_name)
|
56
73
|
|
74
|
+
if ready? && split.nil?
|
75
|
+
@config.logger.warn("split: you passed #{split_name} " \
|
76
|
+
'that does not exist in this environment, please double check what Splits exist in the web console')
|
77
|
+
end
|
78
|
+
|
57
79
|
return if split.nil? || Engine::Models::Split.archived?(split)
|
58
80
|
|
59
81
|
build_split_view(split_name, split)
|
60
82
|
end
|
61
83
|
|
84
|
+
def block_until_ready(time = nil)
|
85
|
+
@sdk_blocker.block(time) if @sdk_blocker && !@sdk_blocker.ready?
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
62
90
|
def build_split_view(name, split)
|
63
91
|
return {} unless split
|
64
92
|
|
@@ -79,5 +107,11 @@ module SplitIoClient
|
|
79
107
|
configs: split[:configurations] || {}
|
80
108
|
}
|
81
109
|
end
|
110
|
+
|
111
|
+
# move to blocker, alongside block until ready to avoid duplication
|
112
|
+
def ready?
|
113
|
+
return @sdk_blocker.ready? if @sdk_blocker
|
114
|
+
true
|
115
|
+
end
|
82
116
|
end
|
83
117
|
end
|
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
module SplitIoClient
|
4
4
|
class RedisMetricsFixer
|
5
|
-
def initialize(metrics_repository)
|
5
|
+
def initialize(metrics_repository, config)
|
6
6
|
@metrics_repository = metrics_repository
|
7
|
+
@config = config
|
7
8
|
end
|
8
9
|
|
9
10
|
def call
|
10
|
-
return if ENV['SPLITCLIENT_ENV'] == 'test' ||
|
11
|
+
return if ENV['SPLITCLIENT_ENV'] == 'test' || @config.mode == :standalone
|
11
12
|
|
12
13
|
fixer_thread
|
13
14
|
|
@@ -23,11 +24,11 @@ module SplitIoClient
|
|
23
24
|
def fixer_thread
|
24
25
|
Thread.new do
|
25
26
|
begin
|
26
|
-
|
27
|
+
@config.logger.info('Starting redis metrics fixer')
|
27
28
|
|
28
29
|
@metrics_repository.fix_latencies
|
29
30
|
rescue StandardError => error
|
30
|
-
|
31
|
+
@config.log_found_exception(__method__.to_s, error)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -2,15 +2,6 @@ require 'logger'
|
|
2
2
|
require 'socket'
|
3
3
|
|
4
4
|
module SplitIoClient
|
5
|
-
|
6
|
-
class << self
|
7
|
-
attr_accessor :configuration
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.configure(opts={})
|
11
|
-
self.configuration ||= SplitConfig.new(opts)
|
12
|
-
end
|
13
|
-
|
14
5
|
#
|
15
6
|
# This class manages configuration options for the split client library.
|
16
7
|
# If not custom configuration is required the default configuration values will be used
|
@@ -68,9 +59,7 @@ module SplitIoClient
|
|
68
59
|
@logger = opts[:logger] || SplitConfig.default_logger
|
69
60
|
@debug_enabled = opts[:debug_enabled] || SplitConfig.default_debug
|
70
61
|
@transport_debug_enabled = opts[:transport_debug_enabled] || SplitConfig.default_debug
|
71
|
-
@block_until_ready =
|
72
|
-
|
73
|
-
@logger.warn 'no ready parameter has been set - incorrect control treatments could be logged' if block_until_ready == 0 && !mode.equal?(:consumer)
|
62
|
+
@block_until_ready = SplitConfig.default_block_until_ready
|
74
63
|
|
75
64
|
@machine_name = opts[:machine_name] || SplitConfig.machine_hostname
|
76
65
|
@machine_ip = opts[:machine_ip] || SplitConfig.machine_ip
|
@@ -96,7 +85,8 @@ module SplitIoClient
|
|
96
85
|
opts[:cache_adapter] || SplitConfig.default_cache_adapter, :queue_adapter, @events_queue_size, @redis_url
|
97
86
|
)
|
98
87
|
@valid_mode = true
|
99
|
-
|
88
|
+
@split_logger = SplitIoClient::SplitLogger.new(self)
|
89
|
+
@split_validator = SplitIoClient::Validators.new(self)
|
100
90
|
startup_log
|
101
91
|
end
|
102
92
|
|
@@ -160,6 +150,21 @@ module SplitIoClient
|
|
160
150
|
# @return [Logger] The configured logger
|
161
151
|
attr_accessor :logger
|
162
152
|
|
153
|
+
#
|
154
|
+
# The split logger. The client library uses the split logger
|
155
|
+
# to use common functions around the logger
|
156
|
+
#
|
157
|
+
# @return [SplitLogger] The configured logger
|
158
|
+
attr_accessor :split_logger
|
159
|
+
|
160
|
+
|
161
|
+
#
|
162
|
+
# The split validator. The client library uses the split validator
|
163
|
+
# to validate inputs accross the sdk
|
164
|
+
#
|
165
|
+
# @return [SplitValidator] The validator
|
166
|
+
attr_accessor :split_validator
|
167
|
+
|
163
168
|
#
|
164
169
|
# The boolean that represents the state of the debug log level
|
165
170
|
#
|
@@ -343,7 +348,7 @@ module SplitIoClient
|
|
343
348
|
if defined?(Rails) && Rails.logger
|
344
349
|
Rails.logger
|
345
350
|
elsif ENV['SPLITCLIENT_ENV'] == 'test'
|
346
|
-
Logger.new('/dev/null')
|
351
|
+
Logger.new('/dev/null')
|
347
352
|
else
|
348
353
|
Logger.new($stdout)
|
349
354
|
end
|
@@ -375,6 +380,14 @@ module SplitIoClient
|
|
375
380
|
'SPLITIO'
|
376
381
|
end
|
377
382
|
|
383
|
+
#
|
384
|
+
# The default block until ready value
|
385
|
+
#
|
386
|
+
# @return [int]
|
387
|
+
def self.default_block_until_ready
|
388
|
+
15
|
389
|
+
end
|
390
|
+
|
378
391
|
#
|
379
392
|
# The default transport_debug_enabled value
|
380
393
|
#
|
@@ -429,6 +442,14 @@ module SplitIoClient
|
|
429
442
|
@logger.info("Loaded cache class: #{@cache_adapter.class}")
|
430
443
|
end
|
431
444
|
|
445
|
+
def standalone?
|
446
|
+
@mode.equal?(:standalone)
|
447
|
+
end
|
448
|
+
|
449
|
+
def consumer?
|
450
|
+
@mode.equal?(:consumer)
|
451
|
+
end
|
452
|
+
|
432
453
|
#
|
433
454
|
# gets the hostname where the sdk gem is running
|
434
455
|
#
|
@@ -1,82 +1,94 @@
|
|
1
1
|
module SplitIoClient
|
2
2
|
class SplitFactory
|
3
3
|
ROOT_PROCESS_ID = Process.pid
|
4
|
+
SINGLETON_WARN = 'We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing it throughout your application'
|
4
5
|
include SplitIoClient::Cache::Repositories
|
5
6
|
include SplitIoClient::Cache::Stores
|
6
7
|
|
7
|
-
attr_reader :adapter, :client, :manager
|
8
|
+
attr_reader :adapter, :client, :manager, :config
|
8
9
|
|
9
10
|
def initialize(api_key, config_hash = {})
|
10
11
|
at_exit do
|
11
12
|
unless ENV['SPLITCLIENT_ENV'] == 'test'
|
12
13
|
if (Process.pid == ROOT_PROCESS_ID)
|
13
|
-
|
14
|
+
@config.logger.info('Split SDK shutdown started...')
|
14
15
|
@client.destroy if @client
|
15
16
|
stop!
|
16
|
-
|
17
|
+
@config.logger.info('Split SDK shutdown complete')
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
@api_key = api_key
|
22
|
-
|
23
|
+
@config = SplitConfig.new (config_hash)
|
23
24
|
|
24
25
|
raise 'Invalid SDK mode' unless valid_mode
|
26
|
+
|
27
|
+
@splits_repository = SplitsRepository.new(@config)
|
28
|
+
@segments_repository = SegmentsRepository.new(@config)
|
29
|
+
@impressions_repository = ImpressionsRepository.new(@config)
|
30
|
+
@metrics_repository = MetricsRepository.new(@config)
|
31
|
+
@events_repository = EventsRepository.new(@config, @api_key)
|
25
32
|
|
26
|
-
@
|
27
|
-
|
28
|
-
@splits_repository = SplitsRepository.new(@cache_adapter)
|
29
|
-
@segments_repository = SegmentsRepository.new(@cache_adapter)
|
30
|
-
@impressions_repository = ImpressionsRepository.new(SplitIoClient.configuration.impressions_adapter)
|
31
|
-
@metrics_repository = MetricsRepository.new(SplitIoClient.configuration.metrics_adapter)
|
32
|
-
@events_repository = EventsRepository.new(SplitIoClient.configuration.events_adapter, @api_key)
|
33
|
-
|
34
|
-
if SplitIoClient.configuration.mode == :standalone && SplitIoClient.configuration.block_until_ready > 0
|
35
|
-
@sdk_blocker = SDKBlocker.new(@splits_repository, @segments_repository)
|
36
|
-
end
|
33
|
+
@sdk_blocker = SDKBlocker.new(@splits_repository, @segments_repository, @config)
|
37
34
|
|
38
35
|
@adapter = start!
|
39
36
|
|
40
|
-
@client = SplitClient.new(@api_key, @adapter, @splits_repository, @segments_repository, @impressions_repository, @metrics_repository, @events_repository)
|
41
|
-
@manager = SplitManager.new(@api_key, @adapter, @splits_repository)
|
37
|
+
@client = SplitClient.new(@api_key, @adapter, @splits_repository, @segments_repository, @impressions_repository, @metrics_repository, @events_repository, @sdk_blocker, @config)
|
38
|
+
@manager = SplitManager.new(@api_key, @adapter, @splits_repository, @sdk_blocker, @config)
|
42
39
|
|
43
40
|
validate_api_key
|
44
41
|
|
45
|
-
RedisMetricsFixer.new(@metrics_repository).call
|
42
|
+
RedisMetricsFixer.new(@metrics_repository, @config).call
|
46
43
|
|
47
|
-
|
44
|
+
register_factory
|
48
45
|
end
|
49
46
|
|
50
47
|
def start!
|
51
|
-
SplitAdapter.new(@api_key, @splits_repository, @segments_repository, @impressions_repository, @metrics_repository, @events_repository, @sdk_blocker)
|
48
|
+
SplitAdapter.new(@api_key, @splits_repository, @segments_repository, @impressions_repository, @metrics_repository, @events_repository, @sdk_blocker, @config)
|
52
49
|
end
|
53
50
|
|
54
51
|
def stop!
|
55
|
-
|
52
|
+
@config.threads.each { |_, t| t.exit }
|
53
|
+
end
|
54
|
+
|
55
|
+
def register_factory
|
56
|
+
SplitIoClient.load_factory_registry
|
57
|
+
|
58
|
+
number_of_factories = SplitIoClient.split_factory_registry.number_of_factories_for(@api_key)
|
59
|
+
|
60
|
+
if(number_of_factories > 0)
|
61
|
+
@config.logger.warn("Factory instantiation: You already have #{number_of_factories} factories with this API Key. #{SINGLETON_WARN}")
|
62
|
+
elsif(SplitIoClient.split_factory_registry.other_factories)
|
63
|
+
@config.logger.warn('Factory instantiation: You already have an instance of the Split factory.' \
|
64
|
+
" Make sure you definitely want this additional instance. #{SINGLETON_WARN}")
|
65
|
+
end
|
66
|
+
|
67
|
+
SplitIoClient.split_factory_registry.add(@api_key)
|
56
68
|
end
|
57
69
|
|
58
70
|
def valid_mode
|
59
71
|
valid_startup_mode = false
|
60
|
-
case
|
72
|
+
case @config.mode
|
61
73
|
when :consumer
|
62
|
-
if
|
74
|
+
if @config.cache_adapter.is_a? SplitIoClient::Cache::Adapters::RedisAdapter
|
63
75
|
valid_startup_mode = true
|
64
76
|
else
|
65
|
-
|
77
|
+
@config.logger.error('Consumer mode cannot be used with Memory adapter. ' \
|
66
78
|
'Use Redis adapter instead.')
|
67
79
|
end
|
68
80
|
when :standalone
|
69
|
-
if
|
81
|
+
if @config.cache_adapter.is_a? SplitIoClient::Cache::Adapters::MemoryAdapter
|
70
82
|
valid_startup_mode = true
|
71
83
|
else
|
72
|
-
|
84
|
+
@config.logger.error('Standalone mode cannot be used with Redis adapter. ' \
|
73
85
|
'Use Memory adapter instead.')
|
74
86
|
end
|
75
87
|
when :producer
|
76
|
-
|
88
|
+
@config.logger.error('Producer mode is no longer supported. Use Split Synchronizer. ' \
|
77
89
|
'See: https://github.com/splitio/split-synchronizer')
|
78
90
|
else
|
79
|
-
|
91
|
+
@config.logger.error('Invalid SDK mode selected. ' \
|
80
92
|
"Valid modes are 'standalone with memory adapter' and 'consumer with redis adapter'")
|
81
93
|
end
|
82
94
|
|
@@ -89,11 +101,11 @@ module SplitIoClient
|
|
89
101
|
|
90
102
|
def validate_api_key
|
91
103
|
if(@api_key.nil?)
|
92
|
-
|
93
|
-
|
104
|
+
@config.logger.error('Factory Instantiation: you passed a nil api_key, api_key must be a non-empty String')
|
105
|
+
@config.valid_mode = false
|
94
106
|
elsif (@api_key.empty?)
|
95
|
-
|
96
|
-
|
107
|
+
@config.logger.error('Factory Instantiation: you passed and empty api_key, api_key must be a non-empty String')
|
108
|
+
@config.valid_mode = false
|
97
109
|
end
|
98
110
|
end
|
99
111
|
end
|
@@ -5,9 +5,8 @@ module SplitIoClient
|
|
5
5
|
def self.build(api_key, config = {})
|
6
6
|
case api_key
|
7
7
|
when 'localhost'
|
8
|
-
|
9
|
-
|
10
|
-
LocalhostSplitFactory.new(split_file(config[:split_file]), config[:reload_rate])
|
8
|
+
configuration = SplitConfig.new(config)
|
9
|
+
LocalhostSplitFactory.new(split_file(config[:split_file], configuration.logger), configuration, config[:reload_rate])
|
11
10
|
else
|
12
11
|
SplitFactory.new(api_key, config)
|
13
12
|
end
|
@@ -15,10 +14,10 @@ module SplitIoClient
|
|
15
14
|
|
16
15
|
private
|
17
16
|
|
18
|
-
def self.split_file(split_file_path)
|
17
|
+
def self.split_file(split_file_path, logger)
|
19
18
|
return split_file_path unless split_file_path.nil?
|
20
19
|
|
21
|
-
|
20
|
+
logger.warn('Localhost mode: .split mocks ' \
|
22
21
|
'will be deprecated soon in favor of YAML files, which provide more ' \
|
23
22
|
'targeting power. Take a look in our documentation.')
|
24
23
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
module SplitIoClient
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_accessor :split_factory_registry
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.load_factory_registry
|
11
|
+
self.split_factory_registry ||= SplitFactoryRegistry.new
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# This class manages configuration options for the split client library.
|
16
|
+
# If not custom configuration is required the default configuration values will be used
|
17
|
+
#
|
18
|
+
class SplitFactoryRegistry
|
19
|
+
|
20
|
+
attr_accessor :api_keys_hash
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@api_keys_hash = Hash.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def add(api_key)
|
27
|
+
return unless api_key
|
28
|
+
|
29
|
+
@api_keys_hash[api_key] = 0 unless @api_keys_hash[api_key]
|
30
|
+
@api_keys_hash[api_key] += 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def remove(api_key)
|
34
|
+
return unless api_key
|
35
|
+
|
36
|
+
@api_keys_hash[api_key] -= 1 if @api_keys_hash[api_key]
|
37
|
+
@api_keys_hash.delete(api_key) if @api_keys_hash[api_key] == 0
|
38
|
+
end
|
39
|
+
|
40
|
+
def number_of_factories_for(api_key)
|
41
|
+
return 0 unless api_key
|
42
|
+
return 0 unless @api_keys_hash.key?(api_key)
|
43
|
+
|
44
|
+
@api_keys_hash[api_key]
|
45
|
+
end
|
46
|
+
|
47
|
+
def other_factories
|
48
|
+
return !@api_keys_hash.empty?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,24 +1,15 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
1
|
module SplitIoClient
|
4
2
|
class SplitLogger
|
5
|
-
|
3
|
+
def initialize(config)
|
4
|
+
@config = config
|
5
|
+
end
|
6
6
|
|
7
7
|
def log_if_debug(message)
|
8
|
-
|
8
|
+
@config.logger.debug(message) if @config.debug_enabled
|
9
9
|
end
|
10
10
|
|
11
11
|
def log_if_transport(message)
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def log_error(message)
|
16
|
-
SplitIoClient.configuration.logger.error(message)
|
17
|
-
end
|
18
|
-
|
19
|
-
class << self
|
20
|
-
extend Forwardable
|
21
|
-
def_delegators :instance, *SplitLogger.instance_methods(false)
|
12
|
+
@config.logger.debug(message) if @config.transport_debug_enabled
|
22
13
|
end
|
23
14
|
end
|
24
15
|
end
|