forked from launchdarkly/hello-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rb
More file actions
45 lines (35 loc) · 1.48 KB
/
main.rb
File metadata and controls
45 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'ldclient-rb'
# Set sdk_key to your LaunchDarkly SDK key before running
sdk_key = ""
# Set feature_flag_key to the feature flag key you want to evaluate
feature_flag_key = "my-boolean-flag"
def show_message(s)
puts "*** #{s}"
puts
end
if sdk_key == ""
show_message "Please edit main.rb to set sdk_key to your LaunchDarkly SDK key first"
exit 1
end
client = LaunchDarkly::LDClient.new(sdk_key)
if client.initialized?
show_message "SDK successfully initialized!"
else
show_message "SDK failed to initialize"
exit 1
end
# Set up the context properties. This context should appear on your LaunchDarkly contexts dashboard
# soon after you run the demo.
context = LaunchDarkly::LDContext.create({
key: "example-user-key",
kind: "user",
name: "Sandy"
})
flag_value = client.variation(feature_flag_key, context, false)
show_message "Feature flag '#{feature_flag_key}' is #{flag_value} for this context"
# Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics
# events to LaunchDarkly before the program exits. If analytics events are not delivered,
# the context properties and flag usage statistics will not appear on your dashboard. In a
# normal long-running application, the SDK would continue running and events would be
# delivered automatically in the background.
client.close()