feature_definitions 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +17 -4
- data/VERSION +1 -1
- data/feature_definitions.gemspec +2 -2
- data/lib/feature_definitions.rb +11 -3
- data/test/test_feature_definitions.rb +27 -0
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -5,15 +5,22 @@
|
|
5
5
|
A minimal useful feature toggle mechanism.
|
6
6
|
|
7
7
|
Thanks to Travis-CI, tested on:
|
8
|
-
- "1.8.7"
|
8
|
+
- "1.8.7" ***
|
9
9
|
- "1.9.2"
|
10
10
|
- "1.9.3"
|
11
11
|
- "2.0.0"
|
12
|
-
- jruby-18mode # JRuby in 1.8 mode
|
12
|
+
- jruby-18mode # JRuby in 1.8 mode ***
|
13
13
|
- jruby-19mode # JRuby in 1.9 mode
|
14
|
-
- rbx-18mode
|
14
|
+
- rbx-18mode ***
|
15
15
|
- rbx-19mode
|
16
16
|
|
17
|
+
==== Note on 1.8
|
18
|
+
|
19
|
+
I've given up trying to find a cross version way of using instance_eval/exec
|
20
|
+
to give a nicer syntax to feature evaluation blocks, but it's just not
|
21
|
+
working out. If you're using 1.8, you're block will just have to take the
|
22
|
+
context as an argument.
|
23
|
+
|
17
24
|
== Installation
|
18
25
|
|
19
26
|
gem 'feature_definitions'
|
@@ -24,6 +31,8 @@ Thanks to Travis-CI, tested on:
|
|
24
31
|
lib/features.rb:
|
25
32
|
class Features < FeatureDefinitions
|
26
33
|
AWESOME = self.new {|flags| flags.is_awesome? }
|
34
|
+
# > 1.8 only, evaluated in context of Features.context
|
35
|
+
AWESOME = self.new { is_awesome? }
|
27
36
|
end
|
28
37
|
|
29
38
|
app/main.rb:
|
@@ -51,6 +60,10 @@ app/model/features.rb:
|
|
51
60
|
define_feature :AWESOME do |user|
|
52
61
|
user.is_awesome?
|
53
62
|
end
|
63
|
+
# > 1.8 only, evaluated in context of Features.context
|
64
|
+
define_feature :AWESOMER do
|
65
|
+
is_awesome?
|
66
|
+
end
|
54
67
|
end
|
55
68
|
|
56
69
|
app/controller/application_controller.rb:
|
@@ -65,7 +78,7 @@ app/views/some/view.erb.html:
|
|
65
78
|
<% Features.AWESOME.enabled? do %>
|
66
79
|
You have awesome blocks enabled!
|
67
80
|
<% end %>
|
68
|
-
<% Features.
|
81
|
+
<% Features.AWESOMER do %>
|
69
82
|
Declarative feature blocks!
|
70
83
|
<% end %>
|
71
84
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/feature_definitions.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "feature_definitions"
|
8
|
-
s.version = "0.
|
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 = ["Ryan Graham"]
|
12
|
-
s.date = "2013-04-
|
12
|
+
s.date = "2013-04-12"
|
13
13
|
s.description = "Simple and flexible feature toggle defintion"
|
14
14
|
s.email = "r.m.graham@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/feature_definitions.rb
CHANGED
@@ -12,13 +12,13 @@ class FeatureDefinitions
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
IDENTITY = Proc.new { |arg| arg }
|
16
16
|
|
17
17
|
def initialize(&block)
|
18
18
|
if block_given?
|
19
19
|
@test_proc = block.to_proc
|
20
20
|
else
|
21
|
-
@test_proc =
|
21
|
+
@test_proc = IDENTITY
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -31,10 +31,18 @@ class FeatureDefinitions
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def enabled?(&block)
|
34
|
-
|
34
|
+
eval_test_proc.tap do |verdict|
|
35
35
|
if verdict and block_given?
|
36
36
|
yield
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
def eval_test_proc
|
42
|
+
if test_proc.arity == 0
|
43
|
+
context.instance_exec(&test_proc)
|
44
|
+
else
|
45
|
+
test_proc.call(context)
|
46
|
+
end
|
47
|
+
end
|
40
48
|
end
|
@@ -89,6 +89,33 @@ class TestFeatureDefaultBlock < MiniTest::Unit::TestCase
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
# 1.8 instance_eval makes me sad :-(
|
93
|
+
if RUBY_VERSION.to_i > 1 or RUBY_VERSION.split('.')[1].to_i > 8
|
94
|
+
class TestFeatureEvalBlock < MiniTest::Unit::TestCase
|
95
|
+
def setup
|
96
|
+
@feature_class = Class.new(FeatureDefinitions) do
|
97
|
+
define_feature :AWESOME do
|
98
|
+
some_instance_method
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
def test_feature_enabled
|
103
|
+
@feature_class.context = OpenStruct.new(:some_instance_method => true)
|
104
|
+
assert @feature_class.AWESOME.enabled?
|
105
|
+
end
|
106
|
+
def test_feature_disabled
|
107
|
+
@feature_class.context = OpenStruct.new(:some_instance_method => false)
|
108
|
+
refute @feature_class.AWESOME.enabled?
|
109
|
+
end
|
110
|
+
def test_feature_toggling
|
111
|
+
@feature_class.context = OpenStruct.new(:some_instance_method => true)
|
112
|
+
assert @feature_class.AWESOME.enabled?
|
113
|
+
@feature_class.context = OpenStruct.new(:some_instance_method => false)
|
114
|
+
refute @feature_class.AWESOME.enabled?
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
92
119
|
class TestDeclarativeFeatures < MiniTest::Unit::TestCase
|
93
120
|
def setup
|
94
121
|
@feature_class = Class.new(FeatureDefinitions) do
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: feature_definitions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.4.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ryan Graham
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
segments:
|
127
127
|
- 0
|
128
|
-
hash:
|
128
|
+
hash: -230299105052606753
|
129
129
|
version: '0'
|
130
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
131
|
none: false
|