splitclient-rb 6.4.1 → 7.0.0.pre.rc1

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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/Detailed-README.md +9 -21
  3. data/lib/splitclient-rb/cache/adapters/cache_adapter.rb +3 -3
  4. data/lib/splitclient-rb/cache/repositories/events/memory_repository.rb +5 -4
  5. data/lib/splitclient-rb/cache/repositories/events/redis_repository.rb +4 -3
  6. data/lib/splitclient-rb/cache/repositories/events_repository.rb +10 -9
  7. data/lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb +7 -6
  8. data/lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb +5 -4
  9. data/lib/splitclient-rb/cache/repositories/impressions_repository.rb +9 -8
  10. data/lib/splitclient-rb/cache/repositories/metrics/memory_repository.rb +3 -2
  11. data/lib/splitclient-rb/cache/repositories/metrics/redis_repository.rb +5 -4
  12. data/lib/splitclient-rb/cache/repositories/metrics_repository.rb +6 -4
  13. data/lib/splitclient-rb/cache/repositories/repository.rb +7 -2
  14. data/lib/splitclient-rb/cache/repositories/segments_repository.rb +6 -5
  15. data/lib/splitclient-rb/cache/repositories/splits_repository.rb +54 -7
  16. data/lib/splitclient-rb/cache/routers/impression_router.rb +5 -4
  17. data/lib/splitclient-rb/cache/senders/events_sender.rb +7 -6
  18. data/lib/splitclient-rb/cache/senders/impressions_sender.rb +10 -9
  19. data/lib/splitclient-rb/cache/senders/metrics_sender.rb +9 -8
  20. data/lib/splitclient-rb/cache/stores/sdk_blocker.rb +19 -10
  21. data/lib/splitclient-rb/cache/stores/segment_store.rb +15 -28
  22. data/lib/splitclient-rb/cache/stores/split_store.rb +13 -15
  23. data/lib/splitclient-rb/clients/localhost_split_client.rb +8 -7
  24. data/lib/splitclient-rb/clients/split_client.rb +65 -35
  25. data/lib/splitclient-rb/engine/api/client.rb +17 -13
  26. data/lib/splitclient-rb/engine/api/events.rb +7 -6
  27. data/lib/splitclient-rb/engine/api/impressions.rb +6 -5
  28. data/lib/splitclient-rb/engine/api/metrics.rb +8 -7
  29. data/lib/splitclient-rb/engine/api/segments.rb +11 -10
  30. data/lib/splitclient-rb/engine/api/splits.rb +6 -5
  31. data/lib/splitclient-rb/engine/matchers/all_keys_matcher.rb +1 -1
  32. data/lib/splitclient-rb/engine/matchers/between_matcher.rb +7 -5
  33. data/lib/splitclient-rb/engine/matchers/combining_matcher.rb +5 -4
  34. data/lib/splitclient-rb/engine/matchers/contains_all_matcher.rb +4 -4
  35. data/lib/splitclient-rb/engine/matchers/contains_any_matcher.rb +3 -3
  36. data/lib/splitclient-rb/engine/matchers/contains_matcher.rb +7 -5
  37. data/lib/splitclient-rb/engine/matchers/dependency_matcher.rb +3 -2
  38. data/lib/splitclient-rb/engine/matchers/ends_with_matcher.rb +5 -4
  39. data/lib/splitclient-rb/engine/matchers/equal_to_boolean_matcher.rb +3 -2
  40. data/lib/splitclient-rb/engine/matchers/equal_to_matcher.rb +6 -4
  41. data/lib/splitclient-rb/engine/matchers/equal_to_set_matcher.rb +3 -3
  42. data/lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_matcher.rb +6 -4
  43. data/lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb +6 -4
  44. data/lib/splitclient-rb/engine/matchers/matcher.rb +4 -0
  45. data/lib/splitclient-rb/engine/matchers/matches_string_matcher.rb +3 -2
  46. data/lib/splitclient-rb/engine/matchers/negation_matcher.rb +3 -2
  47. data/lib/splitclient-rb/engine/matchers/part_of_set_matcher.rb +4 -4
  48. data/lib/splitclient-rb/engine/matchers/set_matcher.rb +2 -1
  49. data/lib/splitclient-rb/engine/matchers/starts_with_matcher.rb +4 -3
  50. data/lib/splitclient-rb/engine/matchers/user_defined_segment_matcher.rb +3 -2
  51. data/lib/splitclient-rb/engine/matchers/whitelist_matcher.rb +7 -5
  52. data/lib/splitclient-rb/engine/models/label.rb +2 -0
  53. data/lib/splitclient-rb/engine/parser/condition.rb +31 -20
  54. data/lib/splitclient-rb/engine/parser/evaluator.rb +3 -2
  55. data/lib/splitclient-rb/engine/parser/split_adapter.rb +9 -7
  56. data/lib/splitclient-rb/localhost_split_factory.rb +3 -2
  57. data/lib/splitclient-rb/managers/split_manager.rb +39 -5
  58. data/lib/splitclient-rb/redis_metrics_fixer.rb +5 -4
  59. data/lib/splitclient-rb/split_config.rb +35 -14
  60. data/lib/splitclient-rb/split_factory.rb +44 -32
  61. data/lib/splitclient-rb/split_factory_builder.rb +4 -5
  62. data/lib/splitclient-rb/split_factory_registry.rb +51 -0
  63. data/lib/splitclient-rb/split_logger.rb +5 -14
  64. data/lib/splitclient-rb/validators.rb +19 -16
  65. data/lib/splitclient-rb/version.rb +1 -1
  66. data/lib/splitclient-rb.rb +2 -1
  67. metadata +5 -4
@@ -3,19 +3,20 @@
3
3
  module SplitIoClient
4
4
  module Api
5
5
  class Events < Client
6
- def initialize(api_key)
6
+ def initialize(api_key, config)
7
+ super(config)
7
8
  @api_key = api_key
8
9
  end
9
10
 
10
11
  def post(events)
11
12
  if events.empty?
12
- SplitLogger.log_if_debug('No events to report')
13
+ @config.split_logger.log_if_debug('No events to report')
13
14
  return
14
15
  end
15
16
 
16
- events.each_slice(SplitIoClient.configuration.events_queue_size) do |events_slice|
17
+ events.each_slice(@config.events_queue_size) do |events_slice|
17
18
  response = post_api(
18
- "#{SplitIoClient.configuration.events_uri}/events/bulk",
19
+ "#{@config.events_uri}/events/bulk",
19
20
  @api_key,
20
21
  events_slice.map { |event| formatted_event(event[:e]) },
21
22
  'SplitSDKMachineIP' => events_slice[0][:m][:i],
@@ -24,9 +25,9 @@ module SplitIoClient
24
25
  )
25
26
 
26
27
  if response.success?
27
- SplitLogger.log_if_debug("Events reported: #{events_slice.size}")
28
+ @config.split_logger.log_if_debug("Events reported: #{events_slice.size}")
28
29
  else
