Skip to content

Commit 02944d6

Browse files
prepare 5.7.3 release (#156)
1 parent 304103d commit 02944d6

File tree

7 files changed

+75
-26
lines changed

7 files changed

+75
-26
lines changed

ext/mkrf_conf.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

launchdarkly-server-sdk.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Gem::Specification.new do |spec|
1919
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
2020
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
2121
spec.require_paths = ["lib"]
22-
spec.extensions = 'ext/mkrf_conf.rb'
2322

2423
spec.add_development_dependency "aws-sdk-dynamodb", "~> 1.18"
2524
spec.add_development_dependency "bundler", "~> 1.7"

lib/ldclient-rb/evaluation.rb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,35 +140,44 @@ def self.comparator(converter)
140140
end,
141141
endsWith:
142142
lambda do |a, b|
143-
(a.is_a? String) && (a.end_with? b)
143+
(a.is_a? String) && (b.is_a? String) && (a.end_with? b)
144144
end,
145145
startsWith:
146146
lambda do |a, b|
147-
(a.is_a? String) && (a.start_with? b)
147+
(a.is_a? String) && (b.is_a? String) && (a.start_with? b)
148148
end,
149149
matches:
150150
lambda do |a, b|
151-
(b.is_a? String) && !(Regexp.new b).match(a).nil?
151+
if (b.is_a? String) && (b.is_a? String)
152+
begin
153+
re = Regexp.new b
154+
!re.match(a).nil?
155+
rescue
156+
false
157+
end
158+
else
159+
false
160+
end
152161
end,
153162
contains:
154163
lambda do |a, b|
155-
(a.is_a? String) && (a.include? b)
164+
(a.is_a? String) && (b.is_a? String) && (a.include? b)
156165
end,
157166
lessThan:
158167
lambda do |a, b|
159-
(a.is_a? Numeric) && (a < b)
168+
(a.is_a? Numeric) && (b.is_a? Numeric) && (a < b)
160169
end,
161170
lessThanOrEqual:
162171
lambda do |a, b|
163-
(a.is_a? Numeric) && (a <= b)
172+
(a.is_a? Numeric) && (b.is_a? Numeric) && (a <= b)
164173
end,
165174
greaterThan:
166175
lambda do |a, b|
167-
(a.is_a? Numeric) && (a > b)
176+
(a.is_a? Numeric) && (b.is_a? Numeric) && (a > b)
168177
end,
169178
greaterThanOrEqual:
170179
lambda do |a, b|
171-
(a.is_a? Numeric) && (a >= b)
180+
(a.is_a? Numeric) && (b.is_a? Numeric) && (a >= b)
172181
end,
173182
before:
174183
comparator(DATE_OPERAND) { |n| n < 0 },

lib/ldclient-rb/events.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class StopMessage < SynchronousMessage
9191
# @private
9292
class EventProcessor
9393
def initialize(sdk_key, config, client = nil, diagnostic_accumulator = nil, test_properties = nil)
94+
raise ArgumentError, "sdk_key must not be nil" if sdk_key.nil? # see LDClient constructor comment on sdk_key
9495
@logger = config.logger
9596
@inbox = SizedQueue.new(config.capacity < 100 ? 100 : config.capacity)
9697
@flush_task = Concurrent::TimerTask.new(execution_interval: config.flush_interval) do

lib/ldclient-rb/ldclient.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ class LDClient
3333
# @return [LDClient] The LaunchDarkly client instance
3434
#
3535
def initialize(sdk_key, config = Config.default, wait_for_sec = 5)
36+
# Note that sdk_key is normally a required parameter, and a nil value would cause the SDK to
37+
# fail in most configurations. However, there are some configurations where it would be OK
38+
# (offline = true, *or* we are using LDD mode or the file data source and events are disabled
39+
# so we're not connecting to any LD services) so rather than try to check for all of those
40+
# up front, we will let the constructors for the data source implementations implement this
41+
# fail-fast as appropriate, and just check here for the part regarding events.
42+
if !config.offline? && config.send_events
43+
raise ArgumentError, "sdk_key must not be nil" if sdk_key.nil?
44+
end
45+
3646
@sdk_key = sdk_key
3747

3848
@event_factory_default = EventFactory.new(false)
@@ -352,6 +362,7 @@ def create_default_data_source(sdk_key, config, diagnostic_accumulator)
352362
if config.offline?
353363
return NullUpdateProcessor.new
354364
end
365+
raise ArgumentError, "sdk_key must not be nil" if sdk_key.nil? # see LDClient constructor comment on sdk_key
355366
requestor = Requestor.new(sdk_key, config)
356367
if config.stream?
357368
StreamProcessor.new(sdk_key, config, requestor, diagnostic_accumulator)

spec/evaluation_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,21 +495,21 @@ def boolean_flag_with_clauses(clauses)
495495
# mixed strings and numbers
496496
[ :in, "99", 99, false ],
497497
[ :in, 99, "99", false ],
498-
#[ :contains, "99", 99, false ], # currently throws exception - would return false in Java SDK
499-
#[ :startsWith, "99", 99, false ], # currently throws exception - would return false in Java SDK
500-
#[ :endsWith, "99", 99, false ] # currently throws exception - would return false in Java SDK
498+
[ :contains, "99", 99, false ],
499+
[ :startsWith, "99", 99, false ],
500+
[ :endsWith, "99", 99, false ],
501501
[ :lessThanOrEqual, "99", 99, false ],
502-
#[ :lessThanOrEqual, 99, "99", false ], # currently throws exception - would return false in Java SDK
502+
[ :lessThanOrEqual, 99, "99", false ],
503503
[ :greaterThanOrEqual, "99", 99, false ],
504-
#[ :greaterThanOrEqual, 99, "99", false ], # currently throws exception - would return false in Java SDK
504+
[ :greaterThanOrEqual, 99, "99", false ],
505505

506506
# regex
507507
[ :matches, "hello world", "hello.*rld", true ],
508508
[ :matches, "hello world", "hello.*orl", true ],
509509
[ :matches, "hello world", "l+", true ],
510510
[ :matches, "hello world", "(world|planet)", true ],
511511
[ :matches, "hello world", "aloha", false ],
512-
#[ :matches, "hello world", "***not a regex", false ] # currently throws exception - same as Java SDK
512+
[ :matches, "hello world", "***not a regex", false ],
513513

514514
# dates
515515
[ :before, dateStr1, dateStr2, true ],

spec/ldclient_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,46 @@ def event_processor
4949
client.instance_variable_get(:@event_processor)
5050
end
5151

52+
describe "constructor requirement of non-nil sdk key" do
53+
it "is not enforced when offline" do
54+
subject.new(nil, offline_config)
55+
end
56+
57+
it "is not enforced if use_ldd is true and send_events is false" do
58+
subject.new(nil, LaunchDarkly::Config.new({ use_ldd: true, send_events: false }))
59+
end
60+
61+
it "is not enforced if using file data and send_events is false" do
62+
source = LaunchDarkly::FileDataSource.factory({})
63+
subject.new(nil, LaunchDarkly::Config.new({ data_source: source, send_events: false }))
64+
end
65+
66+
it "is enforced in streaming mode even if send_events is false" do
67+
expect {
68+
subject.new(nil, LaunchDarkly::Config.new({ send_events: false }))
69+
}.to raise_error(ArgumentError)
70+
end
71+
72+
it "is enforced in polling mode even if send_events is false" do
73+
expect {
74+
subject.new(nil, LaunchDarkly::Config.new({ stream: false, send_events: false }))
75+
}.to raise_error(ArgumentError)
76+
end
77+
78+
it "is enforced if use_ldd is true and send_events is true" do
79+
expect {
80+
subject.new(nil, LaunchDarkly::Config.new({ use_ldd: true }))
81+
}.to raise_error(ArgumentError)
82+
end
83+
84+
it "is enforced if using file data and send_events is true" do
85+
source = LaunchDarkly::FileDataSource.factory({})
86+
expect {
87+
subject.new(nil, LaunchDarkly::Config.new({ data_source: source }))
88+
}.to raise_error(ArgumentError)
89+
end
90+
end
91+
5292
describe '#variation' do
5393
feature_with_value = { key: "key", on: false, offVariation: 0, variations: ["value"], version: 100,
5494
trackEvents: true, debugEventsUntilDate: 1000 }

0 commit comments

Comments
 (0)