abstract_feature_branch 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +97 -57
- data/VERSION +1 -1
- data/abstract_feature_branch.gemspec +2 -2
- data/lib/ext/feature_branch.rb +19 -8
- metadata +3 -3
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
Abstract Feature Branch
|
2
|
-
|
1
|
+
Abstract Feature Branch 0.2.0
|
2
|
+
=============================
|
3
3
|
|
4
4
|
abstract_feature_branch is a Rails gem that enables developers to easily branch by
|
5
5
|
abstraction as per this pattern: http://paulhammant.com/blog/branch_by_abstraction.html
|
@@ -15,77 +15,117 @@ switched on in production, but do enable them in staging and locally.
|
|
15
15
|
This gives developers the added benefit of being able to switch a feature off after
|
16
16
|
release should big problems arise for a high risk feature.
|
17
17
|
|
18
|
+
Requirements
|
19
|
+
------------
|
20
|
+
- Ruby 1.9.x or 1.8.7x
|
21
|
+
- Rails 3.x or 2.x
|
22
|
+
|
18
23
|
Setup
|
19
24
|
-----
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
1. Add 'abstract_feature_branch' gem to Gemfile in Rails 3.x or
|
26
|
+
- Add 'abstract_feature_branch' gem to Gemfile in Rails 3.x or
|
24
27
|
"config.gem 'absract_feature_branch'" to environment.rb in Rails 2.x
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
Notice how the feature "
|
28
|
+
- Configure config/features.yml in your Rails app directory as follows:
|
29
|
+
|
30
|
+
> defaults: &defaults
|
31
|
+
> features:
|
32
|
+
> feature1: true
|
33
|
+
> feature2: true
|
34
|
+
> feature3: false
|
35
|
+
>
|
36
|
+
> development:
|
37
|
+
> <<: *defaults
|
38
|
+
>
|
39
|
+
> test:
|
40
|
+
> <<: *defaults
|
41
|
+
>
|
42
|
+
> staging:
|
43
|
+
> <<: *defaults
|
44
|
+
> feature2: false
|
45
|
+
>
|
46
|
+
> production:
|
47
|
+
> <<: *defaults
|
48
|
+
> features:
|
49
|
+
> feature1: false
|
50
|
+
> feature2: false
|
51
|
+
|
52
|
+
Notice how the feature "feature1" was configured as true (enabled) by default, but
|
50
53
|
overridden as false (disabled) in production. This is a recommended practice.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
|
55
|
+
Instructions
|
56
|
+
------------
|
57
|
+
|
58
|
+
- declaratively feature branch logic to only run when feature1 is enabled:
|
59
|
+
|
60
|
+
> feature_branch :feature1 do
|
61
|
+
> # perform logic
|
62
|
+
> end
|
63
|
+
|
64
|
+
- declaratively feature branch two paths of logic, one that runs when feature1 is enabled and one that runs when it is disabled:
|
65
|
+
|
66
|
+
> feature_branch :feature1,
|
67
|
+
> :true => lambda {
|
68
|
+
> # perform logic
|
69
|
+
> },
|
70
|
+
> :false => lambda {
|
71
|
+
> # perform alternate logic
|
72
|
+
> }
|
73
|
+
|
74
|
+
- imperatively check if a feature is enabled or not:
|
75
|
+
|
76
|
+
> if feature_enabled?(:feature1)
|
77
|
+
> # perform logic
|
78
|
+
> else
|
79
|
+
> # perform alternate logic
|
80
|
+
> end
|
57
81
|
|
58
82
|
Recommendations
|
59
83
|
---------------
|
84
|
+
|
60
85
|
- Wrap routes in routes.rb with feature blocks to disable entire MVC feature elements by
|
61
86
|
simply switching off the URL route to them. Example:
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
\*
|
87
|
+
|
88
|
+
> feature_branch :add_business_project do
|
89
|
+
> resources :projects
|
90
|
+
> end
|
67
91
|
|
68
92
|
- Wrap visual links to these routes in ERB views. Example:
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
93
|
+
|
94
|
+
> <% feature_branch :add_business_project do %>
|
95
|
+
> <h2>Submit a Business</h2>
|
96
|
+
> <p>
|
97
|
+
> Please submit a business idea for review.
|
98
|
+
> </p>
|
99
|
+
> <ul>
|
100
|
+
> <% current_user.projects.each do |p| %>
|
101
|
+
> <li><%= link_to p.business_campaign_name, project_path(p) %></li>
|
102
|
+
> <% end %>
|
103
|
+
> </ul>
|
104
|
+
> <h4>
|
105
|
+
> <%= link_to('Start', new_project_path, :id => "business_background_invitation", :class => 'button') %>
|
106
|
+
> </h4>
|
107
|
+
> <% end %>
|
108
|
+
|
85
109
|
- Once a feature has been released and switched on in production, and it has worked well for a while,
|
86
110
|
it is recommended that its feature branching code is plucked out of the code base to simplify the code
|
87
111
|
for better maintenance as the need is not longer there for feature branching at that point.
|
88
112
|
|
113
|
+
Release Notes
|
114
|
+
-------------
|
115
|
+
|
116
|
+
Version 0.2.0:
|
117
|
+
|
118
|
+
- Support an "else" block to execute when a feature is off (via :true and :false lambda arguments)
|
119
|
+
- Support ability to check if a feature is enabled or not (via feature_enabled?)
|
120
|
+
|
121
|
+
Upcoming
|
122
|
+
--------
|
123
|
+
|
124
|
+
- Support the option of having multiple features.yml files, one per environment, as opposed to one for all environments
|
125
|
+
- Support general Ruby (non-Rails) use
|
126
|
+
- Support contexts of features to group features, once they grow beyond a certain size, in separate files, one per context
|
127
|
+
- Simplify features.yml requirement to have a features header under each environment
|
128
|
+
- Add rake task to reorder feature entries in feature.yml alphabetically
|
89
129
|
|
90
130
|
Contributing to abstract_feature_branch
|
91
131
|
---------------------------------------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "abstract_feature_branch"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Annas \"Andy\" Maleh"]
|
12
|
-
s.date = "2012-11-
|
12
|
+
s.date = "2012-11-25"
|
13
13
|
s.description = "It gives ability to wrap blocks of code with an abstract feature branch name, and then\nspecify which features to be switched on or off in a configuration file.\n\nThe goal is to build out future features with full integration into the codebase, thus\nensuring no delay in integration in the future, while releasing currently done features\nat the same time. Developers then disable future features until they are ready to be\nswitched on in production, but do enable them in staging and locally.\n\nThis gives developers the added benefit of being able to switch a feature off after\nrelease should big problems arise for a high risk feature.\n"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
data/lib/ext/feature_branch.rb
CHANGED
@@ -1,13 +1,24 @@
|
|
1
1
|
class Object
|
2
|
-
raise 'Abstract branch conflicts with another Ruby library' if respond_to?(:feature_branch)
|
3
|
-
def self.feature_branch(feature_name, &feature_work)
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
raise 'Abstract feature branch conflicts with another Ruby library' if respond_to?(:feature_branch)
|
3
|
+
def self.feature_branch(feature_name, branches = {}, &feature_work)
|
4
|
+
branches[:true] ||= feature_work
|
5
|
+
branches[:false] ||= lambda {}
|
6
|
+
feature_status = Settings[Rails.env.to_s]['features'][feature_name].to_s.to_sym
|
7
|
+
branches[feature_status].call
|
7
8
|
end
|
8
9
|
|
9
|
-
raise 'Abstract branch conflicts with another Ruby library' if
|
10
|
-
def
|
11
|
-
|
10
|
+
raise 'Abstract feature branch conflicts with another Ruby library' if respond_to?(:feature_enabled?)
|
11
|
+
def self.feature_enabled?(feature_name)
|
12
|
+
Settings[Rails.env.to_s]['features'][feature_name]
|
13
|
+
end
|
14
|
+
|
15
|
+
raise 'Abstract feature branch conflicts with another Ruby library' if Object.new.respond_to?(:feature_branch)
|
16
|
+
def feature_branch(feature_name, branches = {}, &feature_work)
|
17
|
+
Object.feature_branch(feature_name, branches, &feature_work)
|
18
|
+
end
|
19
|
+
|
20
|
+
raise 'Abstract feature branch conflicts with another Ruby library' if Object.new.respond_to?(:feature_enabled?)
|
21
|
+
def feature_enabled?(feature_name)
|
22
|
+
Object.feature_enabled?(feature_name)
|
12
23
|
end
|
13
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abstract_feature_branch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails_config
|
@@ -141,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
segments:
|
143
143
|
- 0
|
144
|
-
hash:
|
144
|
+
hash: 2916198605962621809
|
145
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
146
|
none: false
|
147
147
|
requirements:
|