29
- SplitLogger.log_error("Unexpected status code while posting events: #{response.status}." \
30
+ @config.logger.error("Unexpected status code while posting events: #{response.status}." \
30
31
  ' - Check your API key and base URI')
31
32
  raise 'Split SDK failed to connect to backend to post events'
32
33
  end
@@ -3,23 +3,24 @@
3
3
  module SplitIoClient
4
4
  module Api
5
5
  class Impressions < Client
6
- def initialize(api_key)
6
+ def initialize(api_key, config)
7
7
  @api_key = api_key
8
+ @config = config
8
9
  end
9
10
 
10
11
  def post(impressions)
11
12
  if impressions.empty?
12
- SplitLogger.log_if_debug('No impressions to report')
13
+ @config.split_logger.log_if_debug('No impressions to report')
13
14
  return
14
15
  end
15
16
 
16
17
  impressions_by_ip(impressions).each do |ip, impressions_ip|
17
- response = post_api("#{SplitIoClient.configuration.events_uri}/testImpressions/bulk", @api_key, impressions_ip, 'SplitSDKMachineIP' => ip)
18
+ response = post_api("#{@config.events_uri}/testImpressions/bulk", @api_key, impressions_ip, 'SplitSDKMachineIP' => ip)
18
19
 
19
20
  if response.success?
20
- SplitLogger.log_if_debug("Impressions reported: #{total_impressions(impressions)}")
21
+ @config.split_logger.log_if_debug("Impressions reported: #{total_impressions(impressions)}")
21
22
  else
22
- SplitLogger.log_error("Unexpected status code while posting impressions: #{response.status}." \
23
+ @config.logger.error("Unexpected status code while posting impressions: #{response.status}." \
23
24
  ' - Check your API key and base URI')
24
25
  raise 'Split SDK failed to connect to backend to post impressions'
25
26
  end
@@ -3,7 +3,8 @@
3
3
  module SplitIoClient
4
4
  module Api
5
5
  class Metrics < Client
6
- def initialize(api_key, metrics_repository)
6
+ def initialize(api_key, metrics_repository, config)
7
+ super(config)
7
8
  @api_key = api_key
8
9
  @metrics_repository = metrics_repository
9
10
  end
@@ -17,12 +18,12 @@ module SplitIoClient
17
18
 
18
19
  def post_latencies
19
20
  if @metrics_repository.latencies.empty?
20
- SplitLogger.log_if_debug('No latencies to report.')
21
+ @config.split_logger.log_if_debug('No latencies to report.')
21
22
  else
22
23
  @metrics_repository.latencies.each do |name, latencies|
23
24
  metrics_time = { name: name, latencies: latencies }
24
25
 
25
- response = post_api("#{SplitIoClient.configuration.events_uri}/metrics/time", @api_key, metrics_time)
26
+ response = post_api("#{@config.events_uri}/metrics/time", @api_key, metrics_time)
26
27
 
27
28
  log_status(response, metrics_time.size)
28
29
  end
@@ -33,12 +34,12 @@ module SplitIoClient
33
34
 
34
35
  def post_counts
35
36
  if @metrics_repository.counts.empty?
36
- SplitLogger.log_if_debug('No counts to report.')
37
+ @config.split_logger.log_if_debug('No counts to report.')
37
38
  else
38
39
  @metrics_repository.counts.each do |name, count|
39
40
  metrics_count = { name: name, delta: count }
40
41
 
41
- response = post_api("#{SplitIoClient.configuration.events_uri}/metrics/counter", @api_key, metrics_count)
42
+ response = post_api("#{@config.events_uri}/metrics/counter", @api_key, metrics_count)
42
43
 
43
44
  log_status(response, metrics_count.size)
44
45
  end
@@ -48,9 +49,9 @@ module SplitIoClient
48
49
 
49
50
  def log_status(response, info_to_log)
50
51
  if response.success?
51
- SplitLogger.log_if_debug("Metric time reported: #{info_to_log}")
52
+ @config.split_logger.log_if_debug("Metric time reported: #{info_to_log}")
52
53
  else
53
- SplitLogger.log_error("Unexpected status code while posting time metrics: #{response.status}" \
54
+ @config.logger.error("Unexpected status code while posting time metrics: #{response.status}" \
54
55
  ' - Check your API key and base URI')
55
56
  raise 'Split SDK failed to connect to backend to post metrics'
56
57
  end
@@ -6,7 +6,8 @@ module SplitIoClient
6
6
  class Segments < Client
7
7
  METRICS_PREFIX = 'segmentChangeFetcher'
8
8
 
9
- def initialize(api_key, metrics, segments_repository)
9
+ def initialize(api_key, metrics, segments_repository, config)
10
+ super(config)
10
11
  @metrics = metrics
11
12
  @api_key = api_key
12
13
  @segments_repository = segments_repository
@@ -23,7 +24,7 @@ module SplitIoClient
23
24
  segment = fetch_segment_changes(name, since)
24
25
  @segments_repository.add_to_segment(segment)
25
26
 
26
- SplitLogger.log_if_debug("Segment #{name} fetched before: #{since}, \
27
+ @config.split_logger.log_if_debug("Segment #{name} fetched before: #{since}, \
27
28
  till: #{@segments_repository.get_change_number(name)}")
28
29
 
29
30
  break if since.to_i >= @segments_repository.get_change_number(name).to_i
@@ -39,28 +40,28 @@ module SplitIoClient
39
40
  private
40
41
 
41
42
  def fetch_segment_changes(name, since)
42
- response = get_api("#{SplitIoClient.configuration.base_uri}/segmentChanges/#{name}", @api_key, since: since)
43
+ response = get_api("#{@config.base_uri}/segmentChanges/#{name}", @api_key, since: since)
43
44
  if response.success?
44
45
  segment = JSON.parse(response.body, symbolize_names: true)
45
46
  @segments_repository.set_change_number(name, segment[:till])
46
47
  @metrics.count(METRICS_PREFIX + '.status.' + response.status.to_s, 1)
47
48
 
48
- SplitLogger.log_if_debug("\'#{segment[:name]}\' segment retrieved.")
49
+ @config.split_logger.log_if_debug("\'#{segment[:name]}\' segment retrieved.")
49
50
  unless segment[:added].empty?
50
- SplitLogger.log_if_debug("\'#{segment[:name]}\' #{segment[:added].size} added keys")
51
+ @config.split_logger.log_if_debug("\'#{segment[:name]}\' #{segment[:added].size} added keys")
51
52
  end
52
53
  unless segment[:removed].empty?
53
- SplitLogger.log_if_debug("\'#{segment[:name]}\' #{segment[:removed].size} removed keys")
54
+ @config.split_logger.log_if_debug("\'#{segment[:name]}\' #{segment[:removed].size} removed keys")
54
55
  end
55
- SplitLogger.log_if_transport(segment.to_s)
56
+ @config.split_logger.log_if_transport(segment.to_s)
56
57
 
57
58
  segment
58
59
  elsif response.status == 403
59
- SplitIoClient.configuration.logger.error('Factory Instantiation: You passed a browser type api_key, ' \
60
+ @config.logger.error('Factory Instantiation: You passed a browser type api_key, ' \
60
61
  'please grab an api key from the Split console that is of type sdk')
61
- SplitIoClient.configuration.valid_mode = false
62
+ @config.valid_mode = false
62
63
  else
63
- SplitLogger.log_error("Unexpected status code while fetching segments: #{response.status}." \
64
+ @config.logger.error("Unexpected status code while fetching segments: #{response.status}." \
64
65
  "Since #{since} - Check your API key and base URI")
65
66
  @metrics.count(METRICS_PREFIX + '.status.' + response.status.to_s, 1)
66
67
  raise 'Split SDK failed to connect to backend to fetch segments'
@@ -6,7 +6,8 @@ module SplitIoClient
6
6
  class Splits < Client
7
7
  METRICS_PREFIX = 'splitChangeFetcher'
8
8
 
9
- def initialize(api_key, metrics)
9
+ def initialize(api_key, metrics, config)
10
+ super(config)
10
11
  @api_key = api_key
11
12
  @metrics = metrics
12
13
  end
@@ -14,16 +15,16 @@ module SplitIoClient
14
15
  def since(since)
15
16
  start = Time.now
16
17
 
17
- response = get_api("#{SplitIoClient.configuration.base_uri}/splitChanges", @api_key, since: since)
18
+ response = get_api("#{@config.base_uri}/splitChanges", @api_key, since: since)
18
19
 
19
20
  if response.success?
20
21
  result = splits_with_segment_names(response.body)
21
22
 
22
23
  @metrics.count(METRICS_PREFIX + '.status.' + response.status.to_s, 1)
23
24
  unless result[:splits].empty?
24
- SplitLogger.log_if_debug("#{result[:splits].length} splits retrieved. since=#{since}")
25
+ @config.split_logger.log_if_debug("#{result[:splits].length} splits retrieved. since=#{since}")
25
26
  end
26
- SplitLogger.log_if_transport(result.to_s)
27
+ @config.split_logger.log_if_transport(result.to_s)
27
28
 
28
29
  latency = (Time.now - start) * 1000.0
29
30
  @metrics.time(METRICS_PREFIX + '.time', latency)
@@ -31,7 +32,7 @@ module SplitIoClient
31
32
  result
32
33
  else
33
34
  @metrics.count(METRICS_PREFIX + '.status.' + response.status.to_s, 1)
34
- SplitLogger.log_error("Unexpected status code while fetching splits: #{response.status}. " \
35
+ @config.logger.error("Unexpected status code while fetching splits: #{response.status}. " \
35
36
  'Check your API key and base URI')
36
37
  raise 'Split SDK failed to connect to backend to fetch split definitions'
37
38
  end
@@ -12,7 +12,7 @@ module SplitIoClient
12
12
  #
13
13
  # @return [boolean] true for all instances
14
14
  def match?(_args)
15
- SplitLogger.log_if_debug('[AllKeysMatcher] is always -> true')
15
+ @logger.log_if_debug('[AllKeysMatcher] is always -> true')
16
16
  true
17
17
  end
18
18
 
@@ -6,7 +6,9 @@ module SplitIoClient
6
6
 
7
7
  attr_reader :attribute
8
8
 
9
- def initialize(attribute_hash)
9
+ def initialize(attribute_hash, logger, validator)
10
+ super(logger)
11
+ @validator = validator
10
12
  @attribute = attribute_hash[:attribute]
11
13
  @data_type = attribute_hash[:data_type]
12
14
  @start_value = formatted_value(attribute_hash[:start_value], true)
@@ -14,16 +16,16 @@ module SplitIoClient
14
16
  end
15
17
 
16
18
  def match?(args)
17
- SplitLogger.log_if_debug('[BetweenMatcher] evaluating value and attributes.')
19
+ @logger.log_if_debug('[BetweenMatcher] evaluating value and attributes.')
18
20
 
19
- return false unless SplitIoClient::Validators.valid_matcher_arguments(args)
21
+ return false unless @validator.valid_matcher_arguments(args)
20
22
 
21
23
  value = formatted_value(args[:value] || args[:attributes][@attribute.to_sym])
22
- SplitLogger.log_if_debug("[BetweenMatcher] Value from parameters: #{value}.")
24
+ @logger.log_if_debug("[BetweenMatcher] Value from parameters: #{value}.")
23
25
  return false unless value.is_a?(Integer)
24
26
 
25
27
  matches = (@start_value..@end_value).cover? value
26
- SplitLogger.log_if_debug("[BetweenMatcher] is #{value} between #{@start_value} and #{@end_value} -> #{matches} .")
28
+ @logger.log_if_debug("[BetweenMatcher] is #{value} between #{@start_value} and #{@end_value} -> #{matches} .")
27
29
  matches
28
30
  end
29
31
 
@@ -7,7 +7,8 @@ module SplitIoClient
7
7
  class CombiningMatcher < Matcher
8
8
  MATCHER_TYPE = 'COMBINING_MATCHER'
9
9
 
10
- def initialize(combiner = '', matchers = [])
10
+ def initialize(logger, combiner = '', matchers = [])
11
+ super(logger)
11
12
  @combiner = combiner
12
13
  @matchers = matchers
13
14
  end
@@ -23,17 +24,17 @@ module SplitIoClient
23
24
  # @return [boolean]
24
25
  def match?(args)
25
26
  if @matchers.empty?
26
- SplitLogger.log_if_debug('[CombiningMatcher] Matchers Empty')
27
+ @logger.log_if_debug('[CombiningMatcher] Matchers Empty')
27
28
  return false
28
29
  end
29
30
 
30
31
  case @combiner
31
32
  when Combiners::AND
32
33
  matches = eval_and(args)
33
- SplitLogger.log_if_debug("[CombiningMatcher] Combiner AND result -> #{matches}")
34
+ @logger.log_if_debug("[CombiningMatcher] Combiner AND result -> #{matches}")
34
35
  return matches
35
36
  else
36
- SplitLogger.log_if_debug("[CombiningMatcher] Invalid Combiner Type - Combiner -> #{@combiner}")
37
+ @logger.log_if_debug("[CombiningMatcher] Invalid Combiner Type - Combiner -> #{@combiner}")
37
38
  @logger.error('Invalid combiner type')
38
39
  end
39
40
 
@@ -6,18 +6,18 @@ module SplitIoClient
6
6
 
7
7
  attr_reader :attribute
8
8
 
9
- def initialize(attribute, remote_array)
10
- super(attribute, remote_array)
9
+ def initialize(attribute, remote_array, logger)
10
+ super(attribute, remote_array, logger)
11
11
  end
12
12
 
13
13
  def match?(args)
14
14
  if @remote_set.empty?
15
- SplitLogger.log_if_debug('[ContainsAllMatcher] Remote Set Empty')
15
+ @logger.log_if_debug('[ContainsAllMatcher] Remote Set Empty')
16
16
  return false
17
17
  end
18
18
 
19
19
  matches = @remote_set.subset? local_set(args[:attributes], @attribute)
20
- SplitLogger.log_if_debug("[ContainsAllMatcher] Remote Set #{@remote_set} contains #{@attribute} -> #{matches}")
20
+ @logger.log_if_debug("[ContainsAllMatcher] Remote Set #{@remote_set} contains #{@attribute} -> #{matches}")
21
21
  matches
22
22
  end
23
23
  end
@@ -6,13 +6,13 @@ module SplitIoClient
6
6
 
7
7
  attr_reader :attribute
8
8
 
9
- def initialize(attribute, remote_array)
10
- super(attribute, remote_array)
9
+ def initialize(attribute, remote_array, logger)
10
+ super(attribute, remote_array, logger)
11
11
  end
12
12
 
13
13
  def match?(args)
14
14
  matches = local_set(args[:attributes], @attribute).intersect? @remote_set
15
- SplitLogger.log_if_debug("[ContainsAnyMatcher] Remote Set #{@remote_set} contains any \
15
+ @logger.log_if_debug("[ContainsAnyMatcher] Remote Set #{@remote_set} contains any \
16
16
  #{@attribute} or #{args[:attributes]}-> #{matches}")
17
17
  matches
18
18
  end
@@ -6,23 +6,25 @@ module SplitIoClient
6
6
 
7
7
  attr_reader :attribute
8
8
 
9
- def initialize(attribute, substr_list)
9
+ def initialize(attribute, substr_list, logger, validator)
10
10
  @attribute = attribute
11
11
  @substr_list = substr_list
12
+ @logger = logger
13
+ @validator = validator
12
14
  end
13
15
 
14
16
  def match?(args)
15
- SplitLogger.log_if_debug('[ContainsMatcher] evaluating value and attributes.')
17
+ @logger.log_if_debug('[ContainsMatcher] evaluating value and attributes.')
16
18
 
17
- return false unless SplitIoClient::Validators.valid_matcher_arguments(args)
19
+ return false unless @validator.valid_matcher_arguments(args)
18
20
 
19
21
  value = get_value(args)
20
22
 
21
- SplitLogger.log_if_debug("[ContainsMatcher] Value from parameters: #{value}.")
23
+ @logger.log_if_debug("[ContainsMatcher] Value from parameters: #{value}.")
22
24
  return false if @substr_list.empty?
23
25
 
24
26
  matches = @substr_list.any? { |substr| value.to_s.include? substr }
25
- SplitLogger.log_if_debug("[ContainsMatcher] #{@value} contains any of #{@substr_list} -> #{matches} .")
27
+ @logger.log_if_debug("[ContainsMatcher] #{@value} contains any of #{@substr_list} -> #{matches} .")
26
28
  matches
27
29
  end
28
30
 
@@ -4,16 +4,17 @@ module SplitIoClient
4
4
  class DependencyMatcher
5
5
  MATCHER_TYPE = 'IN_SPLIT_TREATMENT'
6
6
 
7
- def initialize(split, treatments)
7
+ def initialize(split, treatments, logger)
8
8
  @split = split
9
9
  @treatments = treatments
10
+ @logger = logger
10
11
  end
11
12
 
12
13
  def match?(args)
13
14
  keys = { matching_key: args[:matching_key], bucketing_key: args[:bucketing_key] }
14
15
  evaluate = args[:evaluator].call(keys, @split, args[:attributes])
15
16
  matches = @treatments.include?(evaluate[:treatment])
16
- SplitLogger.log_if_debug("[dependencyMatcher] Parent split #{@split} evaluated to #{evaluate[:treatment]} \
17
+ @logger.log_if_debug("[dependencyMatcher] Parent split #{@split} evaluated to #{evaluate[:treatment]} \
17
18
  with label #{evaluate[:label]}. #{@split} evaluated treatment is part of [#{@treatments}] ? #{matches}.")
18
19
  matches
19
20
  end
@@ -6,23 +6,24 @@ module SplitIoClient
6
6
 
7
7
  attr_reader :attribute
8
8
 
9
- def initialize(attribute, suffix_list)
9
+ def initialize(attribute, suffix_list, logger)
10
10
  @attribute = attribute
11
11
  @suffix_list = suffix_list
12
+ @logger = logger
12
13
  end
13
14
 
14
15
  def match?(args)
15
16
  value = get_value(args)
16
17
 
17
- SplitLogger.log_if_debug("[EndsWithMatcher] Value from parameters: #{value}.")
18
+ @logger.log_if_debug("[EndsWithMatcher] Value from parameters: #{value}.")
18
19
 
19
20
  if @suffix_list.empty?
20
- SplitLogger.log_if_debug('[EndsWithMatcher] Sufix List empty.')
21
+ @logger.log_if_debug('[EndsWithMatcher] Sufix List empty.')
21
22
  return false
22
23
  end
23
24
 
24
25
  matches = @suffix_list.any? { |suffix| value.to_s.end_with? suffix }
25
- SplitLogger.log_if_debug("[EndsWithMatcher] #{value} ends with any #{@suffix_list}")
26
+ @logger.log_if_debug("[EndsWithMatcher] #{value} ends with any #{@suffix_list}")
26
27
  matches
27
28
  end
28
29
 
@@ -6,9 +6,10 @@ module SplitIoClient
6
6
 
7
7
  attr_reader :attribute
8
8
 
9
- def initialize(attribute, boolean)
9
+ def initialize(attribute, boolean, logger)
10
10
  @attribute = attribute
11
11
  @boolean = boolean
12
+ @logger = logger
12
13
  end
13
14
 
14
15
  def match?(args)
@@ -17,7 +18,7 @@ module SplitIoClient
17
18
  value = true if value.to_s.casecmp('true').zero?
18
19
 
19
20
  matches = value == @boolean
20
- SplitLogger.log_if_debug("[EqualToBooleanMatcher] #{value} equals to #{@boolean} -> #{matches}")
21
+ @logger.log_if_debug("[EqualToBooleanMatcher] #{value} equals to #{@boolean} -> #{matches}")
21
22
  matches
22
23
  end
23
24
 
@@ -6,21 +6,23 @@ module SplitIoClient
6
6
 
7
7
  attr_reader :attribute
8
8
 
9
- def initialize(attribute_hash)
9
+ def initialize(attribute_hash, logger, validator)
10
+ super(logger)
11
+ @validator = validator
10
12
  @attribute = attribute_hash[:attribute]
11
13
  @data_type = attribute_hash[:data_type]
12
14
  @value = formatted_value(attribute_hash[:value], true)
13
15
  end
14
16
 
15
17
  def match?(args)
16
- SplitLogger.log_if_debug('[EqualsToMatcher] evaluating value and attributes.')
18
+ @logger.log_if_debug('[EqualsToMatcher] evaluating value and attributes.')
17
19
 
18
- return false unless SplitIoClient::Validators.valid_matcher_arguments(args)
20
+ return false unless @validator.valid_matcher_arguments(args)
19
21
 
20
22
  value = formatted_value(args[:value] || args[:attributes][@attribute.to_sym])
21
23
 
22
24
  matches = value.is_a?(Integer) ? (value == @value) : false
23
- SplitLogger.log_if_debug("[EqualsToMatcher] #{value} equals to #{@value} -> #{matches}")
25
+ @logger.log_if_debug("[EqualsToMatcher] #{value} equals to #{@value} -> #{matches}")
24
26
  matches
25
27
  end
26
28
 
@@ -6,14 +6,14 @@ module SplitIoClient
6
6
 
7
7
  attr_reader :attribute
8
8
 
9
- def initialize(attribute, remote_array)
10
- super(attribute, remote_array)
9
+ def initialize(attribute, remote_array, logger)
10
+ super(attribute, remote_array, logger)
11
11
  end
12
12
 
13
13
  def match?(args)
14
14
  set = local_set(args[:attributes], @attribute)
15
15
  matches = set == @remote_set
16
- SplitLogger.log_if_debug("[EqualsToSetMatcher] #{set} equals to #{@remote_set} -> #{matches}")
16
+ @logger.log_if_debug("[EqualsToSetMatcher] #{set} equals to #{@remote_set} -> #{matches}")
17
17
  matches
18
18
  end
19
19
  end
@@ -6,21 +6,23 @@ module SplitIoClient
6
6
 
7
7
  attr_reader :attribute
8
8
 
9
- def initialize(attribute_hash)
9
+ def initialize(attribute_hash, logger, validator)
10
+ super(logger)
11
+ @validator = validator
10
12
  @attribute = attribute_hash[:attribute]
11
13
  @data_type = attribute_hash[:data_type]
12
14
  @value = formatted_value(attribute_hash[:value], true)
13
15
  end
14
16
 
15
17
  def match?(args)
16
- SplitLogger.log_if_debug('[GreaterThanOrEqualToMatcher] evaluating value and attributes.')
18
+ @logger.log_if_debug('[GreaterThanOrEqualToMatcher] evaluating value and attributes.')
17
19
 
18
- return false unless SplitIoClient::Validators.valid_matcher_arguments(args)
20
+ return false unless @validator.valid_matcher_arguments(args)
19
21
 
20
22
  value = formatted_value(args[:value] || args[:attributes][@attribute.to_sym])
21
23
 
22
24
  matches = value.is_a?(Integer) ? (value >= @value) : false
23
- SplitLogger.log_if_debug("[GreaterThanOrEqualToMatcher] #{value} greater than or equal to #{@value} -> #{matches}")
25
+ @logger.log_if_debug("[GreaterThanOrEqualToMatcher] #{value} greater than or equal to #{@value} -> #{matches}")
24
26
  matches
25
27
  end
26
28
 
@@ -6,21 +6,23 @@ module SplitIoClient
6
6
 
7
7
  attr_reader :attribute
8
8
 
9
- def initialize(attribute_hash)
9
+ def initialize(attribute_hash, logger, validator)
10
+ super(logger)
11
+ @validator = validator
10
12
  @attribute = attribute_hash[:attribute]
11
13
  @data_type = attribute_hash[:data_type]
12
14
  @value = formatted_value(attribute_hash[:value], true)
13
15
  end
14
16
 
15
17
  def match?(args)
16
- SplitLogger.log_if_debug('[LessThanOrEqualToMatcher] evaluating value and attributes.')
18
+ @logger.log_if_debug('[LessThanOrEqualToMatcher] evaluating value and attributes.')
17
19
 
18
- return false unless SplitIoClient::Validators.valid_matcher_arguments(args)
20
+ return false unless @validator.valid_matcher_arguments(args)
19
21
 
20
22
  value = formatted_value(args[:value] || args[:attributes][@attribute.to_sym])
21
23
 
22
24
  matches = value.is_a?(Integer) ? (value <= @value) : false
23
- SplitLogger.log_if_debug("[LessThanOrEqualToMatcher] #{value} less than or equal to #{@value} -> #{matches}")
25
+ @logger.log_if_debug("[LessThanOrEqualToMatcher] #{value} less than or equal to #{@value} -> #{matches}")
24
26
  matches
25
27
  end
26
28
 
@@ -5,6 +5,10 @@ module SplitIoClient
5
5
  # class to implement the all keys matcher
6
6
  #
7
7
  class Matcher
8
+ def initialize(logger)
9
+ @logger = logger
10
+ end
11
+
8
12
  #
9
13
  # evaluates if the given object equals the matcher
10
14
  #
@@ -6,9 +6,10 @@ module SplitIoClient
6
6
 
7
7
  attr_reader :attribute
8
8
 
9
- def initialize(attribute, regexp_string)
9
+ def initialize(attribute, regexp_string, logger)
10
10
  @attribute = attribute
11
11
  @regexp_string = @regexp_string.is_a?(Regexp) ? regexp_string : Regexp.new(regexp_string)
12
+ @logger = logger
12
13
  end
13
14
 
14
15
  def match?(args)
@@ -17,7 +18,7 @@ module SplitIoClient
17
18
  end
18
19
 
19
20
  matches = !(value =~ @regexp_string).nil?
20
- SplitLogger.log_if_debug("[MatchesStringMatcher] #{value} matches #{@regexp_string} -> #{matches}")
21
+ @logger.log_if_debug("[MatchesStringMatcher] #{value} matches #{@regexp_string} -> #{matches}")
21
22
  matches
22
23
  end
23
24
 
@@ -7,7 +7,8 @@ module SplitIoClient
7
7
  class NegationMatcher < Matcher
8
8
  MATCHER_TYPE = 'NEGATION_MATCHER'
9
9
 
10
- def initialize(matcher = nil)
10
+ def initialize(logger, matcher = nil)
11
+ super(logger)
11
12
  @matcher = matcher
12
13
  end
13
14
 
@@ -19,7 +20,7 @@ module SplitIoClient
19
20
  # @return [boolean] evaluation of the negation matcher
20
21
  def match?(args)
21
22
  matches = !@matcher.match?(args)
22
- SplitLogger.log_if_debug("[NegationMatcherMatcher] Matcher #{@matcher} Arguments #{args} -> #{matches}")
23
+ @logger.log_if_debug("[NegationMatcherMatcher] Matcher #{@matcher} Arguments #{args} -> #{matches}")
23
24
  matches
24
25
  end
25
26
 
@@ -6,20 +6,20 @@ module SplitIoClient
6
6
 
7
7
  attr_reader :attribute
8
8
 
9
- def initialize(attribute, remote_array)
10
- super(attribute, remote_array)
9
+ def initialize(attribute, remote_array, logger)
10
+ super(attribute, remote_array, logger)
11
11
  end
12
12
 
13
13
  def match?(args)
14
14
  @local_set = local_set(args[:attributes], @attribute)
15
15
 
16
16
  if @local_set.empty?
17
- SplitLogger.log_if_debug('[PartOfSetMatcher] Local Set is empty.')
17
+ @logger.log_if_debug('[PartOfSetMatcher] Local Set is empty.')
18
18
  return false
19
19
  end
20
20
 
21
21
  matches = @local_set.subset? @remote_set
22
- SplitLogger.log_if_debug("[PartOfSetMatcher] Local Set #{@local_set} is a subset of #{@remote_set} -> #{matches}")
22
+ @logger.log_if_debug("[PartOfSetMatcher] Local Set #{@local_set} is a subset of #{@remote_set} -> #{matches}")
23
23
  matches
24
24
  end
25
25
  end
@@ -10,9 +10,10 @@ module SplitIoClient
10
10
 
11
11
  protected
12
12
 
13
- def initialize(attribute, remote_array)
13
+ def initialize(attribute, remote_array, logger)
14
14
  @attribute = attribute
15
15
  @remote_set = remote_array.to_set
16
+ @logger = logger
16
17
  end
17
18
 
18
19
  def local_set(data, attribute)