flagship 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/CHANGELOG.md +11 -0
- data/README.md +38 -0
- data/lib/flagship/context.rb +11 -0
- data/lib/flagship/version.rb +1 -1
- data/lib/flagship.rb +13 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 556082102efa5bcacc1d965b6255d0023e16078e
|
4
|
+
data.tar.gz: c7f253ce7312a0cdbbc70a80516eaabd3ee9ecaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9819f0aeee1e3ee35841cfd0a4e6451c67ce96534e6a31960f32440d56499a42e7a128b81a24864672343c2632d9bc7992924ca2be56bd755047383f3dc1da1
|
7
|
+
data.tar.gz: 0d0b6451bd8a3daf4335f761aa879fd1e62eda735e9ddd93963707ee3e58a851e540167300513c32ca4aa023847be1d56fa44e5a7549493008fcc83d59fa18a9
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [0.6.0] - 2017-05-15
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- Add `Flagship.with_context` method to apply temporal changes to context variables [#26](https://github.com/yuya-takeyama/flagship/pull/26)
|
8
|
+
- Now `Flagship.clear_state` clears context variables as well [#27](https://github.com/yuya-takeyama/flagship/pull/27)
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
- Allow `Flagship.set_context` to set multiple variables at once using `Hash` [#25](https://github.com/yuya-takeyama/flagship/pull/25)
|
13
|
+
|
3
14
|
## [0.5.0] - 2017-01-07
|
4
15
|
|
5
16
|
- Documented about helper methods [#21](https://github.com/yuya-takeyama/flagship/pull/21)
|
data/README.md
CHANGED
@@ -62,6 +62,24 @@ Or you can set a method too.
|
|
62
62
|
Flagship.set_context :current_user, method(:current_user)
|
63
63
|
```
|
64
64
|
|
65
|
+
### Apply temporal changes to context variables
|
66
|
+
|
67
|
+
Using `Flagship.with_context` method, you can override context variables temporarily.
|
68
|
+
|
69
|
+
```rb
|
70
|
+
class User
|
71
|
+
def enabled_features
|
72
|
+
Flagship.with_context current_user: self do
|
73
|
+
Flagship.features.enabled.map(&:key)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
It's useful when you implement a method using `Flagship` into some domain objects.
|
80
|
+
|
81
|
+
By using this, values specified in the argument is overridden and other values are inherited.
|
82
|
+
|
65
83
|
### Extend flagset
|
66
84
|
|
67
85
|
```rb
|
@@ -200,6 +218,26 @@ Flagship.define :production do
|
|
200
218
|
end
|
201
219
|
```
|
202
220
|
|
221
|
+
### Testing
|
222
|
+
|
223
|
+
#### RSpec
|
224
|
+
|
225
|
+
It's recommended to clear state of `Flagship` before the suite and after the each tests.
|
226
|
+
|
227
|
+
You can do it by configuring like below:
|
228
|
+
|
229
|
+
```rb
|
230
|
+
RSpec.configure do |config|
|
231
|
+
config.before(:suite) do
|
232
|
+
Flagship.clear_state
|
233
|
+
end
|
234
|
+
|
235
|
+
config.after(:each) do
|
236
|
+
Flagship.clear_state
|
237
|
+
end
|
238
|
+
end
|
239
|
+
```
|
240
|
+
|
203
241
|
## Development
|
204
242
|
|
205
243
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/flagship/context.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
class Flagship::Context
|
2
|
+
extend Forwardable
|
3
|
+
def_delegators :@values, :clear
|
4
|
+
|
2
5
|
def initialize
|
3
6
|
@values = {}
|
4
7
|
end
|
@@ -24,4 +27,12 @@ class Flagship::Context
|
|
24
27
|
def respond_to_missing?(name, include_private = false)
|
25
28
|
@values.key?(name) or super
|
26
29
|
end
|
30
|
+
|
31
|
+
def with_values(values, &block)
|
32
|
+
original_values = @values
|
33
|
+
@values = @values.dup.merge(values)
|
34
|
+
block.call
|
35
|
+
ensure
|
36
|
+
@values = original_values
|
37
|
+
end
|
27
38
|
end
|
data/lib/flagship/version.rb
CHANGED
data/lib/flagship.rb
CHANGED
@@ -20,8 +20,18 @@ module Flagship
|
|
20
20
|
current_flagset.enabled?(key)
|
21
21
|
end
|
22
22
|
|
23
|
-
def set_context(
|
24
|
-
|
23
|
+
def set_context(key_or_hash, value=nil)
|
24
|
+
if key_or_hash.is_a?(Hash)
|
25
|
+
key_or_hash.each { |k, v| default_context.__set(k, v) }
|
26
|
+
else
|
27
|
+
default_context.__set(key_or_hash, value)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def with_context(values, &block)
|
32
|
+
default_context.with_values values do
|
33
|
+
block.call
|
34
|
+
end
|
25
35
|
end
|
26
36
|
|
27
37
|
def select_flagset(key)
|
@@ -51,6 +61,7 @@ module Flagship
|
|
51
61
|
def clear_state
|
52
62
|
@default_flagsts_container = nil
|
53
63
|
@current_flagset = nil
|
64
|
+
@default_context && @default_context.clear
|
54
65
|
end
|
55
66
|
end
|
56
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flagship
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuya Takeyama
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|