groupme-paddock 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.md +60 -0
- data/lib/paddock.rb +69 -0
- data/spec/paddock_spec.rb +211 -0
- metadata +70 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2010 Pivotal Labs
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Paddock
|
2
|
+
|
3
|
+
"...even Nedry knew better than to mess with the raptor fences."
|
4
|
+
|
5
|
+
Paddock is a feature switch system.
|
6
|
+
|
7
|
+
Define which features should be used in certain environments.
|
8
|
+
|
9
|
+
## Setup
|
10
|
+
|
11
|
+
Put this somewhere like: `config/initializers/paddock.rb`
|
12
|
+
|
13
|
+
include Paddock
|
14
|
+
|
15
|
+
Paddock(Rails.env) do
|
16
|
+
enable :phone_system, :in => [:development, :test]
|
17
|
+
enable :door_locks, :in => :development
|
18
|
+
enable :raptor_fences
|
19
|
+
disable :cryo_security
|
20
|
+
disable :tyranosaur_fences, :in => :production
|
21
|
+
end
|
22
|
+
|
23
|
+
You name it, we got it.
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
# Check if feature is enabled
|
28
|
+
if paddock(:perimeter_fence)
|
29
|
+
# do work
|
30
|
+
end
|
31
|
+
|
32
|
+
# Guard a block
|
33
|
+
paddock(:perimeter_fence) do
|
34
|
+
# do work
|
35
|
+
end
|
36
|
+
|
37
|
+
This is a unix system. I know this.
|
38
|
+
|
39
|
+
## Testing
|
40
|
+
|
41
|
+
This might need some work.
|
42
|
+
|
43
|
+
You can define which features are enabled in a test:
|
44
|
+
|
45
|
+
before(:each) do
|
46
|
+
Paddock.enable :feature_i_am_testing
|
47
|
+
end
|
48
|
+
|
49
|
+
You think that kind of automation is easy? Or cheap?
|
50
|
+
|
51
|
+
## Authors
|
52
|
+
|
53
|
+
We're not computer nerds. We prefer to be called "hackers."
|
54
|
+
|
55
|
+
* Pat Nakajima
|
56
|
+
* Brandon Keene
|
57
|
+
|
58
|
+
![system secured](http://ak2.static.dailymotion.com/static/video/024/680/8086420:jpeg_preview_large.jpg)
|
59
|
+
|
60
|
+
(c) Copyright 2010 Pivotal Labs, see LICENSE
|
data/lib/paddock.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module Paddock
|
2
|
+
class FeatureNotFound < StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
class Feature
|
6
|
+
def self.add(name, envs, disabled=false)
|
7
|
+
@features ||= {}
|
8
|
+
@features[name] = new(name, envs, disabled)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.get(name)
|
12
|
+
(@features ||= {})[name] || raise(Paddock::FeatureNotFound.new("#{name} is not a valid feature."))
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(name, envs, disabled)
|
16
|
+
@name, @envs, @disabled = name, envs, disabled
|
17
|
+
end
|
18
|
+
|
19
|
+
def enabled?
|
20
|
+
result = true if @envs == :all
|
21
|
+
result ||= Array(@envs).map { |env| env.to_sym }.include?(Paddock.environment.to_sym)
|
22
|
+
@disabled ? (!result) : result
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.environment=(env)
|
27
|
+
@environment = env
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.environment
|
31
|
+
@environment
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.features(&block)
|
35
|
+
@block = block
|
36
|
+
instance_eval(&block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.reset!
|
40
|
+
if block = @block
|
41
|
+
features(&block)
|
42
|
+
else
|
43
|
+
raise "No paddock block defined!"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.enable(name, options={})
|
48
|
+
Paddock::Feature.add(name, (options[:in] || :all))
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.disable(name, options={})
|
52
|
+
Paddock::Feature.add(name, (options[:in] || :all), :disabled)
|
53
|
+
end
|
54
|
+
|
55
|
+
def paddock(name)
|
56
|
+
enabled = Paddock::Feature.get(name).enabled?
|
57
|
+
enabled && yield if block_given?
|
58
|
+
enabled
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def Paddock(env, &block)
|
63
|
+
if block_given?
|
64
|
+
::Paddock.environment = env
|
65
|
+
::Paddock.features(&block)
|
66
|
+
else
|
67
|
+
::Paddock
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,211 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib paddock])
|
2
|
+
|
3
|
+
describe Paddock('development') do
|
4
|
+
include Paddock
|
5
|
+
|
6
|
+
it "has an environment" do
|
7
|
+
Paddock.environment = "development"
|
8
|
+
Paddock.environment.should == "development"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "raises a FeatureNotFound error when the feature don't not exist none" do
|
12
|
+
proc {
|
13
|
+
paddock(:raptor_fences)
|
14
|
+
}.should raise_error(Paddock::FeatureNotFound)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "defining enabled features" do
|
18
|
+
context "when not specifying environments" do
|
19
|
+
before(:each) do
|
20
|
+
Paddock('development') do
|
21
|
+
enable :perimeter_fence
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "runs the feature block always" do
|
26
|
+
called = false
|
27
|
+
paddock(:perimeter_fence) { called = true }
|
28
|
+
called.should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "always returns true on feature check" do
|
32
|
+
paddock(:perimeter_fence).should be_true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when specifying environment" do
|
37
|
+
before(:each) do
|
38
|
+
Paddock('development') do
|
39
|
+
enable :perimeter_fence, :in => :development
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when in appropriate environment" do
|
44
|
+
before(:each) do
|
45
|
+
Paddock.environment = 'development'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "runs the feature block" do
|
49
|
+
called = false
|
50
|
+
paddock(:perimeter_fence) { called = true }
|
51
|
+
called.should be_true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns true from the feature check" do
|
55
|
+
paddock(:perimeter_fence).should be_true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "is indifferent to strings/symbols" do
|
59
|
+
Paddock('development') do
|
60
|
+
enable :perimeter_fence, :in => 'development'
|
61
|
+
end
|
62
|
+
|
63
|
+
called = false
|
64
|
+
paddock(:perimeter_fence) { called = true }
|
65
|
+
called.should be_true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when specifying multiple environments" do
|
71
|
+
before(:each) do
|
72
|
+
Paddock('development') do
|
73
|
+
enable :perimeter_fence, :in => [:development, :test]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when in appropriate environment" do
|
78
|
+
before(:each) do
|
79
|
+
Paddock.environment = 'development'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "runs the feature block" do
|
83
|
+
called = false
|
84
|
+
paddock(:perimeter_fence) { called = true }
|
85
|
+
called.should be_true
|
86
|
+
end
|
87
|
+
|
88
|
+
it "returns true from the feature check" do
|
89
|
+
paddock(:perimeter_fence).should be_true
|
90
|
+
end
|
91
|
+
|
92
|
+
it "is indifferent to strings/symbols" do
|
93
|
+
Paddock('development') do
|
94
|
+
enable :perimeter_fence, :in => %w[development test]
|
95
|
+
end
|
96
|
+
|
97
|
+
called = false
|
98
|
+
paddock(:perimeter_fence) { called = true }
|
99
|
+
called.should be_true
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "when not in appropriate environment" do
|
104
|
+
before(:each) do
|
105
|
+
Paddock.environment = 'production'
|
106
|
+
end
|
107
|
+
|
108
|
+
it "does not run the feature block when not in an appropriate environment" do
|
109
|
+
called = false
|
110
|
+
paddock(:perimeter_fence) { called = true }
|
111
|
+
called.should be_false
|
112
|
+
end
|
113
|
+
|
114
|
+
it "returns false from the feature check" do
|
115
|
+
paddock(:perimeter_fence).should be_false
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "disabling features" do
|
122
|
+
before(:each) do
|
123
|
+
Paddock('development') do
|
124
|
+
disable :perimeter_fence
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
it "does not run the feature block when not in an appropriate environment" do
|
129
|
+
called = false
|
130
|
+
paddock(:perimeter_fence) { called = true }
|
131
|
+
called.should be_false
|
132
|
+
end
|
133
|
+
|
134
|
+
it "returns false from the feature check" do
|
135
|
+
paddock(:perimeter_fence).should be_false
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "disabling features in certain environments" do
|
140
|
+
before(:each) do
|
141
|
+
Paddock('production') do
|
142
|
+
disable :perimeter_fence, :in => :production
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it "does not run the feature block when not in an appropriate environment" do
|
147
|
+
called = false
|
148
|
+
paddock(:perimeter_fence) { called = true }
|
149
|
+
called.should be_false
|
150
|
+
end
|
151
|
+
|
152
|
+
it "returns false from the feature check" do
|
153
|
+
paddock(:perimeter_fence).should be_false
|
154
|
+
end
|
155
|
+
|
156
|
+
it "is indifferent to strings/symbols" do
|
157
|
+
Paddock('development') do
|
158
|
+
disable :perimeter_fence, :in => 'production'
|
159
|
+
end
|
160
|
+
|
161
|
+
called = false
|
162
|
+
paddock(:perimeter_fence) { called = true }
|
163
|
+
called.should be_true
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "using disabled features in different environment" do
|
168
|
+
before(:each) do
|
169
|
+
Paddock('development') do
|
170
|
+
disable :perimeter_fence, :in => :production
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
it "does not run the feature block when not in an appropriate environment" do
|
175
|
+
called = false
|
176
|
+
paddock(:perimeter_fence) { called = true }
|
177
|
+
called.should be_true
|
178
|
+
end
|
179
|
+
|
180
|
+
it "returns false from the feature check" do
|
181
|
+
paddock(:perimeter_fence).should be_true
|
182
|
+
end
|
183
|
+
|
184
|
+
it "is indifferent to strings/symbols" do
|
185
|
+
Paddock('development') do
|
186
|
+
disable :perimeter_fence, :in => %w[production other]
|
187
|
+
end
|
188
|
+
|
189
|
+
called = false
|
190
|
+
paddock(:perimeter_fence) { called = true }
|
191
|
+
called.should be_true
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "resetting changes" do
|
196
|
+
before(:each) do
|
197
|
+
Paddock('development') do
|
198
|
+
disable :disabled_feature
|
199
|
+
enable :enabled_feature
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
it "restores original feature behavior" do
|
204
|
+
Paddock.disable :enabled_feature
|
205
|
+
paddock(:enabled_feature).should be_false
|
206
|
+
|
207
|
+
Paddock.reset!
|
208
|
+
paddock(:enabled_feature).should be_true
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: groupme-paddock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Pat Nakajima & Brandon Keene
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-03-05 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email: nyc+github@pivotallabs.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- LICENSE
|
32
|
+
- README.md
|
33
|
+
- lib/paddock.rb
|
34
|
+
- spec/paddock_spec.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/groupme/paddock
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
hash: 3
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
version: "0"
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.7
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Paddock is an environment-based feature switch system.
|
69
|
+
test_files: []
|
70
|
+
|