feature_toggle_service 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +81 -7
- data/lib/feature_toggle_service/repository.rb +3 -3
- data/lib/feature_toggle_service/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94683c6c8febdcbeb9ae8df28ac90e244acf029a
|
4
|
+
data.tar.gz: fc1cb1163743da6089b743f59f69f563806dd5c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d074c23443f26130480d02d8a4f3417abe1c3dadb84664ef2a11ef63c2f7838e84e8f869d5eb690ac1e406d2b3286fc0aebe75e0b275ec9be7b287d8d70e51e4
|
7
|
+
data.tar.gz: c25a48c250aab516617b141c37ea4606a87cdcb5d415f29aee48e46988866f7823f39a6017d1646a6da617d4110276dd2dd2080f4f433f69c20ce4ca3fe2ff49
|
data/README.md
CHANGED
@@ -112,22 +112,96 @@ Or install it yourself as:
|
|
112
112
|
|
113
113
|
### Setup
|
114
114
|
|
115
|
-
Example of configuration in an Rails initializer
|
115
|
+
Example of configuration in an Rails initializer. We're setting up some config params, and also enabling by default a feature `'my_feature'`
|
116
|
+
|
117
|
+
|
118
|
+
First, we add common config to the Application config, like where do we have our etcd repository and how to access it.
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
# config/application.rb
|
122
|
+
|
123
|
+
module MyCoolProject
|
124
|
+
class Application < Rails::Application
|
125
|
+
|
126
|
+
#... other stuff
|
127
|
+
|
128
|
+
# FEATURE TOGGLE
|
129
|
+
config.feature_toggle = ActiveSupport::OrderedOptions.new
|
130
|
+
config.feature_toggle.enabled = true
|
131
|
+
config.feature_toggle.cache_toggles = true
|
132
|
+
config.feature_toggle.app_name = 'MyCoolProject'
|
133
|
+
config.feature_toggle.etcd_client = ActiveSupport::OrderedOptions.new
|
134
|
+
config.feature_toggle.etcd_client.host = 'etcd.example.org'
|
135
|
+
config.feature_toggle.etcd_client.port = 443
|
136
|
+
config.feature_toggle.etcd_client.use_ssl = true
|
137
|
+
config.feature_toggle.etcd_client.user_name = 'my-basic-auth-username'
|
138
|
+
config.feature_toggle.etcd_client.password = 'my-basic-auth-password'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
143
|
+
Then we add environment keys, overrides and defaults on the env config
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
# config/environments/mcp_int.rb
|
147
|
+
|
148
|
+
MyCoolProject::Application.configure do
|
149
|
+
|
150
|
+
# FEATURED TOGGLES
|
151
|
+
config.feature_toggle.key_suffix = 'int'
|
152
|
+
config.feature_toggle.default_on = [:feature_1, :another_feature]
|
153
|
+
config.feature_toggle.default_off = []
|
154
|
+
config.feature_toggle.override_on = [:feature_3]
|
155
|
+
config.feature_toggle.override_off = []
|
156
|
+
end
|
157
|
+
|
158
|
+
```
|
159
|
+
|
160
|
+
Finally, we load the config into `FeatureToggleService` in the initializer:
|
116
161
|
|
117
162
|
```ruby
|
163
|
+
# config/initializers/feature_toggles.rb
|
164
|
+
|
118
165
|
require 'feature_toggle_service'
|
119
166
|
|
120
167
|
# config
|
121
|
-
|
122
|
-
FeatureToggleService.config_params
|
123
|
-
|
124
|
-
|
125
|
-
|
168
|
+
ftc = Rails.configuration.feature_toggle
|
169
|
+
cp = FeatureToggleService.config_params
|
170
|
+
|
171
|
+
cp[:logger] = Rails.logger
|
172
|
+
cp[:cache_toggles] = ftc.cache_toggles unless ftc.cache_toggles.nil?
|
173
|
+
cp[:enabled] = ftc.enabled unless ftc.enabled.nil?
|
174
|
+
cp[:app_name] = ftc.app_name unless ftc.app_name.nil?
|
175
|
+
cp[:key_suffix] = ftc.key_suffix unless ftc.key_suffix.nil?
|
176
|
+
|
177
|
+
etcd_cnf = ftc.etcd_client
|
178
|
+
if etcd_cnf
|
179
|
+
cp[:etcd_client][:host] = etcd_cnf.host unless etcd_cnf.host.nil?
|
180
|
+
cp[:etcd_client][:port] = etcd_cnf.port unless etcd_cnf.port.nil?
|
181
|
+
cp[:etcd_client][:use_ssl] = etcd_cnf.use_ssl unless etcd_cnf.use_ssl.nil?
|
182
|
+
cp[:etcd_client][:user_name] = etcd_cnf.user_name unless etcd_cnf.user_name.nil?
|
183
|
+
cp[:etcd_client][:password] = etcd_cnf.password unless etcd_cnf.password.nil?
|
184
|
+
end
|
126
185
|
|
127
186
|
# specific defaults on this project
|
128
|
-
|
187
|
+
Array(ftc.default_on).each do |key|
|
188
|
+
FeatureToggleService.default_on key
|
189
|
+
end
|
190
|
+
|
191
|
+
Array(ftc.default_off).each do |key|
|
192
|
+
FeatureToggleService.default_off key
|
193
|
+
end
|
194
|
+
|
195
|
+
Array(ftc.override_on).each do |key|
|
196
|
+
FeatureToggleService.override_on key
|
197
|
+
end
|
198
|
+
|
199
|
+
Array(ftc.override_off).each do |key|
|
200
|
+
FeatureToggleService.override_off key
|
201
|
+
end
|
129
202
|
```
|
130
203
|
|
204
|
+
|
131
205
|
## Development
|
132
206
|
|
133
207
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -55,11 +55,11 @@ module FeatureToggleService
|
|
55
55
|
def retrieve_value(key)
|
56
56
|
fk = final_key(key)
|
57
57
|
etcd_get_toggle(fk)
|
58
|
-
rescue Etcd::KeyNotFound =>
|
58
|
+
rescue Etcd::KeyNotFound => _e
|
59
59
|
logger.error { "Feature Toggle without key #{key.inspect}, final key #{fk.inspect}." }
|
60
60
|
default_value_for(key)
|
61
|
-
rescue Errno::ECONNREFUSED => e
|
62
|
-
logger.error { "Cannot connect with Feature Toggle Repository! #{key.inspect}, final key #{fk.inspect}." }
|
61
|
+
rescue Errno::ECONNREFUSED, SocketError => e
|
62
|
+
logger.error { "Cannot connect with Feature Toggle Repository! #{key.inspect}, final key #{fk.inspect}. Error: #{e}" }
|
63
63
|
Airbrake.notify(e) if defined?(Airbrake)
|
64
64
|
default_value_for(key)
|
65
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feature_toggle_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo Turiño
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: etcd
|
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
218
|
version: '0'
|
219
219
|
requirements: []
|
220
220
|
rubyforge_project:
|
221
|
-
rubygems_version: 2.
|
221
|
+
rubygems_version: 2.2.2
|
222
222
|
signing_key:
|
223
223
|
specification_version: 4
|
224
224
|
summary: Service for using feature toggles in your ruby code (true/false by a specific
|