feature_definitions 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,7 +2,6 @@ source "http://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
- gem 'lazy_const', '~> 0.1.3'
6
5
 
7
6
  # Add dependencies to develop your gem here.
8
7
  # Include everything needed to run rake, tests, features, etc.
data/README.rdoc CHANGED
@@ -37,6 +37,12 @@ app/elsewhere.rb
37
37
  # else noop
38
38
  end
39
39
 
40
+ def some_other_method
41
+ Features.AWESOME do
42
+ # declarative form!
43
+ end
44
+ end
45
+
40
46
  === Rails (and define_feature helper)
41
47
  Rails is *NOT* required, but this is how you would use this gem with Rails.
42
48
 
@@ -59,6 +65,10 @@ app/views/some/view.erb.html:
59
65
  <% Features.AWESOME.enabled? do %>
60
66
  You have awesome blocks enabled!
61
67
  <% end %>
68
+ <% Features.AWESOME do %>
69
+ Declarative feature blocks!
70
+ <% end %>
71
+
62
72
 
63
73
  == Contributing to feature_definitions
64
74
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "feature_definitions"
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
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-03-19"
12
+ s.date = "2013-03-20"
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 = [
@@ -40,14 +40,12 @@ Gem::Specification.new do |s|
40
40
  s.specification_version = 3
41
41
 
42
42
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
- s.add_runtime_dependency(%q<lazy_const>, ["~> 0.1.3"])
44
43
  s.add_development_dependency(%q<minitest>, [">= 0"])
45
44
  s.add_development_dependency(%q<bundler>, [">= 0"])
46
45
  s.add_development_dependency(%q<rake>, [">= 0"])
47
46
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
47
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
49
48
  else
50
- s.add_dependency(%q<lazy_const>, ["~> 0.1.3"])
51
49
  s.add_dependency(%q<minitest>, [">= 0"])
52
50
  s.add_dependency(%q<bundler>, [">= 0"])
53
51
  s.add_dependency(%q<rake>, [">= 0"])
@@ -55,7 +53,6 @@ Gem::Specification.new do |s|
55
53
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
56
54
  end
57
55
  else
58
- s.add_dependency(%q<lazy_const>, ["~> 0.1.3"])
59
56
  s.add_dependency(%q<minitest>, [">= 0"])
60
57
  s.add_dependency(%q<bundler>, [">= 0"])
61
58
  s.add_dependency(%q<rake>, [">= 0"])
@@ -1,11 +1,15 @@
1
- require 'lazy_const'
2
-
3
1
  class FeatureDefinitions
4
- extend LazyConst
5
2
  attr_reader :test_proc
6
3
 
7
- def self.define_feature(name, &block)
8
- lazy_const(name) { new(&block) }
4
+ def self.define_feature(name, &feature_test_block)
5
+ feature = new(&feature_test_block)
6
+ meta_class = class << self; self end
7
+ meta_class.__send__(:define_method, name) do |&feature_impl_block|
8
+ if block_given?
9
+ feature.enabled?(&feature_impl_block)
10
+ end
11
+ feature
12
+ end
9
13
  end
10
14
 
11
15
  PASSTHROUGH = Proc.new { |arg| arg }
@@ -30,7 +34,9 @@ class FeatureDefinitions
30
34
 
31
35
  def enabled?(&block)
32
36
  test_proc.call(context).tap do |verdict|
33
- yield if verdict and block_given?
37
+ if verdict and block_given?
38
+ yield
39
+ end
34
40
  end
35
41
  end
36
42
  end
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'feature_definitions'
2
3
 
3
4
  class ConstFeatures < FeatureDefinitions
4
5
  ALWAYS_ENABLED_FEATURE = self.new { |context| true }
@@ -72,7 +73,7 @@ class TestFeatureDefaultBlock < MiniTest::Unit::TestCase
72
73
  @feature_class.context = false
73
74
  refute @feature_class.AWESOME.enabled?
74
75
  end
75
- def test_feature_toggle
76
+ def test_feature_toggles
76
77
  @feature_class.context = true
77
78
  assert @feature_class.AWESOME.enabled?
78
79
  @feature_class.context = false
@@ -87,3 +88,26 @@ class TestFeatureDefaultBlock < MiniTest::Unit::TestCase
87
88
  assert called
88
89
  end
89
90
  end
91
+
92
+ class TestDeclarativeFeatures < MiniTest::Unit::TestCase
93
+ def setup
94
+ @feature_class = Class.new(FeatureDefinitions) do
95
+ define_feature(:ENABLED_FEATURE) { |c| true }
96
+ define_feature(:DISABLED_FEATURE) { |c| false }
97
+ end
98
+ end
99
+ def test_declarative_feature_enabled
100
+ called = false
101
+ @feature_class.ENABLED_FEATURE do
102
+ called = true
103
+ end
104
+ assert called
105
+ end
106
+ def test_declarative_feature_disabled
107
+ called = false
108
+ @feature_class.DISABLED_FEATURE do
109
+ called = true
110
+ end
111
+ refute called
112
+ end
113
+ end
metadata CHANGED
@@ -2,31 +2,15 @@
2
2
  name: feature_definitions
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.3.1
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-19 00:00:00.000000000 Z
12
+ date: 2013-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- version_requirements: !ruby/object:Gem::Requirement
16
- none: false
17
- requirements:
18
- - - ~>
19
- - !ruby/object:Gem::Version
20
- version: 0.1.3
21
- type: :runtime
22
- name: lazy_const
23
- requirement: !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ~>
27
- - !ruby/object:Gem::Version
28
- version: 0.1.3
29
- prerelease: false
30
14
  - !ruby/object:Gem::Dependency
31
15
  version_requirements: !ruby/object:Gem::Requirement
32
16
  none: false
@@ -141,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
125
  - !ruby/object:Gem::Version
142
126
  segments:
143
127
  - 0
144
- hash: -4330562717910034088
128
+ hash: -2164482606995363912
145
129
  version: '0'
146
130
  required_rubygems_version: !ruby/object:Gem::Requirement
147
131
  none: false