abstract_feature_branch 0.3.6 → 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: 6f1030acce2b8092fcf6ac90e233253b273d5e10
4
- data.tar.gz: 91baad506146ddd0aa419062c30c8d3f7d8dae3e
3
+ metadata.gz: c6a6aaa5dee1e8e0fa7d7dba8051fe8a160e1cb1
4
+ data.tar.gz: 7f089bf19a1c027ba5e4e27cea6cfccf92d5dd40
5
5
  SHA512:
6
- metadata.gz: c4a44fabd06d5945c799cc157b22019cc2522fcbe7aa86ff0174d83f0bba64eebdee6d539b28c2628c61b0d84343167ed6ff37f17877ad6241f750472ee5be7c
7
- data.tar.gz: 54c63e4ea5f19b9900ec5b565f8c8100f033bdaa35a40640dd960d3809855f109b5eb8defd5bbe825122eeff18eda10bce03a82af32e0cf5bdb42372a81cbb3b
6
+ metadata.gz: 7b8e441a5218c69ba59fee50418b379d99ffd00298f370b3e6939a043f97f2f85d1e72a056722e005f0d2694672023fa6efe6b6a72455767e009c996f9c4fdb2
7
+ data.tar.gz: a07a4fbcc2ad0e16d9f75be7563a91970eda21e67d1c085804f2648f215f7fdb65f9076949ce9c843b3fc64d8f5740790bc557d0c95ae7990c7f10ff223bcfb3
data/README.md CHANGED
@@ -24,11 +24,15 @@ Setup
24
24
  -----
25
25
 
26
26
  1. Configure Rubygem
27
- - Rails (~> 4.0.0 or ~> 3.0): Add the following to Gemfile <pre>gem 'abstract_feature_branch', '0.3.6'</pre>
28
- - Rails (~> 2.0): Add the following to config/environment.rb <pre>config.gem 'absract_feature_branch'</pre>
27
+ - Rails (~> 4.0.0 or ~> 3.0): Add the following to Gemfile <pre>gem 'abstract_feature_branch', '0.4.0'</pre>
28
+ - Rails (~> 2.0): Add the following to config/environment.rb <pre>config.gem 'absract_feature_branch', :version => '0.4.0'</pre>
29
29
  2. Generate config/features.yml in your Rails app directory by running <pre>rails g abstract_feature_branch:install</pre>
30
30
 
31
- Here are the contents of the generated sample config/features.yml, which you can modify with your own features.
31
+ Instructions
32
+ ------------
33
+
34
+ Here are the contents of the generated sample config/features.yml, which you can modify with your own features, each
35
+ enabled (true) or disabled (false) per environment (e.g. production).
32
36
 
33
37
  > defaults: &defaults
34
38
  > feature1: true
@@ -53,9 +57,6 @@ Here are the contents of the generated sample config/features.yml, which you can
53
57
  Notice in the sample file how the feature "feature1" was configured as true (enabled) by default, but
54
58
  overridden as false (disabled) in production. This is a recommended practice.
55
59
 
56
- Instructions
57
- ------------
58
-
59
60
  - Declaratively feature branch logic to only run when feature1 is enabled:
60
61
 
61
62
  multi-line logic:
@@ -90,6 +91,38 @@ Note that feature_branch executes the false branch if the feature is non-existen
90
91
 
91
92
  Note that feature_enabled? returns false if the feature is disabled and nil if the feature is non-existent (practically the same effect, but nil can sometimes be useful to detect if a feature is referenced).
92
93
 
94
+ Environment Variable Overrides
95
+ ------------------------------
96
+
97
+ You can override feature configuration with environment variables by setting an environment variable with
98
+ a name matching this convention (case-insensitive):
99
+ ABSTRACT_FEATURE_BRANCH_[feature_name] and giving it the case-insensitive value "TRUE" or "FALSE"
100
+
101
+ Examples:
102
+
103
+ - export ABSTRACT_FEATURE_BRANCH_FEATURE1=TRUE
104
+ - export abstract_feature_branch_feature2=false
105
+
106
+ Heroku
107
+ ------
108
+
109
+ Environment variable overrides can be extremely helpful on Heroku as they allow developers to enable/disable features
110
+ at runtime without a redeploy.
111
+
112
+ Examples:
113
+
114
+ Enabling a new feature without a redeploy:
115
+ <pre>heroku config:add ABSTRACT_FEATURE_BRANCH_FEATURE3=true -a heroku_application_name</pre>
116
+
117
+ Disabling a buggy recently deployed feature without a redeploy:
118
+ <pre>heroku config:add ABSTRACT_FEATURE_BRANCH_FEATURE2=false -a heroku_application_name</pre>
119
+
120
+ Removing an environment variable override:
121
+ <pre>heroku config:remove ABSTRACT_FEATURE_BRANCH_FEATURE2 -a heroku_application_name</pre>
122
+
123
+ Note that it is recommended to use environment variables as an emergency or temporary measure, make the change
124
+ officially in config/features.yml afterward, deploy, and finally remove the environment variable override for the long term.
125
+
93
126
  Recommendations
94
127
  ---------------
95
128
 
@@ -153,6 +186,9 @@ for better maintenance as the need is not longer there for feature branching at
153
186
  Release Notes
154
187
  -------------
155
188
 
189
+ Version 0.4.0:
190
+ - Added support for overwriting feature configuration with environment variable overrides. Very useful on Heroku to quickly enable/disable features without a redeploy.
191
+
156
192
  Version 0.3.6:
157
193
  - Fixed feature_branch issue with invalid feature name, preventing block execution and returning nil instead
158
194
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.6
1
+ 0.4.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.3.6"
8
+ s.version = "0.4.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 = "2013-11-19"
12
+ s.date = "2013-11-21"
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",
@@ -3,8 +3,10 @@ class Object
3
3
  def self.feature_branch(feature_name, branches = {}, &feature_work)
4
4
  branches[:true] ||= feature_work
5
5
  branches[:false] ||= lambda {}
6
- feature_status = (AbstractFeatureBranch.features[Rails.env.to_s][feature_name.to_s] || false).to_s.to_sym
7
- branches[feature_status].call
6
+ feature_status = abstract_feature_branch_environment_value(feature_name)
7
+ feature_status = AbstractFeatureBranch.features[Rails.env.to_s][feature_name.to_s] if feature_status.nil?
8
+ feature_status = false if feature_status.nil?
9
+ branches[feature_status.to_s.to_sym].call
8
10
  end
9
11
 
10
12
  raise 'Abstract feature branch conflicts with another Ruby library' if respond_to?(:feature_enabled?)
@@ -21,4 +23,15 @@ class Object
21
23
  def feature_enabled?(feature_name)
22
24
  Object.feature_enabled?(feature_name.to_s)
23
25
  end
26
+
27
+ private
28
+
29
+ ABSTRACT_FEATURE_BRANCH_POSITIVE_VALUES = ['true', 'on', 'yes']
30
+
31
+ raise 'Abstract feature branch conflicts with another Ruby library' if respond_to?(:abstract_feature_branch_environment_value)
32
+ def self.abstract_feature_branch_environment_value(feature_name)
33
+ downcased_env = Hash[ENV.map {|k, v| [k.downcase, v]}]
34
+ value = downcased_env["abstract_feature_branch_#{feature_name.to_s.downcase}"]
35
+ value && ABSTRACT_FEATURE_BRANCH_POSITIVE_VALUES.include?(value.downcase)
36
+ end
24
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abstract_feature_branch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Annas "Andy" Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-19 00:00:00.000000000 Z
11
+ date: 2013-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec