feature 0.7.0 → 1.0.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.
- data/CHANGELOG.md +7 -0
- data/Gemfile +3 -3
- data/README.md +9 -2
- data/Rakefile +1 -1
- data/lib/feature/generators/install_generator.rb +1 -1
- data/lib/feature/generators/templates/feature_toggle.rb +1 -1
- data/lib/feature/repository/active_record_repository.rb +2 -2
- data/lib/feature/testing.rb +3 -2
- data/lib/feature.rb +18 -8
- data/spec/feature/active_record_repository_spec.rb +3 -3
- data/spec/feature/feature_spec.rb +25 -10
- data/spec/spec_helper.rb +1 -2
- metadata +38 -18
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 1.0.0 (2014-03-26)
|
2
|
+
|
3
|
+
* drop ruby 1.8 support
|
4
|
+
* support Rails 4 generator loading only (mauriciovieira)
|
5
|
+
* add Feature.switch method (FlavourSys)
|
6
|
+
* minor code and doc fixes and cleanup
|
7
|
+
|
1
8
|
## 0.7.0 (2013-12-07)
|
2
9
|
|
3
10
|
* add ActiveRecordRepository and a Rails::Generator (bigzed)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -5,12 +5,14 @@ Feature is a battle-tested [feature toggle](http://martinfowler.com/bliki/Featur
|
|
5
5
|
The feature toggle functionality has to be configured by feature repositories. A feature repository simply provides lists of active features (symbols!). Unknown features are assumed deactive.
|
6
6
|
With this approach Feature is higly configurable and not bound to a specific kind of configuration.
|
7
7
|
|
8
|
+
**NOTE:** Ruby 1.8 is only supported until version 0.7.0. Later Versions require at least Ruby 1.9.
|
9
|
+
|
8
10
|
## CI status
|
9
11
|
|
10
12
|
[](https://rubygems.org/gems/feature)
|
11
13
|
[](https://travis-ci.org/mgsnova/feature)
|
12
14
|
[](https://codeclimate.com/github/mgsnova/feature)
|
13
|
-
[](https://coveralls.io/r/mgsnova/feature)
|
15
|
+
[](https://coveralls.io/r/mgsnova/feature)
|
14
16
|
|
15
17
|
## Installation
|
16
18
|
|
@@ -22,7 +24,7 @@ With this approach Feature is higly configurable and not bound to a specific kin
|
|
22
24
|
* Create a repository (see examples below)
|
23
25
|
* set repository to Feature
|
24
26
|
|
25
|
-
|
27
|
+
Feature.set_repository(your_repository)
|
26
28
|
|
27
29
|
* Use Feature in your production code
|
28
30
|
|
@@ -38,6 +40,11 @@ With this approach Feature is higly configurable and not bound to a specific kin
|
|
38
40
|
# code
|
39
41
|
end
|
40
42
|
|
43
|
+
Feature.switch(:feature_name, value_true, value_false) # => returns value_true if :feature_name is active, otherwise value_false
|
44
|
+
|
45
|
+
# May also take Procs (here in Ruby 1.9 lambda syntax), returns code evaluation result.
|
46
|
+
Feature.switch(:feature_name, -> { code... }, -> { code... })
|
47
|
+
|
41
48
|
* Use Feature in your test code (for reliable testing of feature depending code)
|
42
49
|
|
43
50
|
require 'feature/testing'
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'rails/generators/active_record'
|
|
5
5
|
module Feature
|
6
6
|
class InstallGenerator < Rails::Generators::Base
|
7
7
|
include Rails::Generators::Migration
|
8
|
-
extend
|
8
|
+
extend Rails::Generators::Migration
|
9
9
|
|
10
10
|
desc 'This generator creates a migration and a model for FeatureToggles.'
|
11
11
|
source_root File.expand_path('../templates', __FILE__)
|
@@ -21,7 +21,7 @@ module Feature
|
|
21
21
|
# @return [Array<Symbol>] list of active features
|
22
22
|
#
|
23
23
|
def active_features
|
24
|
-
@model.where(:
|
24
|
+
@model.where(active: true).map { |f| f.name.to_sym }
|
25
25
|
end
|
26
26
|
|
27
27
|
# Add an active feature to repository
|
@@ -31,7 +31,7 @@ module Feature
|
|
31
31
|
def add_active_feature(feature)
|
32
32
|
check_feature_is_not_symbol(feature)
|
33
33
|
check_feature_already_in_list(feature)
|
34
|
-
@model.new(:
|
34
|
+
@model.new(name: feature.to_s, active: true).save
|
35
35
|
end
|
36
36
|
|
37
37
|
# Checks if the given feature is a not symbol and raises an exception if so
|
data/lib/feature/testing.rb
CHANGED
@@ -7,8 +7,9 @@ require 'feature'
|
|
7
7
|
# To enable Feature testing capabilities do:
|
8
8
|
# require 'feature/testing'
|
9
9
|
module Feature
|
10
|
+
|
10
11
|
# Execute the code block with the given feature active
|
11
|
-
#
|
12
|
+
#
|
12
13
|
# Example usage:
|
13
14
|
# Feature.run_with_activated(:feature) do
|
14
15
|
# # your test code here
|
@@ -22,7 +23,7 @@ module Feature
|
|
22
23
|
end
|
23
24
|
|
24
25
|
# Execute the code block with the given feature deactive
|
25
|
-
#
|
26
|
+
#
|
26
27
|
# Example usage:
|
27
28
|
# Feature.run_with_deactivated(:feature) do
|
28
29
|
# # your test code here
|
data/lib/feature.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# - to refresh the feature lists (request them from repository)
|
6
6
|
#
|
7
7
|
# @note all features not active will be handled has inactive
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# Example usage:
|
10
10
|
# repository = SimpleRepository.new
|
11
11
|
# repository.add_active_feature(:feature_name)
|
@@ -22,8 +22,8 @@
|
|
22
22
|
#
|
23
23
|
module Feature
|
24
24
|
require 'feature/repository'
|
25
|
-
# Only load the generator if Rails is defined
|
26
|
-
require 'feature/generators/install_generator' if defined?(Rails)
|
25
|
+
# Only load the generator if Rails is defined and Version is greater than 3
|
26
|
+
require 'feature/generators/install_generator' if defined?(Rails) and Rails::VERSION::STRING > "3"
|
27
27
|
|
28
28
|
@repository = nil
|
29
29
|
@active_features = nil
|
@@ -80,9 +80,7 @@ module Feature
|
|
80
80
|
raise ArgumentError, "no block given to #{__method__}"
|
81
81
|
end
|
82
82
|
|
83
|
-
if active?(feature)
|
84
|
-
yield
|
85
|
-
end
|
83
|
+
yield if active?(feature)
|
86
84
|
end
|
87
85
|
|
88
86
|
# Execute the given block if feature is inactive
|
@@ -94,8 +92,20 @@ module Feature
|
|
94
92
|
raise ArgumentError, "no block given to #{__method__}"
|
95
93
|
end
|
96
94
|
|
97
|
-
if inactive?(feature)
|
98
|
-
|
95
|
+
yield if inactive?(feature)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Return value or execute Proc/lambda depending on Feature status.
|
99
|
+
#
|
100
|
+
# @param [Symbol] feature
|
101
|
+
# @param [Object] value to be returned / lambda to be evaluated if feature is active
|
102
|
+
# @param [Object] value to be returned / lambda to be evaluated if feature is inactive
|
103
|
+
#
|
104
|
+
def self.switch(feature, l1, l2)
|
105
|
+
if active?(feature)
|
106
|
+
l1.is_a?(Proc) ? l1.call : l1
|
107
|
+
else
|
108
|
+
l2.is_a?(Proc) ? l2.call : l2
|
99
109
|
end
|
100
110
|
end
|
101
111
|
end
|
@@ -17,7 +17,7 @@ describe Feature::Repository::ActiveRecordRepository do
|
|
17
17
|
|
18
18
|
it "should add an active feature" do
|
19
19
|
@features.should_receive(:exists?).with("feature_a").and_return(false)
|
20
|
-
@features.should_receive(:new).with(:
|
20
|
+
@features.should_receive(:new).with(name: "feature_a", active: true).and_return(stub(save: true))
|
21
21
|
|
22
22
|
@repository.add_active_feature :feature_a
|
23
23
|
end
|
@@ -29,8 +29,8 @@ describe Feature::Repository::ActiveRecordRepository do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should raise an exception when adding a active feature already added as active" do
|
32
|
-
@features.should_receive(:new).with(:
|
33
|
-
@features.stub(:exists?).and_return(false,true)
|
32
|
+
@features.should_receive(:new).with(name: "feature_a", active: true).and_return(stub(save: true))
|
33
|
+
@features.stub(:exists?).and_return(false, true)
|
34
34
|
|
35
35
|
@repository.add_active_feature :feature_a
|
36
36
|
expect {
|
@@ -41,16 +41,6 @@ describe Feature do
|
|
41
41
|
end.should raise_error(ArgumentError, "given repository does not respond to active_features")
|
42
42
|
end
|
43
43
|
|
44
|
-
it "should set a feature repository" do
|
45
|
-
lambda do
|
46
|
-
Feature.active?(:feature_a)
|
47
|
-
end.should_not raise_error
|
48
|
-
|
49
|
-
lambda do
|
50
|
-
Feature.inactive?(:feature_a)
|
51
|
-
end.should_not raise_error
|
52
|
-
end
|
53
|
-
|
54
44
|
it "should get active features from repository once" do
|
55
45
|
@repository.add_active_feature(:feature_a)
|
56
46
|
Feature.active?(:feature_a).should be_false
|
@@ -145,5 +135,30 @@ describe Feature do
|
|
145
135
|
end.should raise_error(ArgumentError, "no block given to without")
|
146
136
|
end
|
147
137
|
|
138
|
+
describe 'switch()' do
|
139
|
+
context 'given a value' do
|
140
|
+
it "should return the first value if the feature is active" do
|
141
|
+
retval = Feature.switch(:feature_active, 1, 2)
|
142
|
+
expect(retval).to eq(1)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should return the second value if the feature is inactive" do
|
146
|
+
retval = Feature.switch(:feature_inactive, 1, 2)
|
147
|
+
expect(retval).to eq(2)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'given a proc/lambda' do
|
152
|
+
it "should call the first proc/lambda if the feature is active" do
|
153
|
+
retval = Feature.switch(:feature_active, lambda { 1 }, lambda { 2 })
|
154
|
+
expect(retval).to eq(1)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should call the second proc/lambda if the feature is active" do
|
158
|
+
retval = Feature.switch(:feature_inactive, lambda { 1 }, lambda { 2 })
|
159
|
+
expect(retval).to eq(2)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
148
163
|
end
|
149
164
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,22 +1,32 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: feature
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Markus Gerdes
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
17
|
+
|
18
|
+
date: 2014-03-26 00:00:00 Z
|
13
19
|
dependencies: []
|
20
|
+
|
14
21
|
description:
|
15
22
|
email: github@mgsnova.de
|
16
23
|
executables: []
|
24
|
+
|
17
25
|
extensions: []
|
26
|
+
|
18
27
|
extra_rdoc_files: []
|
19
|
-
|
28
|
+
|
29
|
+
files:
|
20
30
|
- lib/feature.rb
|
21
31
|
- lib/feature/generators/install_generator.rb
|
22
32
|
- lib/feature/generators/templates/create_feature_toggles.rb
|
@@ -39,26 +49,36 @@ files:
|
|
39
49
|
- CHANGELOG.md
|
40
50
|
homepage: http://github.com/mgsnova/feature
|
41
51
|
licenses: []
|
52
|
+
|
42
53
|
post_install_message:
|
43
54
|
rdoc_options: []
|
44
|
-
|
55
|
+
|
56
|
+
require_paths:
|
45
57
|
- lib
|
46
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
59
|
none: false
|
48
|
-
requirements:
|
49
|
-
- -
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
|
52
|
-
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
68
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
58
76
|
requirements: []
|
77
|
+
|
59
78
|
rubyforge_project:
|
60
|
-
rubygems_version: 1.8.
|
79
|
+
rubygems_version: 1.8.29
|
61
80
|
signing_key:
|
62
81
|
specification_version: 3
|
63
82
|
summary: Feature Toggle library for ruby
|
64
83
|
test_files: []
|
84
|
+
|