splitclient-rb 6.0.1 → 6.1.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -1
  3. data/.simplecov +1 -0
  4. data/README.md +2 -2
  5. data/lib/splitclient-rb.rb +1 -0
  6. data/lib/splitclient-rb/clients/split_client.rb +30 -9
  7. data/lib/splitclient-rb/engine/api/client.rb +8 -9
  8. data/lib/splitclient-rb/engine/api/events.rb +4 -2
  9. data/lib/splitclient-rb/engine/api/faraday_middleware/gzip.rb +10 -8
  10. data/lib/splitclient-rb/engine/api/impressions.rb +4 -2
  11. data/lib/splitclient-rb/engine/api/metrics.rb +5 -5
  12. data/lib/splitclient-rb/engine/api/segments.rb +5 -1
  13. data/lib/splitclient-rb/engine/api/splits.rb +4 -4
  14. data/lib/splitclient-rb/engine/matchers/all_keys_matcher.rb +8 -13
  15. data/lib/splitclient-rb/engine/matchers/between_matcher.rb +12 -23
  16. data/lib/splitclient-rb/engine/matchers/combiners.rb +3 -1
  17. data/lib/splitclient-rb/engine/matchers/combining_matcher.rb +16 -24
  18. data/lib/splitclient-rb/engine/matchers/contains_all_matcher.rb +10 -7
  19. data/lib/splitclient-rb/engine/matchers/contains_any_matcher.rb +7 -6
  20. data/lib/splitclient-rb/engine/matchers/contains_matcher.rb +19 -8
  21. data/lib/splitclient-rb/engine/matchers/dependency_matcher.rb +8 -3
  22. data/lib/splitclient-rb/engine/matchers/ends_with_matcher.rb +21 -6
  23. data/lib/splitclient-rb/engine/matchers/equal_to_boolean_matcher.rb +17 -8
  24. data/lib/splitclient-rb/engine/matchers/equal_to_matcher.rb +11 -23
  25. data/lib/splitclient-rb/engine/matchers/equal_to_set_matcher.rb +7 -6
  26. data/lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_matcher.rb +13 -25
  27. data/lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb +13 -25
  28. data/lib/splitclient-rb/engine/matchers/matcher.rb +30 -0
  29. data/lib/splitclient-rb/engine/matchers/matches_string_matcher.rb +6 -2
  30. data/lib/splitclient-rb/engine/matchers/negation_matcher.rb +8 -22
  31. data/lib/splitclient-rb/engine/matchers/part_of_set_matcher.rb +10 -7
  32. data/lib/splitclient-rb/engine/matchers/set_matcher.rb +7 -1
  33. data/lib/splitclient-rb/engine/matchers/starts_with_matcher.rb +18 -5
  34. data/lib/splitclient-rb/engine/matchers/user_defined_segment_matcher.rb +7 -25
  35. data/lib/splitclient-rb/engine/matchers/whitelist_matcher.rb +33 -35
  36. data/lib/splitclient-rb/managers/split_manager.rb +10 -3
  37. data/lib/splitclient-rb/split_config.rb +34 -9
  38. data/lib/splitclient-rb/split_factory.rb +27 -0
  39. data/lib/splitclient-rb/validators.rb +104 -36
  40. data/lib/splitclient-rb/version.rb +1 -1
  41. metadata +6 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0aab1aa3e329b992c7861e5bbedec99b1cb88cac36beaef4066d26a5b507c273
4
- data.tar.gz: eb5cc6e1c13c306b6c836ed9c5b31b16b38c53236f4d77cfef3c8d08d085b26e
3
+ metadata.gz: 7f253d1b85393689589b06dbf61824e7f1287e71b1f817c0b040628e5d79d3e3
4
+ data.tar.gz: 10cf34fcdc34f3050d424afd2c127d5b42312e933bfe582cba8279889092a030
5
5
  SHA512:
