splitclient-rb 6.0.1 → 6.1.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +12 -1
- data/.simplecov +1 -0
- data/README.md +2 -2
- data/lib/splitclient-rb.rb +1 -0
- data/lib/splitclient-rb/clients/split_client.rb +30 -9
- data/lib/splitclient-rb/engine/api/client.rb +8 -9
- data/lib/splitclient-rb/engine/api/events.rb +4 -2
- data/lib/splitclient-rb/engine/api/faraday_middleware/gzip.rb +10 -8
- data/lib/splitclient-rb/engine/api/impressions.rb +4 -2
- data/lib/splitclient-rb/engine/api/metrics.rb +5 -5
- data/lib/splitclient-rb/engine/api/segments.rb +5 -1
- data/lib/splitclient-rb/engine/api/splits.rb +4 -4
- data/lib/splitclient-rb/engine/matchers/all_keys_matcher.rb +8 -13
- data/lib/splitclient-rb/engine/matchers/between_matcher.rb +12 -23
- data/lib/splitclient-rb/engine/matchers/combiners.rb +3 -1
- data/lib/splitclient-rb/engine/matchers/combining_matcher.rb +16 -24
- data/lib/splitclient-rb/engine/matchers/contains_all_matcher.rb +10 -7
- data/lib/splitclient-rb/engine/matchers/contains_any_matcher.rb +7 -6
- data/lib/splitclient-rb/engine/matchers/contains_matcher.rb +19 -8
- data/lib/splitclient-rb/engine/matchers/dependency_matcher.rb +8 -3
- data/lib/splitclient-rb/engine/matchers/ends_with_matcher.rb +21 -6
- data/lib/splitclient-rb/engine/matchers/equal_to_boolean_matcher.rb +17 -8
- data/lib/splitclient-rb/engine/matchers/equal_to_matcher.rb +11 -23
- data/lib/splitclient-rb/engine/matchers/equal_to_set_matcher.rb +7 -6
- data/lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_matcher.rb +13 -25
- data/lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb +13 -25
- data/lib/splitclient-rb/engine/matchers/matcher.rb +30 -0
- data/lib/splitclient-rb/engine/matchers/matches_string_matcher.rb +6 -2
- data/lib/splitclient-rb/engine/matchers/negation_matcher.rb +8 -22
- data/lib/splitclient-rb/engine/matchers/part_of_set_matcher.rb +10 -7
- data/lib/splitclient-rb/engine/matchers/set_matcher.rb +7 -1
- data/lib/splitclient-rb/engine/matchers/starts_with_matcher.rb +18 -5
- data/lib/splitclient-rb/engine/matchers/user_defined_segment_matcher.rb +7 -25
- data/lib/splitclient-rb/engine/matchers/whitelist_matcher.rb +33 -35
- data/lib/splitclient-rb/managers/split_manager.rb +10 -3
- data/lib/splitclient-rb/split_config.rb +34 -9
- data/lib/splitclient-rb/split_factory.rb +27 -0
- data/lib/splitclient-rb/validators.rb +104 -36
- data/lib/splitclient-rb/version.rb +1 -1
- metadata +6 -4
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SplitIoClient
|
2
|
-
class LessThanOrEqualToMatcher
|
3
|
-
MATCHER_TYPE = 'LESS_THAN_OR_EQUAL_TO'
|
4
|
+
class LessThanOrEqualToMatcher < Matcher
|
5
|
+
MATCHER_TYPE = 'LESS_THAN_OR_EQUAL_TO'
|
4
6
|
|
5
7
|
attr_reader :attribute
|
6
8
|
|
@@ -11,29 +13,15 @@ module SplitIoClient
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def match?(args)
|
14
|
-
|
15
|
-
return false if args.key?(:value) && args[:value].nil?
|
16
|
-
return false if args.key?(:attributes) && args[:attributes].nil?
|
17
|
-
|
18
|
-
value = formatted_value(args[:value] || args[:attributes][@attribute.to_sym])
|
16
|
+
SplitLogger.log_if_debug('[LessThanOrEqualToMatcher] evaluating value and attributes.')
|
19
17
|
|
20
|
-
|
21
|
-
end
|
18
|
+
return false unless SplitIoClient::Validators.valid_matcher_arguments(args)
|
22
19
|
|
23
|
-
|
24
|
-
if obj.nil?
|
25
|
-
false
|
26
|
-
elsif !obj.instance_of?(LessThanOrEqualToMatcher)
|
27
|
-
false
|
28
|
-
elsif self.equal?(obj)
|
29
|
-
true
|
30
|
-
else
|
31
|
-
false
|
32
|
-
end
|
33
|
-
end
|
20
|
+
value = formatted_value(args[:value] || args[:attributes][@attribute.to_sym])
|
34
21
|
|
35
|
-
|
36
|
-
|
22
|
+
matches = value.is_a?(Integer) ? (value <= @value) : false
|
23
|
+
SplitLogger.log_if_debug("[LessThanOrEqualToMatcher] #{value} less than or equal to #{@value} -> #{matches}")
|
24
|
+
matches
|
37
25
|
end
|
38
26
|
|
39
27
|
private
|
@@ -41,10 +29,10 @@ module SplitIoClient
|
|
41
29
|
def formatted_value(value, sdk_data = false)
|
42
30
|
case @data_type
|
43
31
|
when 'NUMBER'
|
44
|
-
|
32
|
+
value
|
45
33
|
when 'DATETIME'
|
46
|
-
value
|
47
|
-
|
34
|
+
value /= 1000 if sdk_data # sdk returns already miliseconds, turning to seconds to do a correct zero_hour
|
35
|
+
SplitIoClient::Utilities.to_milis_zero_out_from_seconds(value)
|
48
36
|
else
|
49
37
|
@logger.error('Invalid data type')
|
50
38
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SplitIoClient
|
4
|
+
#
|
5
|
+
# class to implement the all keys matcher
|
6
|
+
#
|
7
|
+
class Matcher
|
8
|
+
#
|
9
|
+
# evaluates if the given object equals the matcher
|
10
|
+
#
|
11
|
+
# @param obj [object] object to be evaluated
|
12
|
+
#
|
13
|
+
# @return [boolean] true if obj equals the matcher
|
14
|
+
def equals?(obj)
|
15
|
+
if obj.nil?
|
16
|
+
false
|
17
|
+
elsif !obj.instance_of?(self.class)
|
18
|
+
false
|
19
|
+
elsif equal?(obj)
|
20
|
+
true
|
21
|
+
else
|
22
|
+
false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def string_type?
|
27
|
+
false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SplitIoClient
|
2
4
|
class MatchesStringMatcher
|
3
|
-
MATCHER_TYPE = 'MATCHES_STRING'
|
5
|
+
MATCHER_TYPE = 'MATCHES_STRING'
|
4
6
|
|
5
7
|
attr_reader :attribute
|
6
8
|
|
@@ -14,7 +16,9 @@ module SplitIoClient
|
|
14
16
|
args[:attributes][a.to_s] || args[:attributes][a.to_sym]
|
15
17
|
end
|
16
18
|
|
17
|
-
(value =~ @regexp_string)
|
19
|
+
matches = !(value =~ @regexp_string).nil?
|
20
|
+
SplitLogger.log_if_debug("[MatchesStringMatcher] #{value} matches #{@regexp_string} -> #{matches}")
|
21
|
+
matches
|
18
22
|
end
|
19
23
|
|
20
24
|
def string_type?
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SplitIoClient
|
2
4
|
#
|
3
5
|
# class to implement the negation of a matcher
|
4
6
|
#
|
5
|
-
class NegationMatcher
|
6
|
-
MATCHER_TYPE = 'NEGATION_MATCHER'
|
7
|
+
class NegationMatcher < Matcher
|
8
|
+
MATCHER_TYPE = 'NEGATION_MATCHER'
|
7
9
|
|
8
10
|
def initialize(matcher = nil)
|
9
11
|
@matcher = matcher
|
@@ -16,7 +18,9 @@ module SplitIoClient
|
|
16
18
|
#
|
17
19
|
# @return [boolean] evaluation of the negation matcher
|
18
20
|
def match?(args)
|
19
|
-
!@matcher.match?(args)
|
21
|
+
matches = !@matcher.match?(args)
|
22
|
+
SplitLogger.log_if_debug("[NegationMatcherMatcher] Matcher #{@matcher} Arguments #{args} -> #{matches}")
|
23
|
+
matches
|
20
24
|
end
|
21
25
|
|
22
26
|
def respond_to?(method)
|
@@ -31,28 +35,10 @@ module SplitIoClient
|
|
31
35
|
@matcher.string_type?
|
32
36
|
end
|
33
37
|
|
34
|
-
#
|
35
|
-
# evaluates if the given object equals the matcher
|
36
|
-
#
|
37
|
-
# @param obj [object] object to be evaluated
|
38
|
-
#
|
39
|
-
# @returns [boolean] true if obj equals the matcher
|
40
|
-
def equals?(obj)
|
41
|
-
if obj.nil?
|
42
|
-
false
|
43
|
-
elsif !obj.instance_of?(NegationMatcher)
|
44
|
-
false
|
45
|
-
elsif self.equal?(obj)
|
46
|
-
true
|
47
|
-
else
|
48
|
-
false
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
38
|
#
|
53
39
|
# function to print string value for this matcher
|
54
40
|
#
|
55
|
-
# @
|
41
|
+
# @return [string] string value of this matcher
|
56
42
|
def to_s
|
57
43
|
"not #{@matcher}"
|
58
44
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SplitIoClient
|
2
4
|
class PartOfSetMatcher < SetMatcher
|
3
|
-
MATCHER_TYPE = 'PART_OF_SET'
|
5
|
+
MATCHER_TYPE = 'PART_OF_SET'
|
4
6
|
|
5
7
|
attr_reader :attribute
|
6
8
|
|
@@ -11,13 +13,14 @@ module SplitIoClient
|
|
11
13
|
def match?(args)
|
12
14
|
@local_set = local_set(args[:attributes], @attribute)
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
if @local_set.empty?
|
17
|
+
SplitLogger.log_if_debug('[PartOfSetMatcher] Local Set is empty.')
|
18
|
+
return false
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
matches = @local_set.subset? @remote_set
|
22
|
+
SplitLogger.log_if_debug("[PartOfSetMatcher] Local Set #{@local_set} is a subset of #{@remote_set} -> #{matches}")
|
23
|
+
matches
|
21
24
|
end
|
22
25
|
end
|
23
26
|
end
|
@@ -1,7 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'set'
|
2
4
|
|
3
5
|
module SplitIoClient
|
4
6
|
class SetMatcher
|
7
|
+
def string_type?
|
8
|
+
false
|
9
|
+
end
|
10
|
+
|
5
11
|
protected
|
6
12
|
|
7
13
|
def initialize(attribute, remote_array)
|
@@ -12,7 +18,7 @@ module SplitIoClient
|
|
12
18
|
def local_set(data, attribute)
|
13
19
|
data = data.fetch(attribute) { |a| data[a.to_s] || data[a.to_sym] }
|
14
20
|
# Allow user to pass individual elements as well
|
15
|
-
local_array = data.
|
21
|
+
local_array = data.is_a?(Array) ? data : [data]
|
16
22
|
|
17
23
|
local_array.to_set
|
18
24
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SplitIoClient
|
2
4
|
class StartsWithMatcher
|
3
|
-
MATCHER_TYPE = 'STARTS_WITH'
|
5
|
+
MATCHER_TYPE = 'STARTS_WITH'
|
4
6
|
|
5
7
|
attr_reader :attribute
|
6
8
|
|
@@ -10,17 +12,28 @@ module SplitIoClient
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def match?(args)
|
13
|
-
|
14
|
-
|
15
|
+
if @prefix_list.empty?
|
16
|
+
SplitLogger.log_if_debug('[StartsWithMatcher] Prefix List is empty.')
|
17
|
+
return false
|
15
18
|
end
|
16
19
|
|
17
|
-
|
20
|
+
value = get_value(args)
|
18
21
|
|
19
|
-
@prefix_list.any? { |prefix| value.to_s.start_with? prefix }
|
22
|
+
matches = @prefix_list.any? { |prefix| value.to_s.start_with? prefix }
|
23
|
+
SplitLogger.log_if_debug("[StartsWithMatcher] #{value} matches any of #{@prefix_list} -> #{matches}")
|
24
|
+
matches
|
20
25
|
end
|
21
26
|
|
22
27
|
def string_type?
|
23
28
|
true
|
24
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def get_value(args)
|
34
|
+
args[:value] || args[:attributes].fetch(@attribute) do |a|
|
35
|
+
args[:attributes][a.to_s] || args[:attributes][a.to_sym]
|
36
|
+
end
|
37
|
+
end
|
25
38
|
end
|
26
39
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SplitIoClient
|
2
4
|
#
|
3
5
|
# class to implement the user defined matcher
|
4
6
|
#
|
5
|
-
class UserDefinedSegmentMatcher
|
6
|
-
MATCHER_TYPE = 'IN_SEGMENT'
|
7
|
+
class UserDefinedSegmentMatcher < Matcher
|
8
|
+
MATCHER_TYPE = 'IN_SEGMENT'
|
7
9
|
|
8
10
|
def initialize(segments_repository, segment_name)
|
9
11
|
@segments_repository = segments_repository
|
@@ -17,29 +19,9 @@ module SplitIoClient
|
|
17
19
|
#
|
18
20
|
# @return [boolean] evaluation of the key against the segment
|
19
21
|
def match?(args)
|
20
|
-
@segments_repository.in_segment?(@segment_name, args[:value] || args[:matching_key])
|
21
|
-
|
22
|
-
|
23
|
-
#
|
24
|
-
# evaluates if the given object equals the matcher
|
25
|
-
#
|
26
|
-
# @param obj [object] object to be evaluated
|
27
|
-
#
|
28
|
-
# @returns [boolean] true if obj equals the matcher
|
29
|
-
def equals?(obj)
|
30
|
-
if obj.nil?
|
31
|
-
false
|
32
|
-
elsif !obj.instance_of?(UserDefinedSegmentMatcher)
|
33
|
-
false
|
34
|
-
elsif self.equal?(obj)
|
35
|
-
true
|
36
|
-
else
|
37
|
-
false
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def string_type?
|
42
|
-
false
|
22
|
+
matches = @segments_repository.in_segment?(@segment_name, args[:value] || args[:matching_key])
|
23
|
+
SplitLogger.log_if_debug("[InSegmentMatcher] #{@segment_name} is in segment -> #{matches}")
|
24
|
+
matches
|
43
25
|
end
|
44
26
|
end
|
45
27
|
end
|
@@ -1,54 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SplitIoClient
|
2
4
|
#
|
3
5
|
# class to implement the user defined matcher
|
4
6
|
#
|
5
|
-
class WhitelistMatcher <
|
7
|
+
class WhitelistMatcher < Matcher
|
6
8
|
MATCHER_TYPE = 'WHITELIST_MATCHER'
|
7
9
|
|
8
10
|
attr_reader :attribute
|
9
11
|
|
10
12
|
def initialize(whitelist_data)
|
11
13
|
@whitelist = case whitelist_data
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
when Array
|
15
|
+
whitelist_data
|
16
|
+
when Hash
|
17
|
+
@matcher_type = 'ATTR_WHITELIST'
|
18
|
+
@attribute = whitelist_data[:attribute]
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
whitelist_data[:value]
|
21
|
+
else
|
22
|
+
[]
|
23
|
+
end
|
22
24
|
end
|
23
25
|
|
24
26
|
def match?(args)
|
25
|
-
return
|
26
|
-
|
27
|
-
return false if !args.key?(:attributes) && !args.key?(:value)
|
28
|
-
return false if args.key?(:value) && args[:value].nil?
|
29
|
-
return false if args.key?(:attributes) && args[:attributes].nil?
|
27
|
+
return matches_user_whitelist(args) unless @matcher_type == 'ATTR_WHITELIST'
|
30
28
|
|
31
|
-
|
29
|
+
SplitLogger.log_if_debug('[WhitelistMatcher] evaluating value and attributes.')
|
32
30
|
|
33
|
-
false
|
34
|
-
end
|
31
|
+
return false unless SplitIoClient::Validators.valid_matcher_arguments(args)
|
35
32
|
|
36
|
-
|
37
|
-
# evaluates if the given object equals the matcher
|
38
|
-
#
|
39
|
-
# @param obj [object] object to be evaluated
|
40
|
-
#
|
41
|
-
# @returns [boolean] true if obj equals the matcher
|
42
|
-
def equals?(obj)
|
43
|
-
if obj.nil?
|
44
|
-
false
|
45
|
-
elsif !obj.instance_of?(WhitelistMatcher)
|
46
|
-
false
|
47
|
-
elsif self.equal?(obj)
|
48
|
-
true
|
49
|
-
else
|
50
|
-
false
|
51
|
-
end
|
33
|
+
matches_attr_whitelist(args)
|
52
34
|
end
|
53
35
|
|
54
36
|
def string_type?
|
@@ -58,9 +40,25 @@ module SplitIoClient
|
|
58
40
|
#
|
59
41
|
# function to print string value for this matcher
|
60
42
|
#
|
61
|
-
# @
|
43
|
+
# @return [string] string value of this matcher
|
62
44
|
def to_s
|
63
45
|
"in segment #{@whitelist}"
|
64
46
|
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def matches_user_whitelist(args)
|
51
|
+
matches = @whitelist.include?(args[:value] || args[:matching_key])
|
52
|
+
SplitLogger.log_if_debug("[WhitelistMatcher] #{@whitelist} include \
|
53
|
+
#{args[:value] || args[:matching_key]} -> #{matches}")
|
54
|
+
matches
|
55
|
+
end
|
56
|
+
|
57
|
+
def matches_attr_whitelist(args)
|
58
|
+
matches = @whitelist.include?(args[:value] || args[:attributes][@attribute.to_sym])
|
59
|
+
SplitLogger.log_if_debug("[WhitelistMatcher] #{@whitelist} include \
|
60
|
+
#{args[:value] || args[:attributes][@attribute.to_sym]} -> #{matches}")
|
61
|
+
matches
|
62
|
+
end
|
65
63
|
end
|
66
64
|
end
|
@@ -17,7 +17,7 @@ module SplitIoClient
|
|
17
17
|
#
|
18
18
|
# @returns [object] array of splits
|
19
19
|
def splits
|
20
|
-
return if @splits_repository.nil?
|
20
|
+
return [] if !SplitIoClient.configuration.valid_mode || @splits_repository.nil?
|
21
21
|
|
22
22
|
@splits_repository.splits.each_with_object([]) do |(name, split), memo|
|
23
23
|
split_view = build_split_view(name, split)
|
@@ -33,7 +33,7 @@ module SplitIoClient
|
|
33
33
|
#
|
34
34
|
# @returns [object] array of split names (String)
|
35
35
|
def split_names
|
36
|
-
return if @splits_repository.nil?
|
36
|
+
return [] if !SplitIoClient.configuration.valid_mode || @splits_repository.nil?
|
37
37
|
|
38
38
|
@splits_repository.split_names
|
39
39
|
end
|
@@ -43,7 +43,14 @@ module SplitIoClient
|
|
43
43
|
#
|
44
44
|
# @returns a split view
|
45
45
|
def split(split_name)
|
46
|
-
return unless @splits_repository && SplitIoClient::Validators.valid_split_parameters(split_name)
|
46
|
+
return unless SplitIoClient.configuration.valid_mode && @splits_repository && SplitIoClient::Validators.valid_split_parameters(split_name)
|
47
|
+
|
48
|
+
sanitized_split_name= split_name.to_s.strip
|
49
|
+
|
50
|
+
if split_name.to_s != sanitized_split_name
|
51
|
+
SplitIoClient.configuration.logger.warn("split: split_name #{split_name} has extra whitespace, trimming")
|
52
|
+
split_name = sanitized_split_name
|
53
|
+
end
|
47
54
|
|
48
55
|
split = @splits_repository.get_split(split_name)
|
49
56
|
|
@@ -43,7 +43,7 @@ module SplitIoClient
|
|
43
43
|
@redis_url = opts[:redis_url] || SplitConfig.default_redis_url
|
44
44
|
@redis_namespace = opts[:redis_namespace] ? "#{opts[:redis_namespace]}.#{SplitConfig.default_redis_namespace}" : SplitConfig.default_redis_namespace
|
45
45
|
@cache_adapter = SplitConfig.init_cache_adapter(
|
46
|
-
opts[:cache_adapter] || SplitConfig.default_cache_adapter, :map_adapter
|
46
|
+
opts[:cache_adapter] || SplitConfig.default_cache_adapter, :map_adapter, nil, @redis_url
|
47
47
|
)
|
48
48
|
@connection_timeout = opts[:connection_timeout] || SplitConfig.default_connection_timeout
|
49
49
|
@read_timeout = opts[:read_timeout] || SplitConfig.default_read_timeout
|
@@ -54,7 +54,7 @@ module SplitIoClient
|
|
54
54
|
@impressions_refresh_rate = opts[:impressions_refresh_rate] || SplitConfig.default_impressions_refresh_rate
|
55
55
|
@impressions_queue_size = opts[:impressions_queue_size] || SplitConfig.default_impressions_queue_size
|
56
56
|
@impressions_adapter = SplitConfig.init_cache_adapter(
|
57
|
-
opts[:cache_adapter] || SplitConfig.default_cache_adapter, :queue_adapter, @impressions_queue_size
|
57
|
+
opts[:cache_adapter] || SplitConfig.default_cache_adapter, :queue_adapter, @impressions_queue_size, @redis_url
|
58
58
|
)
|
59
59
|
#Safeguard for users of older SDK versions.
|
60
60
|
@disable_impressions = @impressions_queue_size == -1
|
@@ -62,13 +62,16 @@ module SplitIoClient
|
|
62
62
|
@impressions_bulk_size = opts[:impressions_bulk_size] || @impressions_queue_size > 0 ? @impressions_queue_size : 0
|
63
63
|
|
64
64
|
@metrics_adapter = SplitConfig.init_cache_adapter(
|
65
|
-
opts[:cache_adapter] || SplitConfig.default_cache_adapter, :map_adapter
|
65
|
+
opts[:cache_adapter] || SplitConfig.default_cache_adapter, :map_adapter, nil, @redis_url
|
66
66
|
)
|
67
67
|
|
68
68
|
@logger = opts[:logger] || SplitConfig.default_logger
|
69
69
|
@debug_enabled = opts[:debug_enabled] || SplitConfig.default_debug
|
70
70
|
@transport_debug_enabled = opts[:transport_debug_enabled] || SplitConfig.default_debug
|
71
71
|
@block_until_ready = opts[:ready] || opts[:block_until_ready] || 0
|
72
|
+
|
73
|
+
@logger.warn 'no ready parameter has been set - incorrect control treatments could be logged' if block_until_ready == 0
|
74
|
+
|
72
75
|
@machine_name = opts[:machine_name] || SplitConfig.machine_hostname
|
73
76
|
@machine_ip = opts[:machine_ip] || SplitConfig.machine_ip
|
74
77
|
|
@@ -83,13 +86,16 @@ module SplitIoClient
|
|
83
86
|
@impression_listener = opts[:impression_listener]
|
84
87
|
@impression_listener_refresh_rate = opts[:impression_listener_refresh_rate] || SplitConfig.default_impression_listener_refresh_rate
|
85
88
|
|
89
|
+
@max_key_size = SplitConfig.max_key_size
|
90
|
+
|
86
91
|
@threads = {}
|
87
92
|
|
88
93
|
@events_push_rate = opts[:events_push_rate] || SplitConfig.default_events_push_rate
|
89
94
|
@events_queue_size = opts[:events_queue_size] || SplitConfig.default_events_queue_size
|
90
95
|
@events_adapter = SplitConfig.init_cache_adapter(
|
91
|
-
opts[:cache_adapter] || SplitConfig.default_cache_adapter, :queue_adapter, @events_queue_size
|
96
|
+
opts[:cache_adapter] || SplitConfig.default_cache_adapter, :queue_adapter, @events_queue_size, @redis_url
|
92
97
|
)
|
98
|
+
@valid_mode = true
|
93
99
|
|
94
100
|
startup_log
|
95
101
|
end
|
@@ -184,6 +190,8 @@ module SplitIoClient
|
|
184
190
|
attr_accessor :cache_ttl
|
185
191
|
attr_accessor :max_cache_size
|
186
192
|
|
193
|
+
attr_accessor :max_key_size
|
194
|
+
|
187
195
|
attr_accessor :language
|
188
196
|
attr_accessor :version
|
189
197
|
|
@@ -208,6 +216,8 @@ module SplitIoClient
|
|
208
216
|
|
209
217
|
attr_accessor :threads
|
210
218
|
|
219
|
+
attr_accessor :valid_mode
|
220
|
+
|
211
221
|
#
|
212
222
|
# The schedule time for events flush after the first one
|
213
223
|
#
|
@@ -240,7 +250,7 @@ module SplitIoClient
|
|
240
250
|
'https://events.split.io/api/'
|
241
251
|
end
|
242
252
|
|
243
|
-
def self.init_cache_adapter(adapter, data_structure, queue_size = nil)
|
253
|
+
def self.init_cache_adapter(adapter, data_structure, queue_size = nil, redis_url = nil)
|
244
254
|
case adapter
|
245
255
|
when :memory
|
246
256
|
SplitIoClient::Cache::Adapters::MemoryAdapter.new(map_memory_adapter(data_structure, queue_size))
|
@@ -251,7 +261,7 @@ module SplitIoClient
|
|
251
261
|
fail StandardError, 'To use Redis as a cache adapter you must include it in your Gemfile'
|
252
262
|
end
|
253
263
|
|
254
|
-
SplitIoClient::Cache::Adapters::RedisAdapter.new(
|
264
|
+
SplitIoClient::Cache::Adapters::RedisAdapter.new(redis_url)
|
255
265
|
end
|
256
266
|
end
|
257
267
|
|
@@ -330,9 +340,17 @@ module SplitIoClient
|
|
330
340
|
#
|
331
341
|
# @return [object]
|
332
342
|
def self.default_logger
|
333
|
-
|
343
|
+
if defined?(Rails) && Rails.logger
|
344
|
+
Rails.logger
|
345
|
+
elsif ENV['SPLITCLIENT_ENV'] == 'test'
|
346
|
+
Logger.new('/dev/null')
|
347
|
+
else
|
348
|
+
Logger.new($stdout)
|
349
|
+
end
|
334
350
|
end
|
335
351
|
|
352
|
+
|
353
|
+
|
336
354
|
#
|
337
355
|
# The default debug value
|
338
356
|
#
|
@@ -368,18 +386,25 @@ module SplitIoClient
|
|
368
386
|
#
|
369
387
|
# The default cache time to live
|
370
388
|
#
|
371
|
-
# @return [
|
389
|
+
# @return [int]
|
372
390
|
def self.cache_ttl
|
373
391
|
5
|
374
392
|
end
|
375
393
|
|
376
394
|
# The default max cache size
|
377
395
|
#
|
378
|
-
# @return [
|
396
|
+
# @return [int]
|
379
397
|
def self.max_cache_size
|
380
398
|
500
|
381
399
|
end
|
382
400
|
|
401
|
+
# The default max key size
|
402
|
+
#
|
403
|
+
# @return [int]
|
404
|
+
def self.max_key_size
|
405
|
+
250
|
406
|
+
end
|
407
|
+
|
383
408
|
#
|
384
409
|
# custom logger of exceptions
|
385
410
|
#
|