feature_definitions 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +5 -2
- data/VERSION +1 -1
- data/feature_definitions.gemspec +61 -0
- data/lib/feature_definitions.rb +12 -6
- data/test/test_feature_definitions.rb +8 -0
- metadata +4 -3
data/README.rdoc
CHANGED
@@ -23,8 +23,11 @@ app/controller/application_controller.rb:
|
|
23
23
|
end
|
24
24
|
|
25
25
|
app/views/some/view.erb.html:
|
26
|
-
<% Features.AWESOME.enabled? %>
|
27
|
-
You have awesome enabled!
|
26
|
+
<% if Features.AWESOME.enabled? %>
|
27
|
+
You have the awesome feature enabled!
|
28
|
+
<% end %>
|
29
|
+
<% Features.AWESOME.enabled? do %>
|
30
|
+
You have awesome blocks enabled!
|
28
31
|
<% end %>
|
29
32
|
|
30
33
|
== Contributing to feature_definitions
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "feature_definitions"
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ryan Graham"]
|
12
|
+
s.date = "2013-03-19"
|
13
|
+
s.description = "Simple and flexible feature toggle defintion"
|
14
|
+
s.email = "r.m.graham@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"feature_definitions.gemspec",
|
27
|
+
"lib/feature_definitions.rb",
|
28
|
+
"test/helper.rb",
|
29
|
+
"test/test_feature_definitions.rb"
|
30
|
+
]
|
31
|
+
s.homepage = "http://github.com/rmg/feature_definitions"
|
32
|
+
s.licenses = ["MIT"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = "1.8.23"
|
35
|
+
s.summary = "Simple and flexible feature definition"
|
36
|
+
|
37
|
+
if s.respond_to? :specification_version then
|
38
|
+
s.specification_version = 3
|
39
|
+
|
40
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
41
|
+
s.add_runtime_dependency(%q<lazy_const>, [">= 0"])
|
42
|
+
s.add_development_dependency(%q<minitest>, [">= 0"])
|
43
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
44
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<lazy_const>, [">= 0"])
|
48
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
49
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
50
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
51
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
52
|
+
end
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<lazy_const>, [">= 0"])
|
55
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
57
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/lib/feature_definitions.rb
CHANGED
@@ -2,23 +2,29 @@ require 'lazy_const'
|
|
2
2
|
|
3
3
|
class FeatureDefinitions
|
4
4
|
extend LazyConst
|
5
|
+
attr_reader :opts, :test_proc
|
5
6
|
|
6
7
|
def self.define_feature(name, opts = {}, &block)
|
7
|
-
lazy_const(name){ new(opts,
|
8
|
+
lazy_const(name){ new(opts, block.to_proc) }
|
8
9
|
end
|
9
10
|
|
10
|
-
def initialize(opts
|
11
|
+
def initialize(opts, proc)
|
11
12
|
@opts = opts
|
12
|
-
@
|
13
|
+
@test_proc = proc
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.context=(context)
|
16
17
|
@@context = context
|
17
18
|
end
|
18
19
|
|
19
|
-
def
|
20
|
-
|
21
|
-
@proc.call(*args)
|
20
|
+
def context
|
21
|
+
@@context
|
22
22
|
end
|
23
23
|
|
24
|
+
def enabled?(&block)
|
25
|
+
args = opts[:using].map { |sym| context.public_send(sym) }
|
26
|
+
test_proc.call(*args).tap do |verdict|
|
27
|
+
yield if block_given? and verdict
|
28
|
+
end
|
29
|
+
end
|
24
30
|
end
|
@@ -21,4 +21,12 @@ class TestFeatureDefinitions < MiniTest::Unit::TestCase
|
|
21
21
|
Features.context = OpenStruct.new(is_awesome?: false)
|
22
22
|
refute Features.AWESOME.enabled?
|
23
23
|
end
|
24
|
+
def test_feature_toggle_with_block
|
25
|
+
Features.context = OpenStruct.new(is_awesome?: true)
|
26
|
+
called = false
|
27
|
+
Features.AWESOME.enabled? do
|
28
|
+
called = true
|
29
|
+
end
|
30
|
+
assert called
|
31
|
+
end
|
24
32
|
end
|
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.2.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-03-
|
12
|
+
date: 2013-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- README.rdoc
|
106
106
|
- Rakefile
|
107
107
|
- VERSION
|
108
|
+
- feature_definitions.gemspec
|
108
109
|
- lib/feature_definitions.rb
|
109
110
|
- test/helper.rb
|
110
111
|
- test/test_feature_definitions.rb
|
@@ -122,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
123
|
- !ruby/object:Gem::Version
|
123
124
|
segments:
|
124
125
|
- 0
|
125
|
-
hash: -
|
126
|
+
hash: -3803903361324450403
|
126
127
|
version: '0'
|
127
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
129
|
none: false
|