flagship 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cc791479b0f25f7d381e01b9dd1a34b214f4d7e
4
- data.tar.gz: f485f304352532299eb3757ca01bcb1d9978cfc1
3
+ metadata.gz: b5e0f2c9053b747cfc441a1e3ba8f31a5453d00d
4
+ data.tar.gz: ba52d5627d54d495773f47649bb8333a37793dbe
5
5
  SHA512:
6
- metadata.gz: 42632f27ed80b517a0662dc2ac8df22566aa3ae41a1ec80bcf7630ca46abdd19d52b0ce3f9ed83112d7ccf7120b580e3cbeb49d7abc299ad94819d1b1d1d7e94
7
- data.tar.gz: 2a28a9460e250b90d43837c56d56e0ec9189cc3dc0df5a6e3dfc6e20c0982d0c34a10af5bac4b7b61000736e8ce8cc9b74ce0a65d95b8e27cf4d054e079c37f0
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 enabled features
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
- # Fetch keys of enabled communication features
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 flagset
40
- instance_eval(&@definition)
41
- ::Flagship::Flagset.new(@key, @features, @base)
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
@@ -27,6 +27,10 @@ class Flagship::Feature
27
27
  end
28
28
  end
29
29
 
30
+ def disabled?
31
+ !enabled?
32
+ end
33
+
30
34
  def extend_feature(feature)
31
35
  self.class.new(@key, @enabled, @context, feature.tags.merge(@tags))
32
36
  end
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Flagship
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/flagship.rb CHANGED
@@ -2,6 +2,7 @@ require "flagship/version"
2
2
  require "flagship/context"
3
3
  require "flagship/dsl"
4
4
  require "flagship/feature"
5
+ require "flagship/features"
5
6
  require "flagship/flagset"
6
7
  require "flagship/flagsets_container"
7
8
 
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.3.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-23 00:00:00.000000000 Z
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.1
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