unleash 0.1.4 → 3.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +62 -3
- data/.travis.yml +12 -6
- data/README.md +84 -9
- data/Rakefile +1 -1
- data/bin/unleash-client +109 -0
- data/examples/simple.rb +8 -2
- data/lib/unleash.rb +7 -8
- data/lib/unleash/activation_strategy.rb +17 -5
- data/lib/unleash/client.rb +108 -36
- data/lib/unleash/configuration.rb +68 -41
- data/lib/unleash/constraint.rb +26 -0
- data/lib/unleash/context.rb +38 -9
- data/lib/unleash/feature_toggle.rb +137 -25
- data/lib/unleash/metrics.rb +11 -3
- data/lib/unleash/metrics_reporter.rb +10 -26
- data/lib/unleash/scheduled_executor.rb +43 -13
- data/lib/unleash/strategy/application_hostname.rb +2 -2
- data/lib/unleash/strategy/base.rb +2 -2
- data/lib/unleash/strategy/default.rb +1 -1
- data/lib/unleash/strategy/flexible_rollout.rb +55 -0
- data/lib/unleash/strategy/gradual_rollout_random.rb +1 -1
- data/lib/unleash/strategy/gradual_rollout_sessionid.rb +3 -2
- data/lib/unleash/strategy/gradual_rollout_userid.rb +3 -2
- data/lib/unleash/strategy/remote_address.rb +1 -1
- data/lib/unleash/strategy/user_with_id.rb +1 -1
- data/lib/unleash/strategy/util.rb +4 -4
- data/lib/unleash/toggle_fetcher.rb +44 -67
- data/lib/unleash/util/http.rb +48 -0
- data/lib/unleash/variant.rb +23 -0
- data/lib/unleash/variant_definition.rb +25 -0
- data/lib/unleash/variant_override.rb +44 -0
- data/lib/unleash/version.rb +1 -1
- data/unleash-client.gemspec +15 -13
- metadata +60 -26
- data/TODO.md +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da9995687fc28b71318711bd1575d9f5493fb9514cc3f276966323e4a73e15f8
|
4
|
+
data.tar.gz: e4a29a197e0faeaeaf093bb5a67103ed36aba352facf9633a6845739b17ff58c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7831894183515cbe05fb10520542b93d8a8cd521eab6ff33e9c7a4f88540519b479a76fb360a085b4f1ee059be1d03d0b531eb0daa4ff3db0147380b6f5db52
|
7
|
+
data.tar.gz: 93ce839564b8ef8af502ca148bd3e369f5463d32cd42af1d947be5d751dda88c52d8da71ee5a456658de899afe7fff159655f7f8579cf8030c81ff62655f1804
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,11 +1,70 @@
|
|
1
|
+
# inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.5
|
5
|
+
|
1
6
|
Naming/PredicateName:
|
2
|
-
|
7
|
+
AllowedMethods:
|
3
8
|
- is_enabled?
|
4
9
|
|
5
|
-
Metrics/
|
10
|
+
Metrics/ClassLength:
|
6
11
|
Max: 120
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 140
|
14
|
+
Metrics/MethodLength:
|
15
|
+
Max: 20
|
16
|
+
Metrics/BlockLength:
|
17
|
+
Max: 100
|
18
|
+
Exclude:
|
19
|
+
- 'spec/unleash/client_spec.rb'
|
20
|
+
- 'spec/unleash/feature_toggle_spec.rb'
|
7
21
|
|
22
|
+
Metrics/AbcSize:
|
23
|
+
Max: 25
|
24
|
+
Metrics/CyclomaticComplexity:
|
25
|
+
Max: 9
|
26
|
+
Metrics/PerceivedComplexity:
|
27
|
+
Max: 9
|
28
|
+
|
29
|
+
Style/Documentation:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/StringLiterals:
|
33
|
+
Enabled: false
|
8
34
|
Style/RedundantSelf:
|
9
35
|
Enabled: false
|
36
|
+
|
37
|
+
Style/SymbolArray:
|
38
|
+
EnforcedStyle: brackets
|
39
|
+
Style/WordArray:
|
40
|
+
EnforcedStyle: brackets
|
10
41
|
Style/PreferredHashMethods:
|
11
|
-
|
42
|
+
EnforcedStyle: verbose
|
43
|
+
Style/FrozenStringLiteralComment:
|
44
|
+
EnforcedStyle: never
|
45
|
+
Style/GuardClause:
|
46
|
+
MinBodyLength: 8
|
47
|
+
|
48
|
+
Style/HashEachMethods:
|
49
|
+
Enabled: true
|
50
|
+
Style/HashTransformKeys:
|
51
|
+
Enabled: true
|
52
|
+
Style/HashTransformValues:
|
53
|
+
Enabled: true
|
54
|
+
|
55
|
+
Style/IfInsideElse:
|
56
|
+
Exclude:
|
57
|
+
- 'bin/unleash-client'
|
58
|
+
|
59
|
+
Style/Next:
|
60
|
+
Exclude:
|
61
|
+
- 'lib/unleash/scheduled_executor.rb'
|
62
|
+
|
63
|
+
Layout/MultilineMethodCallIndentation:
|
64
|
+
EnforcedStyle: indented
|
65
|
+
|
66
|
+
Layout/SpaceBeforeBlockBraces:
|
67
|
+
EnforcedStyle: no_space
|
68
|
+
Exclude:
|
69
|
+
- 'unleash-client.gemspec'
|
70
|
+
- 'spec/**/*.rb'
|
data/.travis.yml
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
before_install:
|
4
|
+
- jruby
|
5
|
+
- 3.0
|
6
|
+
- 2.7
|
7
|
+
- 2.6
|
8
|
+
- 2.5
|
9
|
+
before_install:
|
10
|
+
- gem install bundler -v 2.1.4
|
11
|
+
- git clone --depth 5 --branch v3.3.0 https://github.com/Unleash/client-specification.git client-specification
|
12
|
+
|
13
|
+
notifications:
|
14
|
+
slack:
|
15
|
+
secure: x593zOjdl2yVB8uP54v8CmuCOat8GFHnK99NPvPHKvif5U7PGe0YOgYh4DC1+Jc9vfjn1ke+0++m+Gif4quowpeOaA/t45xpB494lyziXsBulYml245jRp9yzoUmIIt7KxHhv4rlo3Q1ztMJgh6a5yDCornKHW2bKTkLsvqVTwxBRatLOrt6K9O8FivO/NaqgcoXl7Rw0fOx/bsZtx2IAFueTCH19NoqW1mk9KFEZ96YqJSvuqmfDC0AO7siq03WKlB++nPlKe1QcrlPalCrcsSzrYNhYJ3akBTt/ZbE1v6YJv2L+zUqRnAPTY2H+qp8WejFQtdhIjfeJ/SWox0iWv/Wy/mTFfj+EhFO9Aq+xhMjJ1OOLtNAPoYJyatEVgJkILb6M26igTFcuI60xBbGNmh5ZYeyRdn5/xFb7G2zyJ2Swc3PvN1uLzMHfTF0R7WzGq4CRNGIOjrHTGncyB3IGAONOdJdM3iT9XKY6cdlRK0VkQjEsEMe0eNv2fxxLVSGna4sdJoTND6LhJ6qCfuS9DEDXwoRdLxAXxefycCh9VNp7gloMJx8IbHYxOW0BFZqc3hxNU9X2SwOj6j72DZMrdYDg2aPAW69HG0iMontQ37Di87JEW2F2Cpgb49+4twByrQNIx+st+DGNce1vpc0DN+KuJVdIcmha654lT7Ffe8=
|
data/README.md
CHANGED
@@ -2,17 +2,26 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/Unleash/unleash-client-ruby.svg?branch=master)](https://travis-ci.org/Unleash/unleash-client-ruby)
|
4
4
|
[![Coverage Status](https://coveralls.io/repos/github/Unleash/unleash-client-ruby/badge.svg?branch=master)](https://coveralls.io/github/Unleash/unleash-client-ruby?branch=master)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/unleash.svg)](https://badge.fury.io/rb/unleash)
|
5
6
|
|
6
7
|
Unleash client so you can roll out your features with confidence.
|
7
8
|
|
8
9
|
Leverage the [Unleash Server](https://github.com/Unleash/unleash) for powerful feature toggling in your ruby/rails applications.
|
9
10
|
|
11
|
+
## Supported Ruby Interpreters
|
12
|
+
|
13
|
+
* MRI 3.0
|
14
|
+
* MRI 2.7
|
15
|
+
* MRI 2.6
|
16
|
+
* MRI 2.5
|
17
|
+
* jruby
|
18
|
+
|
10
19
|
## Installation
|
11
20
|
|
12
21
|
Add this line to your application's Gemfile:
|
13
22
|
|
14
23
|
```ruby
|
15
|
-
gem 'unleash', '~>
|
24
|
+
gem 'unleash', '~> 3.2.2'
|
16
25
|
```
|
17
26
|
|
18
27
|
And then execute:
|
@@ -25,16 +34,15 @@ Or install it yourself as:
|
|
25
34
|
|
26
35
|
## Configure
|
27
36
|
|
28
|
-
It is **required** to configure the `url` of the unleash server. Please substitute the sample `'http://unleash.herokuapp.com/api'` for the url of your own instance.
|
37
|
+
It is **required** to configure the `url` of the unleash server and `app_name` with the name of the runninng application. Please substitute the sample `'http://unleash.herokuapp.com/api'` for the url of your own instance.
|
29
38
|
|
30
|
-
It is **highly recommended** to configure `
|
39
|
+
It is **highly recommended** to configure the `instance_id` parameter as well.
|
31
40
|
|
32
|
-
For other options please see `lib/unleash/configuration.rb`.
|
33
41
|
|
34
42
|
```ruby
|
35
43
|
Unleash.configure do |config|
|
36
|
-
config.url
|
37
|
-
config.app_name
|
44
|
+
config.url = 'http://unleash.herokuapp.com/api'
|
45
|
+
config.app_name = 'my_ruby_app'
|
38
46
|
end
|
39
47
|
```
|
40
48
|
|
@@ -44,6 +52,28 @@ or instantiate the client with the valid configuration:
|
|
44
52
|
UNLEASH = Unleash::Client.new(url: 'http://unleash.herokuapp.com/api', app_name: 'my_ruby_app')
|
45
53
|
```
|
46
54
|
|
55
|
+
#### List of Arguments
|
56
|
+
|
57
|
+
Argument | Description | Required? | Type | Default Value|
|
58
|
+
---------|-------------|-----------|-------|---------------|
|
59
|
+
`url` | Unleash server URL. | Y | String | N/A |
|
60
|
+
`app_name` | Name of your program. | Y | String | N/A |
|
61
|
+
`instance_id` | Identifier for the running instance of program. Important so you can trace back to where metrics are being collected from. **Highly recommended be be set.** | N | String | random UUID |
|
62
|
+
`environment` | Environment the program is running on. Could be for example `prod` or `dev`. Not yet in use. | N | String | `default` |
|
63
|
+
`refresh_interval` | How often the unleash client should check with the server for configuration changes. | N | Integer | 15 |
|
64
|
+
`metrics_interval` | How often the unleash client should send metrics to server. | N | Integer | 10 |
|
65
|
+
`disable_client` | Disables all communication with the Unleash server, effectively taking it *offline*. If set, `is_enabled?` will always answer with the `default_value` and configuration validation is skipped. Defeats the entire purpose of using unleash, but can be useful in when running tests. | N | Boolean | `false` |
|
66
|
+
`disable_metrics` | Disables sending metrics to Unleash server. | N | Boolean | `false` |
|
67
|
+
`custom_http_headers` | Custom headers to send to Unleash. | N | Hash | {} |
|
68
|
+
`timeout` | How long to wait for the connection to be established or wait in reading state (open_timeout/read_timeout) | N | Integer | 30 |
|
69
|
+
`retry_limit` | How many consecutive failures in connecting to the Unleash server are allowed before giving up. Use `Float::INFINITY` if you would like it to never give up. | N | Numeric | 5 |
|
70
|
+
`backup_file` | Filename to store the last known state from the Unleash server. Best to not change this from the default. | N | String | `Dir.tmpdir + "/unleash-#{app_name}-repo.json` |
|
71
|
+
`logger` | Specify a custom `Logger` class to handle logs for the Unleash client. | N | Class | `Logger.new(STDOUT)` |
|
72
|
+
`log_level` | Change the log level for the `Logger` class. Constant from `Logger::Severity`. | N | Constant | `Logger::ERROR` |
|
73
|
+
|
74
|
+
For in a more in depth look, please see `lib/unleash/configuration.rb`.
|
75
|
+
|
76
|
+
|
47
77
|
## Usage in a plain Ruby Application
|
48
78
|
|
49
79
|
```ruby
|
@@ -74,6 +104,8 @@ Unleash.configure do |config|
|
|
74
104
|
config.url = 'http://unleash.herokuapp.com/api'
|
75
105
|
config.app_name = Rails.application.class.parent.to_s
|
76
106
|
# config.instance_id = "#{Socket.gethostname}"
|
107
|
+
config.logger = Rails.logger
|
108
|
+
config.environment = Rails.env
|
77
109
|
end
|
78
110
|
|
79
111
|
UNLEASH = Unleash::Client.new
|
@@ -92,6 +124,7 @@ on_worker_boot do
|
|
92
124
|
Unleash.configure do |config|
|
93
125
|
config.url = 'http://unleash.herokuapp.com/api'
|
94
126
|
config.app_name = Rails.application.class.parent.to_s
|
127
|
+
config.environment = Rails.env
|
95
128
|
end
|
96
129
|
Rails.configuration.unleash = Unleash::Client.new
|
97
130
|
end
|
@@ -139,9 +172,53 @@ if Rails.configuration.unleash.is_enabled? "AwesomeFeature", @unleash_context
|
|
139
172
|
end
|
140
173
|
```
|
141
174
|
|
175
|
+
If the feature is not found in the server, it will by default return false. However you can override that by setting the default return value to `true`:
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
if UNLEASH.is_enabled? "AwesomeFeature", @unleash_context, true
|
179
|
+
puts "AwesomeFeature is enabled by default"
|
180
|
+
end
|
181
|
+
```
|
182
|
+
|
183
|
+
Alternatively by using `if_enabled` you can send a code block to be executed as a parameter:
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
UNLEASH.if_enabled "AwesomeFeature", @unleash_context, true do
|
187
|
+
puts "AwesomeFeature is enabled by default"
|
188
|
+
end
|
189
|
+
```
|
190
|
+
|
191
|
+
##### Variations
|
192
|
+
|
193
|
+
If no variant is found in the server, use the fallback variant.
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
fallback_variant = Unleash::Variant.new(name: 'default', enabled: true, payload: {"color" => "blue"})
|
197
|
+
variant = UNLEASH.get_variant "ColorVariants", @unleash_context, fallback_variant
|
198
|
+
|
199
|
+
puts "variant color is: #{variant.payload.fetch('color')}"
|
200
|
+
```
|
201
|
+
|
202
|
+
|
203
|
+
#### Client methods
|
204
|
+
|
205
|
+
Method Name | Description | Return Type |
|
206
|
+
---------|-------------|-------------|
|
207
|
+
`is_enabled?` | Check if feature toggle is to be enabled or not. | Boolean |
|
208
|
+
`enabled?` | Alias to the `is_enabled?` method. But more ruby idiomatic. | Boolean |
|
209
|
+
`if_enabled` | Run a code block, if a feature is enabled. | `yield` |
|
210
|
+
`get_variant` | Get variant for a given feature | `Unleash::Variant` |
|
211
|
+
`shutdown` | Save metrics to disk, flush metrics to server, and then kill ToggleFetcher and MetricsReporter threads. A safe shutdown. Not really useful in long running applications, like web applications. | nil |
|
212
|
+
`shutdown!` | Kill ToggleFetcher and MetricsReporter threads immediately. | nil |
|
213
|
+
|
214
|
+
|
142
215
|
## Local test client
|
143
216
|
|
144
217
|
```
|
218
|
+
# cli unleash client:
|
219
|
+
bundle exec bin/unleash-client --help
|
220
|
+
|
221
|
+
# or a simple sample implementation (with values hardcoded):
|
145
222
|
bundle exec examples/simple.rb
|
146
223
|
```
|
147
224
|
|
@@ -155,7 +232,7 @@ This client comes with the all the required strategies out of the box:
|
|
155
232
|
* GradualRolloutSessionIdStrategy
|
156
233
|
* GradualRolloutUserIdStrategy
|
157
234
|
* RemoteAddressStrategy
|
158
|
-
*
|
235
|
+
* UnknownStrategy
|
159
236
|
* UserWithIdStrategy
|
160
237
|
|
161
238
|
|
@@ -165,8 +242,6 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
165
242
|
|
166
243
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
167
244
|
|
168
|
-
See (TODO.md) for known limitations, and feature roadmap.
|
169
|
-
|
170
245
|
|
171
246
|
## Contributing
|
172
247
|
|
data/Rakefile
CHANGED
data/bin/unleash-client
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'unleash'
|
5
|
+
require 'unleash/client'
|
6
|
+
require 'unleash/context'
|
7
|
+
|
8
|
+
options = {
|
9
|
+
variant: false,
|
10
|
+
verbose: false,
|
11
|
+
quiet: false,
|
12
|
+
url: 'http://localhost:4242',
|
13
|
+
demo: false,
|
14
|
+
disable_metrics: true,
|
15
|
+
sleep: 0.1
|
16
|
+
}
|
17
|
+
|
18
|
+
OptionParser.new do |opts|
|
19
|
+
opts.banner = "Usage: #{__FILE__} [options] feature [key1=val1] [key2=val2]"
|
20
|
+
|
21
|
+
opts.on("-V", "--variant", "Fetch variant for feature") do |v|
|
22
|
+
options[:variant] = v
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
26
|
+
options[:verbose] = v
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("-q", "--quiet", "Quiet mode, minimum output only") do |v|
|
30
|
+
options[:quiet] = v
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on("-uURL", "--url=URL", "URL base for the Unleash feature toggle service") do |u|
|
34
|
+
options[:url] = u
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on("-d", "--demo", "Demo load by looping, instead of a simple lookup") do |d|
|
38
|
+
options[:demo] = d
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on("-m", "--[no-]metrics", "Enable metrics reporting") do |m|
|
42
|
+
options[:disable_metrics] = !m
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on("-sSLEEP", "--sleep=SLEEP", Float, "Sleep interval between checks (seconds) in demo") do |s|
|
46
|
+
options[:sleep] = s
|
47
|
+
end
|
48
|
+
|
49
|
+
opts.on("-h", "--help", "Prints this help") do
|
50
|
+
puts opts
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
end.parse!
|
54
|
+
|
55
|
+
feature_name = ARGV.shift
|
56
|
+
raise 'feature_name is required. see --help for usage.' unless feature_name
|
57
|
+
|
58
|
+
options[:verbose] = false if options[:quiet]
|
59
|
+
|
60
|
+
log_level = \
|
61
|
+
if options[:quiet]
|
62
|
+
Logger::ERROR
|
63
|
+
elsif options[:verbose]
|
64
|
+
Logger::DEBUG
|
65
|
+
else
|
66
|
+
Logger::WARN
|
67
|
+
end
|
68
|
+
|
69
|
+
@unleash = Unleash::Client.new(
|
70
|
+
url: options[:url],
|
71
|
+
app_name: 'unleash-client-ruby-cli',
|
72
|
+
disable_metrics: options[:metrics],
|
73
|
+
log_level: log_level
|
74
|
+
)
|
75
|
+
|
76
|
+
context_params = ARGV.map{ |e| e.split("=") }.map{ |k, v| [k.to_sym, v] }.to_h
|
77
|
+
context_properties = context_params.reject{ |k, _v| [:user_id, :session_id, :remote_address].include? k }
|
78
|
+
context_params.select!{ |k, _v| [:user_id, :session_id, :remote_address].include? k }
|
79
|
+
context_params.merge!(properties: context_properties) unless context_properties.nil?
|
80
|
+
unleash_context = Unleash::Context.new(context_params)
|
81
|
+
|
82
|
+
if options[:verbose]
|
83
|
+
puts "Running configuration:"
|
84
|
+
p options
|
85
|
+
puts "feature: #{feature_name}"
|
86
|
+
puts "context_args: #{ARGV}"
|
87
|
+
puts "context_params: #{context_params}"
|
88
|
+
puts "context: #{unleash_context}"
|
89
|
+
puts ""
|
90
|
+
end
|
91
|
+
|
92
|
+
if options[:demo]
|
93
|
+
loop do
|
94
|
+
enabled = @unleash.is_enabled?(feature_name, unleash_context)
|
95
|
+
print enabled ? '.' : '|'
|
96
|
+
sleep options[:sleep]
|
97
|
+
end
|
98
|
+
elsif options[:variant]
|
99
|
+
variant = @unleash.get_variant(feature_name, unleash_context)
|
100
|
+
puts " For feature \'#{feature_name}\' got variant \'#{variant}\'"
|
101
|
+
else
|
102
|
+
if @unleash.is_enabled?(feature_name, unleash_context)
|
103
|
+
puts " \'#{feature_name}\' is enabled according to unleash"
|
104
|
+
else
|
105
|
+
puts " \'#{feature_name}\' is disabled according to unleash"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
@unleash.shutdown
|
data/examples/simple.rb
CHANGED
@@ -16,12 +16,14 @@ puts ">> START simple.rb"
|
|
16
16
|
|
17
17
|
# or:
|
18
18
|
|
19
|
-
@unleash = Unleash::Client.new(
|
19
|
+
@unleash = Unleash::Client.new(
|
20
|
+
url: 'http://unleash.herokuapp.com/api',
|
21
|
+
app_name: 'simple-test',
|
20
22
|
instance_id: 'local-test-cli',
|
21
23
|
refresh_interval: 2,
|
22
24
|
metrics_interval: 2,
|
23
25
|
retry_limit: 2,
|
24
|
-
log_level: Logger::DEBUG
|
26
|
+
log_level: Logger::DEBUG
|
25
27
|
)
|
26
28
|
|
27
29
|
# feature_name = "AwesomeFeature"
|
@@ -50,4 +52,8 @@ else
|
|
50
52
|
puts "> #{feature_name} is not enabled"
|
51
53
|
end
|
52
54
|
|
55
|
+
puts "> shutting down client..."
|
56
|
+
|
57
|
+
@unleash.shutdown
|
58
|
+
|
53
59
|
puts ">> END simple.rb"
|
data/lib/unleash.rb
CHANGED
@@ -5,19 +5,19 @@ require 'unleash/context'
|
|
5
5
|
require 'unleash/client'
|
6
6
|
require 'logger'
|
7
7
|
|
8
|
-
Gem.find_files('unleash/strategy/**/*.rb').each
|
8
|
+
Gem.find_files('unleash/strategy/**/*.rb').each{ |path| require path unless path.end_with? '_spec.rb' }
|
9
9
|
|
10
10
|
module Unleash
|
11
11
|
TIME_RESOLUTION = 3
|
12
12
|
|
13
13
|
STRATEGIES = Unleash::Strategy.constants
|
14
|
-
.select
|
15
|
-
.
|
16
|
-
.map
|
14
|
+
.select{ |c| Unleash::Strategy.const_get(c).is_a? Class }
|
15
|
+
.reject{ |c| ['NotImplemented', 'Base'].include?(c.to_s) }
|
16
|
+
.map do |c|
|
17
17
|
lowered_c = c.to_s
|
18
18
|
lowered_c[0] = lowered_c[0].downcase
|
19
|
-
[lowered_c.to_sym, Object
|
20
|
-
|
19
|
+
[lowered_c.to_sym, Object.const_get("Unleash::Strategy::#{c}").new]
|
20
|
+
end
|
21
21
|
.to_h
|
22
22
|
|
23
23
|
class << self
|
@@ -30,12 +30,11 @@ module Unleash
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# Support for configuration via yield:
|
33
|
-
def self.configure
|
33
|
+
def self.configure
|
34
34
|
self.configuration ||= Unleash::Configuration.new
|
35
35
|
yield(configuration)
|
36
36
|
|
37
37
|
self.configuration.validate!
|
38
38
|
self.configuration.refresh_backup_file!
|
39
39
|
end
|
40
|
-
|
41
40
|
end
|