flagship 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +24 -4
- data/lib/flagship/dsl.rb +12 -3
- data/lib/flagship/feature.rb +4 -0
- data/lib/flagship/features.rb +19 -0
- data/lib/flagship/flagset.rb +5 -1
- data/lib/flagship/version.rb +1 -1
- data/lib/flagship.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5e0f2c9053b747cfc441a1e3ba8f31a5453d00d
|
4
|
+
data.tar.gz: ba52d5627d54d495773f47649bb8333a37793dbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb5353d961b9a00391af1e0e42028b9bc432772073743d0f4ebb291a91342a3f7aa99bd555b234fee50128bcd85ae9bd0daa44e8fb7ad86e3b502390f21c8c46
|
7
|
+
data.tar.gz: 8db9f8a90a544de056952bccc6ab0b88dd2189029b40d62c1320a40a0eb99f499a54e4a488a95879bada243f8e7532ea774a9920d85938b33c56c4895b284a56
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [0.4.0] - 2016-12-23
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- Added methods to filter `Flagship.features` [#16](https://github.com/yuya-takeyama/flagship/pull/16) [#19](https://github.com/yuya-takeyama/flagship/pull/19)
|
8
|
+
- `enabled?` method in DSL [#17](https://github.com/yuya-takeyama/flagship/pull/17)
|
9
|
+
- `Flagship.disabled?` method [#18](https://github.com/yuya-takeyama/flagship/pull/18)
|
10
|
+
|
3
11
|
## [0.3.0] - 2016-11-24
|
4
12
|
|
5
13
|
### Added
|
data/README.md
CHANGED
@@ -38,6 +38,10 @@ Flagship.select_flagset(:app)
|
|
38
38
|
if Flagship.enabled?(:some_feature)
|
39
39
|
# Implement the feature here
|
40
40
|
end
|
41
|
+
|
42
|
+
if Flagship.disabled?(:some_feature)
|
43
|
+
# Run when :some_feature is not enabled
|
44
|
+
end
|
41
45
|
```
|
42
46
|
|
43
47
|
### Set context variables
|
@@ -93,7 +97,10 @@ Flagship.features
|
|
93
97
|
# => Array of Flagship::Feature
|
94
98
|
|
95
99
|
Flagship.features.map(&:key)
|
96
|
-
# => Array key of
|
100
|
+
# => Array key of all features
|
101
|
+
|
102
|
+
Flagship.features.enabled.map(&:key)
|
103
|
+
# => Array key of all enabled features
|
97
104
|
```
|
98
105
|
|
99
106
|
### Categorize features with tags
|
@@ -102,14 +109,16 @@ Flagship.features.map(&:key)
|
|
102
109
|
Flagship.define :blog do
|
103
110
|
enable :post
|
104
111
|
enable :comment, communication: true
|
105
|
-
enable :trackback, communication: true
|
112
|
+
enable :trackback, communication: true, tracking: true
|
106
113
|
end
|
107
114
|
|
108
115
|
Flagship.select_flagset(:blog)
|
109
116
|
|
110
|
-
|
111
|
-
Flagship.features.select{ |feature| feature.tags[:communication] && feature.enabled? }.map(&:key)
|
117
|
+
Flagship.features.enabled.tagged(communication: true).map(&:key)
|
112
118
|
# => [:comment, :trackback]
|
119
|
+
|
120
|
+
Flagship.features.enabled.tagged(communication: true, tracking: true).map(&:key)
|
121
|
+
# => [:trackback]
|
113
122
|
```
|
114
123
|
|
115
124
|
### `with_tags`
|
@@ -127,6 +136,17 @@ Flagship.define :blog do
|
|
127
136
|
end
|
128
137
|
```
|
129
138
|
|
139
|
+
## Feature flag composition
|
140
|
+
|
141
|
+
You can call `#enabled?` method inside of DSL.
|
142
|
+
|
143
|
+
```rb
|
144
|
+
Flagship.define :blog do
|
145
|
+
enable :comment, if: ->(context) { context.current_user.activated? }
|
146
|
+
enable :comment_deletion, if: ->(context) { enabled?(:comment) && context.current_user.moderator? }
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
130
150
|
## Development
|
131
151
|
|
132
152
|
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
@@ -1,6 +1,8 @@
|
|
1
1
|
class Flagship::Dsl
|
2
2
|
class InvalidOptionError < ::StandardError; end
|
3
3
|
|
4
|
+
attr_reader :flagset
|
5
|
+
|
4
6
|
def initialize(key, context, base = nil, &block)
|
5
7
|
@key = key
|
6
8
|
@context = context
|
@@ -8,6 +10,10 @@ class Flagship::Dsl
|
|
8
10
|
@features = {}
|
9
11
|
@definition = block
|
10
12
|
@base_tags = {}
|
13
|
+
|
14
|
+
instance_eval(&@definition)
|
15
|
+
|
16
|
+
@flagset = ::Flagship::Flagset.new(@key, @features, @base)
|
11
17
|
end
|
12
18
|
|
13
19
|
def enable(key, opts = {})
|
@@ -36,8 +42,11 @@ class Flagship::Dsl
|
|
36
42
|
@base_tags = orig_base_tags
|
37
43
|
end
|
38
44
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
45
|
+
def enabled?(key)
|
46
|
+
@flagset.enabled?(key)
|
47
|
+
end
|
48
|
+
|
49
|
+
def disabled?(key)
|
50
|
+
@flagset.disabled?(key)
|
42
51
|
end
|
43
52
|
end
|
data/lib/flagship/feature.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
class Flagship::Features < Array
|
2
|
+
def tagged_any(tags)
|
3
|
+
self.class.new(select{|feature| tags.any?{|tag, val| feature.tags[tag] == val}})
|
4
|
+
end
|
5
|
+
|
6
|
+
def tagged(tags)
|
7
|
+
self.class.new(select{|feature| tags.all?{|tag, val| feature.tags[tag] == val}})
|
8
|
+
end
|
9
|
+
|
10
|
+
alias tagged_all tagged
|
11
|
+
|
12
|
+
def enabled
|
13
|
+
self.class.new(select(&:enabled?))
|
14
|
+
end
|
15
|
+
|
16
|
+
def disabled
|
17
|
+
self.class.new(select(&:disabled?))
|
18
|
+
end
|
19
|
+
end
|
data/lib/flagship/flagset.rb
CHANGED
@@ -17,8 +17,12 @@ class Flagship::Flagset
|
|
17
17
|
@features[key].enabled?
|
18
18
|
end
|
19
19
|
|
20
|
+
def disabled?(key)
|
21
|
+
!enabled?(key)
|
22
|
+
end
|
23
|
+
|
20
24
|
def features
|
21
|
-
@features.map { |key, feature| feature }
|
25
|
+
Flagship::Features.new @features.map { |key, feature| feature }
|
22
26
|
end
|
23
27
|
|
24
28
|
private
|
data/lib/flagship/version.rb
CHANGED
data/lib/flagship.rb
CHANGED
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.4.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-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- lib/flagship/context.rb
|
75
75
|
- lib/flagship/dsl.rb
|
76
76
|
- lib/flagship/feature.rb
|
77
|
+
- lib/flagship/features.rb
|
77
78
|
- lib/flagship/flagset.rb
|
78
79
|
- lib/flagship/flagsets_container.rb
|
79
80
|
- lib/flagship/version.rb
|
@@ -97,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
98
|
version: '0'
|
98
99
|
requirements: []
|
99
100
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.5.
|
101
|
+
rubygems_version: 2.5.2
|
101
102
|
signing_key:
|
102
103
|
specification_version: 4
|
103
104
|
summary: Ship/unship features using flags defined with declarative DSL
|