flagship 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +31 -5
- data/lib/flagship/dsl.rb +9 -6
- data/lib/flagship/feature.rb +29 -0
- data/lib/flagship/flagset.rb +11 -22
- data/lib/flagship/version.rb +1 -1
- data/lib/flagship.rb +12 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 152c5eda261cabe740a9ffc0b42c86aa43f98365
|
4
|
+
data.tar.gz: ffe613bc7a54e1f473570705b30a36fca4dbbfac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12fee08a5382b52a4dd31dbaecebfdd454204167c6520370cf7481e3dba517b115a1cd84942cf81e72b1eff20d12ddce61c51e78be31cee4a9bd90c80fb92452
|
7
|
+
data.tar.gz: a9b877654a436dc9fe154c8849d6fbc3afcef2db6e713a35f71fbc0af7afdd02d00e32dd50fad070464e2db337f5b5f45587ef4e84088af438d474e10abc63dd
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## [0.2.0] - 2016-11-14
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- `Flagship.features` method to fetch all `Flagship::Feature`
|
8
|
+
- Tagging
|
9
|
+
- `Flagship.select_flagset` instead of `Flagship.set_flagset`
|
10
|
+
|
11
|
+
### Deprecated
|
12
|
+
|
13
|
+
- `Flagship.set_flagset` method
|
14
|
+
|
15
|
+
## [0.1.0] - 2016-10-30
|
16
|
+
|
17
|
+
### Added
|
18
|
+
|
19
|
+
- Initial release
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ Flagship.define :app do
|
|
29
29
|
disable :deprecate_feature
|
30
30
|
end
|
31
31
|
|
32
|
-
Flagship.
|
32
|
+
Flagship.select_flagset(:app)
|
33
33
|
```
|
34
34
|
|
35
35
|
### Branch with a flag
|
@@ -55,7 +55,7 @@ Flagship.set_context :foo, ->(context) { 'FOO' }
|
|
55
55
|
Or you can set a method too.
|
56
56
|
|
57
57
|
```rb
|
58
|
-
Flagship.
|
58
|
+
Flagship.set_context :current_user, method(:current_user)
|
59
59
|
```
|
60
60
|
|
61
61
|
### Extend flagset
|
@@ -74,18 +74,44 @@ Flagship.define :production, extend: :common do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
if Rails.env.production?
|
77
|
-
|
77
|
+
Flagship.select_flagset(:production)
|
78
78
|
else
|
79
|
-
|
79
|
+
Flagship.select_flagset(:development)
|
80
80
|
end
|
81
81
|
```
|
82
82
|
|
83
83
|
### Override flag with ENV
|
84
84
|
|
85
|
-
You can override flags with ENV named `
|
85
|
+
You can override flags with ENV named `FLAGSHIP_***`.
|
86
86
|
|
87
87
|
Assuming that there is a flag `:foo`, you can override it with ENV `FLAGSHIP_FOO=1`.
|
88
88
|
|
89
|
+
### Fetch all features
|
90
|
+
|
91
|
+
```rb
|
92
|
+
Flagship.features
|
93
|
+
# => Array of Flagship::Feature
|
94
|
+
|
95
|
+
Flagship.features.map(&:key)
|
96
|
+
# => Array key of enabled features
|
97
|
+
```
|
98
|
+
|
99
|
+
### Categorize features with tags
|
100
|
+
|
101
|
+
```rb
|
102
|
+
Flagship.define :blog do
|
103
|
+
enable :post
|
104
|
+
enable :comment, communication: true
|
105
|
+
enable :trackback, communication: true
|
106
|
+
end
|
107
|
+
|
108
|
+
Flagship.select_flagset(:blog)
|
109
|
+
|
110
|
+
# Fetch keys of enabled communication features
|
111
|
+
Flagship.features.select{ |feature| feature.tags[:communication] && feature.enabled? }.map(&:key)
|
112
|
+
# => [:comment, :trackback]
|
113
|
+
```
|
114
|
+
|
89
115
|
## Development
|
90
116
|
|
91
117
|
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/dsl.rb
CHANGED
@@ -5,26 +5,29 @@ class Flagship::Dsl
|
|
5
5
|
@key = key
|
6
6
|
@context = context
|
7
7
|
@base = base
|
8
|
-
@
|
8
|
+
@features = {}
|
9
9
|
@definition = block
|
10
10
|
end
|
11
11
|
|
12
12
|
def enable(key, opts = {})
|
13
|
-
|
14
|
-
|
13
|
+
opts = opts.dup
|
14
|
+
condition = opts.delete(:if)
|
15
|
+
|
16
|
+
if condition
|
17
|
+
@features[key] = ::Flagship::Feature.new(key, condition, @context, opts)
|
15
18
|
else
|
16
|
-
@
|
19
|
+
@features[key] = ::Flagship::Feature.new(key, true, @context, opts)
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
20
23
|
def disable(key, opts = {})
|
21
24
|
raise InvalidOptionError.new("Option :if is not available for #disable") if opts[:if]
|
22
25
|
|
23
|
-
@
|
26
|
+
@features[key] = ::Flagship::Feature.new(key, false, @context, opts)
|
24
27
|
end
|
25
28
|
|
26
29
|
def flagset
|
27
30
|
instance_eval(&@definition)
|
28
|
-
::Flagship::Flagset.new(@key, @
|
31
|
+
::Flagship::Flagset.new(@key, @features, @base)
|
29
32
|
end
|
30
33
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Flagship::Feature
|
2
|
+
attr_reader :key, :tags
|
3
|
+
|
4
|
+
def initialize(key, enabled, context, tags = {})
|
5
|
+
@key = key
|
6
|
+
@enabled = enabled
|
7
|
+
@context = context
|
8
|
+
@tags = tags
|
9
|
+
end
|
10
|
+
|
11
|
+
def enabled?
|
12
|
+
env = ENV['FLAGSHIP_' + key.to_s.upcase]
|
13
|
+
|
14
|
+
if env
|
15
|
+
case env.downcase
|
16
|
+
when '1', 'true'
|
17
|
+
return true
|
18
|
+
when '0', 'false', ''
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if @enabled.respond_to?(:call)
|
24
|
+
!!@enabled.call(@context)
|
25
|
+
else
|
26
|
+
!!@enabled
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/flagship/flagset.rb
CHANGED
@@ -1,34 +1,23 @@
|
|
1
1
|
class Flagship::Flagset
|
2
|
-
attr_reader :key
|
2
|
+
attr_reader :key
|
3
3
|
|
4
4
|
class UndefinedFlagError < ::StandardError; end
|
5
5
|
|
6
|
-
def initialize(key,
|
6
|
+
def initialize(key, features_hash, base = nil)
|
7
7
|
@key = key
|
8
|
-
@
|
9
|
-
|
8
|
+
@features = base ?
|
9
|
+
base.features.map{ |f| [f.key, f] }.to_h.merge(features_hash) :
|
10
|
+
features_hash
|
10
11
|
end
|
11
12
|
|
12
|
-
def enabled?(key
|
13
|
-
raise UndefinedFlagError.new("The flag :#{key} is not defined") unless @
|
13
|
+
def enabled?(key)
|
14
|
+
raise UndefinedFlagError.new("The flag :#{key} is not defined") unless @features.key? key
|
14
15
|
|
15
|
-
env = ENV['FLAGSHIP_' + key.to_s.upcase]
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
when '1', 'true'
|
20
|
-
return true
|
21
|
-
when '0', 'false', ''
|
22
|
-
return false
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
flag = @flags[key]
|
17
|
+
@features[key].enabled?
|
18
|
+
end
|
27
19
|
|
28
|
-
|
29
|
-
|
30
|
-
else
|
31
|
-
!!@flags[key]
|
32
|
-
end
|
20
|
+
def features
|
21
|
+
@features.map { |key, feature| feature }
|
33
22
|
end
|
34
23
|
end
|
data/lib/flagship/version.rb
CHANGED
data/lib/flagship.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "flagship/version"
|
2
2
|
require "flagship/context"
|
3
3
|
require "flagship/dsl"
|
4
|
+
require "flagship/feature"
|
4
5
|
require "flagship/flagset"
|
5
6
|
require "flagship/flagsets_container"
|
6
7
|
|
@@ -21,10 +22,20 @@ module Flagship
|
|
21
22
|
self.default_context.__set(key, value)
|
22
23
|
end
|
23
24
|
|
24
|
-
def self.
|
25
|
+
def self.select_flagset(key)
|
25
26
|
@@current_flagset = self.default_flagsets_container.get(key)
|
26
27
|
end
|
27
28
|
|
29
|
+
# Deprecated: Use select_flagset
|
30
|
+
def self.set_flagset(key)
|
31
|
+
warn "[DEPRECATION] `set_flagset` is deprecated. Please use `select_flagset` instead."
|
32
|
+
self.select_flagset(key)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.features
|
36
|
+
self.current_flagset.features
|
37
|
+
end
|
38
|
+
|
28
39
|
def self.get_flagset(key)
|
29
40
|
self.default_flagsets_container.get(key)
|
30
41
|
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.2.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: 2016-
|
11
|
+
date: 2016-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
64
|
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|
@@ -72,6 +73,7 @@ files:
|
|
72
73
|
- lib/flagship.rb
|
73
74
|
- lib/flagship/context.rb
|
74
75
|
- lib/flagship/dsl.rb
|
76
|
+
- lib/flagship/feature.rb
|
75
77
|
- lib/flagship/flagset.rb
|
76
78
|
- lib/flagship/flagsets_container.rb
|
77
79
|
- lib/flagship/version.rb
|