6
- metadata.gz: 39c5812d26d8151f11a21d0d8a7d2c55f05fb87bc70eb21ecaa0e51ac0b2062ab8d7c565b67b10bbfe358bed24bfe15080d7732b9cb4812c1d9a8f903493dc22
7
- data.tar.gz: a0227f046e4e46e069e1ef1df708ba1c55463c23c0155da54cbc58f4aff86df13a16613947319c7c73094b90bd0a1aacce87d76530e8f4bed533f2acf6029f76
6
+ metadata.gz: 2085b899c076c4e7e581bf94273a797747204db850eca6405b8d94e59fb6466dc63db790614e108e6d0bb9d7670cefced490ca0094692a129d26de1626ad7d15
7
+ data.tar.gz: 869897749f978d8e30bfd13a582741bbe3c4461be0bc2d90b797e1298ceba440e96f2af3fe26533176863f9cceb5a02a96d33b9be78420114ffd37b8462608ef
data/.rubocop.yml CHANGED
@@ -17,5 +17,16 @@ Naming/FileName:
17
17
  - splitclient-rb.gemspec
18
18
 
19
19
  AllCops:
20
+ TargetRubyVersion: 2.3.6
20
21
  Exclude:
21
- - lib/**/* #TODO Apply rubocop to the library
22
+ - lib/*
23
+ - lib/murmurhash/**/*
24
+ - lib/splitclient-rb/*
25
+ - lib/splitclient-rb/cache/**/*
26
+ - lib/splitclient-rb/clients/**/*
27
+ - lib/splitclient-rb/managers/**/*
28
+ - lib/splitclient-rb/engine/api/**/*
29
+ - lib/splitclient-rb/engine/evaluator/**/*
30
+ - lib/splitclient-rb/engine/metrics/**/*
31
+ - lib/splitclient-rb/engine/models/**/*
32
+ - lib/splitclient-rb/engine/parser/**/*
data/.simplecov ADDED
@@ -0,0 +1 @@
1
+ SimpleCov.start { add_filter %r{^/spec/} }
data/README.md CHANGED
@@ -30,8 +30,8 @@ Split has built and maintains a SDKs for:
30
30
  * PHP [Github](https://github.com/splitio/php-client) [Docs](http://docs.split.io/docs/php-sdk-overview)
31
31
  * Python [Github](https://github.com/splitio/python-client) [Docs](http://docs.split.io/docs/python-sdk-overview)
32
32
  * GO [Github](https://github.com/splitio/go-client) [Docs](http://docs.split.io/docs/go-sdk-overview)
33
- * Android [Github](https://github.com/splitio/android-client) [Docs](https://docs.split.io/v1/docs/android-sdk-overview)
34
- * IOS [Github](https://github.com/splitio/ios-client) [Docs](https://docs.split.io/v1/docs/ios-sdk-overview)
33
+ * Android [Github](https://github.com/splitio/android-client) [Docs](https://docs.split.io/docs/android-sdk-overview)
34
+ * IOS [Github](https://github.com/splitio/ios-client) [Docs](https://docs.split.io/docs/ios-sdk-overview)
35
35
 
36
36
  For a comprehensive list of opensource projects visit our [Github page](https://github.com/splitio?utf8=%E2%9C%93&query=%20only%3Apublic%20).
37
37
 
@@ -51,6 +51,7 @@ require 'splitclient-rb/engine/parser/condition'
51
51
  require 'splitclient-rb/engine/parser/partition'
52
52
  require 'splitclient-rb/engine/parser/split_adapter'
53
53
  require 'splitclient-rb/engine/parser/evaluator'
54
+ require 'splitclient-rb/engine/matchers/matcher'
54
55
  require 'splitclient-rb/engine/matchers/combiners'
55
56
  require 'splitclient-rb/engine/matchers/combining_matcher'
56
57
  require 'splitclient-rb/engine/matchers/all_keys_matcher'
@@ -13,18 +13,18 @@ module SplitIoClient
13
13
  @impressions_repository = impressions_repository
14
14
  @metrics_repository = metrics_repository
15
15
  @events_repository = events_repository
16
+ @destroyed = false
16
17
 
17
18
  @adapter = adapter
18
19
  end
19
20
 
20
21
  def get_treatments(key, split_names, attributes = {})
21
-
22
22
  return nil unless SplitIoClient::Validators.valid_get_treatments_parameters(split_names)
23
23
 
24
24
  sanitized_split_names = sanitize_split_names(split_names)
25
25
 
26
26
  if sanitized_split_names.empty?
27
- SplitIoClient.configuration.logger.warn('get_treatments: split_names is an empty array or has null values')
27
+ SplitIoClient.configuration.logger.error('get_treatments: split_names must be a non-empty Array')
28
28
  return {}
29
29
  end
30
30
 
@@ -73,15 +73,23 @@ module SplitIoClient
73
73
  key, split_name, attributes = {}, split_data = nil, store_impressions = true,
74
74
  multiple = false, evaluator = nil
75
75
  )
76
+
76
77
  control_treatment = { label: Engine::Models::Label::EXCEPTION, treatment: SplitIoClient::Engine::Models::Treatment::CONTROL }
77
78
  parsed_control_treatment = parsed_treatment(multiple, control_treatment)
78
79
 
79
80
  bucketing_key, matching_key = keys_from_key(key)
80
81
 
81
- return parsed_control_treatment unless SplitIoClient::Validators.valid_get_treatment_parameters(key, split_name, matching_key, bucketing_key)
82
+ return parsed_control_treatment unless valid_client && SplitIoClient::Validators.valid_get_treatment_parameters(key, split_name, matching_key, bucketing_key, attributes)
82
83
 
83
84
  bucketing_key = bucketing_key ? bucketing_key.to_s : nil
84
85
  matching_key = matching_key.to_s
86
+ sanitized_split_name = split_name.to_s.strip
87
+
88
+ if split_name.to_s != sanitized_split_name
89
+ SplitIoClient.configuration.logger.warn("get_treatment: split_name #{split_name} has extra whitespace, trimming")
90
+ split_name = sanitized_split_name
91
+ end
92
+
85
93
  evaluator ||= Engine::Parser::Evaluator.new(@segments_repository, @splits_repository)
86
94
 
87
95
  begin
@@ -117,18 +125,18 @@ module SplitIoClient
117
125
 
118
126
  def destroy
119
127
  SplitIoClient.configuration.logger.info('Split client shutdown started...') if SplitIoClient.configuration.debug_enabled
120
-
121
128
  SplitIoClient.configuration.threads[:impressions_sender].raise(SplitIoClient::ImpressionShutdownException)
122
129
  SplitIoClient.configuration.threads.reject { |k, _| k == :impressions_sender }.each do |name, thread|
123
130
  Thread.kill(thread)
124
131
  end
125
-
126
132
  @metrics_repository.clear
127
133
  @splits_repository.clear
128
134
  @segments_repository.clear
129
135
  @events_repository.clear
130
136
 
131
137
  SplitIoClient.configuration.logger.info('Split client shutdown complete') if SplitIoClient.configuration.debug_enabled
138
+ SplitIoClient.configuration.valid_mode = false
139
+ @destroyed = true
132
140
  end
133
141
 
134
142
  def store_impression(split_name, matching_key, bucketing_key, treatment, store_impressions, attributes)
@@ -177,9 +185,9 @@ module SplitIoClient
177
185
  end
178
186
 
179
187
  def track(key, traffic_type_name, event_type, value = nil)
180
- return false unless SplitIoClient::Validators.valid_track_parameters(key, traffic_type_name, event_type, value)
188
+ return false unless valid_client && SplitIoClient::Validators.valid_track_parameters(key, traffic_type_name, event_type, value)
181
189
  begin
182
- @events_repository.add(key.to_s, traffic_type_name, event_type.to_s, (Time.now.to_f * 1000).to_i, value)
190
+ @events_repository.add(key.to_s, traffic_type_name.downcase, event_type.to_s, (Time.now.to_f * 1000).to_i, value)
183
191
  true
184
192
  rescue StandardError => error
185
193
  SplitIoClient.configuration.log_found_exception(__method__.to_s, error)
@@ -210,13 +218,26 @@ module SplitIoClient
210
218
 
211
219
  def sanitize_split_names(split_names)
212
220
  split_names.compact.uniq.select do |split_name|
213
- if split_name.is_a?(String) && !split_name.empty?
221
+ if (split_name.is_a?(String) || split_name.is_a?(Symbol)) && !split_name.empty?
214
222
  true
223
+ elsif split_name.is_a?(String) && split_name.empty?
224
+ SplitIoClient.configuration.logger.warn('get_treatments: you passed an empty split_name, split_name must be a non-empty String or a Symbol')
225
+ false
215
226
  else
216
- SplitIoClient.configuration.logger.warn('get_treatments: split_name has to be a non empty string')
227
+ SplitIoClient.configuration.logger.warn('get_treatments: you passed an invalid split_name, split_name must be a non-empty String or a Symbol')
217
228
  false
218
229
  end
219
230
  end
220
231
  end
232
+
233
+ private
234
+
235
+ def valid_client
236
+ if @destroyed
237
+ SplitIoClient.configuration.logger.error('Client has already been destroyed - no calls possible')
238
+ return false
239
+ end
240
+ SplitIoClient.configuration.valid_mode
241
+ end
221
242
  end
222
243
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/http/persistent'
2
4
 
3
5
  module SplitIoClient
@@ -12,7 +14,7 @@ module SplitIoClient
12
14
  req.options[:timeout] = SplitIoClient.configuration.read_timeout
13
15
  req.options[:open_timeout] = SplitIoClient.configuration.connection_timeout
14
16
 
15
- SplitIoClient.configuration.logger.debug("GET #{url} proxy: #{api_client.proxy}") if SplitIoClient.configuration.debug_enabled
17
+ SplitLogger.log_if_debug("GET #{url} proxy: #{api_client.proxy}")
16
18
  end
17
19
  rescue StandardError => e
18
20
  SplitIoClient.configuration.logger.warn("#{e}\nURL:#{url}\nparams:#{params}")
@@ -22,23 +24,20 @@ module SplitIoClient
22
24
  def post_api(url, api_key, data, headers = {}, params = {})
23
25
  api_client.post(url) do |req|
24
26
  req.headers = common_headers(api_key)
25
- .merge('Content-Type' => 'application/json')
26
- .merge(headers)
27
+ .merge('Content-Type' => 'application/json')
28
+ .merge(headers)
27
29
 
28
30
  req.body = data.to_json
29
31
 
30
32
  req.options[:timeout] = SplitIoClient.configuration.read_timeout
31
33
  req.options[:open_timeout] = SplitIoClient.configuration.connection_timeout
32
34
 
33
- if SplitIoClient.configuration.transport_debug_enabled
34
- SplitIoClient.configuration.logger.debug("POST #{url} #{req.body}")
35
- elsif SplitIoClient.configuration.debug_enabled
36
- SplitIoClient.configuration.logger.debug("POST #{url}")
37
- end
35
+ SplitLogger.log_if_transport("POST #{url} #{req.body}")
36
+ SplitLogger.log_if_debug("POST #{url}")
38
37
  end
39
38
  rescue StandardError => e
40
39
  SplitIoClient.configuration.logger.warn("#{e}\nURL:#{url}\ndata:#{data}\nparams:#{params}")
41
- raise 'Split SDK failed to connect to backend to retrieve information'
40
+ raise 'Split SDK failed to connect to backend to post information'
42
41
  end
43
42
 
44
43
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SplitIoClient
2
4
  module Api
3
5
  class Events < Client
@@ -7,7 +9,7 @@ module SplitIoClient
7
9
 
8
10
  def post(events)
9
11
  if events.empty?
10
- SplitIoClient.configuration.logger.debug('No events to report') if SplitIoClient.configuration.debug_enabled
12
+ SplitLogger.log_if_debug('No events to report')
11
13
  return
12
14
  end
13
15
 
@@ -25,7 +27,7 @@ module SplitIoClient
25
27
  SplitLogger.log_if_debug("Events reported: #{events_slice.size}")
26
28
  else
27
29
  SplitLogger.log_error("Unexpected status code while posting events: #{response.status}." \
28
- " - Check your API key and base URI")
30
+ ' - Check your API key and base URI')
29
31
  raise 'Split SDK failed to connect to backend to post events'
30
32
  end
31
33
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'faraday'
2
4
 
3
5
  module SplitIoClient
4
6
  module FaradayMiddleware
5
7
  class Gzip < Faraday::Middleware
6
- ACCEPT_ENCODING = 'Accept-Encoding'.freeze
7
- CONTENT_ENCODING = 'Content-Encoding'.freeze
8
- CONTENT_LENGTH = 'Content-Length'.freeze
9
- SUPPORTED_ENCODINGS = 'gzip,deflate'.freeze
8
+ ACCEPT_ENCODING = 'Accept-Encoding'
9
+ CONTENT_ENCODING = 'Content-Encoding'
10
+ CONTENT_LENGTH = 'Content-Length'
11
+ SUPPORTED_ENCODINGS = 'gzip,deflate'
10
12
  RUBY_ENCODING = '1.9'.respond_to?(:force_encoding)
11
13
 
12
14
  def call(env)
@@ -30,10 +32,10 @@ module SplitIoClient
30
32
  def uncompress_gzip(body)
31
33
  io = StringIO.new(body)
32
34
  gzip_reader = if RUBY_ENCODING
33
- Zlib::GzipReader.new(io, :encoding => 'ASCII-8BIT')
34
- else
35
- Zlib::GzipReader.new(io)
36
- end
35
+ Zlib::GzipReader.new(io, encoding: 'ASCII-8BIT')
36
+ else
37
+ Zlib::GzipReader.new(io)
38
+ end
37
39
  gzip_reader.read
38
40
  end
39
41
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SplitIoClient
2
4
  module Api
3
5
  class Impressions < Client
@@ -7,7 +9,7 @@ module SplitIoClient
7
9
 
8
10
  def post(impressions)
9
11
  if impressions.empty?
10
- SplitIoClient.configuration.logger.debug('No impressions to report') if SplitIoClient.configuration.debug_enabled
12
+ SplitLogger.log_if_debug('No impressions to report')
11
13
  return
12
14
  end
13
15
 
@@ -18,7 +20,7 @@ module SplitIoClient
18
20
  SplitLogger.log_if_debug("Impressions reported: #{total_impressions(impressions)}")
19
21
  else
20
22
  SplitLogger.log_error("Unexpected status code while posting impressions: #{response.status}." \
21
- " - Check your API key and base URI")
23
+ ' - Check your API key and base URI')
22
24
  raise 'Split SDK failed to connect to backend to post impressions'
23
25
  end
24
26
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SplitIoClient
2
4
  module Api
3
5
  class Metrics < Client
@@ -15,7 +17,7 @@ module SplitIoClient
15
17
 
16
18
  def post_latencies
17
19
  if @metrics_repository.latencies.empty?
18
- SplitIoClient.configuration.logger.debug('No latencies to report.') if SplitIoClient.configuration.debug_enabled
20
+ SplitLogger.log_if_debug('No latencies to report.')
19
21
  else
20
22
  @metrics_repository.latencies.each do |name, latencies|
21
23
  metrics_time = { name: name, latencies: latencies }
@@ -31,7 +33,7 @@ module SplitIoClient
31
33
 
32
34
  def post_counts
33
35
  if @metrics_repository.counts.empty?
34
- SplitIoClient.configuration.logger.debug('No counts to report.') if SplitIoClient.configuration.debug_enabled
36
+ SplitLogger.log_if_debug('No counts to report.')
35
37
  else
36
38
  @metrics_repository.counts.each do |name, count|
37
39
  metrics_count = { name: name, delta: count }
@@ -44,14 +46,12 @@ module SplitIoClient
44
46
  @metrics_repository.clear_counts
45
47
  end
46
48
 
47
- private
48
-
49
49
  def log_status(response, info_to_log)
50
50
  if response.success?
51
51
  SplitLogger.log_if_debug("Metric time reported: #{info_to_log}")
52
52
  else
53
53
  SplitLogger.log_error("Unexpected status code while posting time metrics: #{response.status}" \
54
- " - Check your API key and base URI")
54
+ ' - Check your API key and base URI')
55
55
  raise 'Split SDK failed to connect to backend to post metrics'
56
56
  end
57
57
  end
@@ -27,6 +27,7 @@ module SplitIoClient
27
27
  till: #{@segments_repository.get_change_number(name)}")
28
28
 
29
29
  break if since.to_i >= @segments_repository.get_change_number(name).to_i
30
+
30
31
  since = @segments_repository.get_change_number(name)
31
32
  end
32
33
  end
@@ -39,7 +40,6 @@ module SplitIoClient
39
40
 
40
41
  def fetch_segment_changes(name, since)
41
42
  response = get_api("#{SplitIoClient.configuration.base_uri}/segmentChanges/#{name}", @api_key, since: since)
42
-
43
43
  if response.success?
44
44
  segment = JSON.parse(response.body, symbolize_names: true)
45
45
  @segments_repository.set_change_number(name, segment[:till])
@@ -55,6 +55,10 @@ module SplitIoClient
55
55
  SplitLogger.log_if_transport(segment.to_s)
56
56
 
57
57
  segment
58
+ elsif response.status == 403
59
+ SplitIoClient.configuration.logger.error('Factory Instantiation: You passed a browser type api_key, ' \
60
+ 'please grab an api key from the Split console that is of type sdk')
61
+ SplitIoClient.configuration.valid_mode = false
58
62
  else
59
63
  SplitLogger.log_error("Unexpected status code while fetching segments: #{response.status}." \
60
64
  "Since #{since} - Check your API key and base URI")
@@ -30,10 +30,10 @@ module SplitIoClient
30
30
 
31
31
  result
32
32
  else
33
- @metrics.count(METRICS_PREFIX + '.status.' + response.status.to_s, 1)
34
- SplitLogger.log_error("Unexpected status code while fetching splits: #{response.status}. " \
35
- 'Check your API key and base URI')
36
- raise 'Split SDK failed to connect to backend to fetch split definitions'
33
+ @metrics.count(METRICS_PREFIX + '.status.' + response.status.to_s, 1)
34
+ SplitLogger.log_error("Unexpected status code while fetching splits: #{response.status}. " \
35
+ 'Check your API key and base URI')
36
+ raise 'Split SDK failed to connect to backend to fetch split definitions'
37
37
  end
38
38
  end
39
39
 
@@ -1,15 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SplitIoClient
2
4
  #
3
5
  # class to implement the all keys matcher
4
6
  #
5
- class AllKeysMatcher
6
- MATCHER_TYPE = 'ALL_KEYS'.freeze
7
+ class AllKeysMatcher < Matcher
8
+ MATCHER_TYPE = 'ALL_KEYS'
7
9
 
8
10
  #
9
11
  # evaluates if the key matches the matcher
10
12
  #
11
13
  # @return [boolean] true for all instances
12
14
  def match?(_args)
15
+ SplitLogger.log_if_debug('[AllKeysMatcher] is always -> true')
13
16
  true
14
17
  end
15
18
 
@@ -20,25 +23,17 @@ module SplitIoClient
20
23
  #
21
24
  # @return [boolean] true if obj equals the matcher
22
25
  def equals?(obj)
23
- if obj.nil?
24
- false
25
- elsif equal?(obj)
26
+ if obj.instance_of?(AllKeysMatcher)
26
27
  true
27
- elsif !obj.instance_of?(AllKeysMatcher)
28
- false
29
28
  else
30
- true
29
+ super(obj)
31
30
  end
32
31
  end
33
32
 
34
- def string_type?
35
- false
36
- end
37
-
38
33
  #
39
34
  # function to print string value for this matcher
40
35
  #
41
- # @reutrn [string] string value of this matcher
36
+ # @return [string] string value of this matcher
42
37
  def to_s
43
38
  'in segment all'
44
39
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SplitIoClient
2
- class BetweenMatcher
3
- MATCHER_TYPE = 'BETWEEN'.freeze
4
+ class BetweenMatcher < Matcher
5
+ MATCHER_TYPE = 'BETWEEN'
4
6
 
5
7
  attr_reader :attribute
6
8
 
@@ -12,30 +14,17 @@ module SplitIoClient
12
14
  end
13
15
 
14
16
  def match?(args)
15
- return false if !args.key?(:attributes) && !args.key?(:value)
16
- return false if args.key?(:value) && args[:value].nil?
17
- return false if args.key?(:attributes) && args[:attributes].nil?
17
+ SplitLogger.log_if_debug('[BetweenMatcher] evaluating value and attributes.')
18
+
19
+ return false unless SplitIoClient::Validators.valid_matcher_arguments(args)
18
20
 
19
21
  value = formatted_value(args[:value] || args[:attributes][@attribute.to_sym])
22
+ SplitLogger.log_if_debug("[BetweenMatcher] Value from parameters: #{value}.")
20
23
  return false unless value.is_a?(Integer)
21
24
 
22
- (@start_value..@end_value).include? value
23
- end
24
-
25
- def equals?(obj)
26
- if obj.nil?
27
- false
28
- elsif !obj.instance_of?(BetweenMatcher)
29
- false
30
- elsif self.equal?(obj)
31
- true
32
- else
33
- false
34
- end
35
- end
36
-
37
- def string_type?
38
- false
25
+ matches = (@start_value..@end_value).cover? value
26
+ SplitLogger.log_if_debug("[BetweenMatcher] is #{value} between #{@start_value} and #{@end_value} -> #{matches} .")
27
+ matches
39
28
  end
40
29
 
41
30
  private
@@ -45,7 +34,7 @@ module SplitIoClient
45
34
  when 'NUMBER'
46
35
  value
47
36
  when 'DATETIME'
48
- value = value / 1000 if sdk_data
37
+ value /= 1000 if sdk_data
49
38
 
50
39
  SplitIoClient::Utilities.to_milis_zero_out_from_seconds(value)
51
40
  else