corral 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ![Corral](http://cl.ly/image/0Q1E2Z451v2a/corral.jpg)
4
4
 
5
- Use Corral to hide certain features in your application.
5
+ Use Corral to disable certain features in your application.
6
6
 
7
7
  ### Is it any good?
8
8
 
@@ -23,9 +23,9 @@ Put this somewhere like: `config/initializers/corral.rb`
23
23
  include Corral
24
24
 
25
25
  corral do
26
- hide :torpedoes, when: -> { true }
27
- hide :fun_and_games, when: -> { Rails.env.production? }
28
- hide :cupcakes, if: ->(person) { person == "Bryan" }
26
+ disable :torpedoes, when: -> { true }
27
+ disable :fun_and_games, when: -> { Rails.env.production? }
28
+ disable :cupcakes, if: ->(person) { person == "Bryan" }
29
29
  end
30
30
  ```
31
31
 
data/corral.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Corral::VERSION
9
9
  spec.authors = ["Bryan Woods"]
10
10
  spec.email = ["bryanwoods4e@gmail.com"]
11
- spec.summary = "Use Corral to hide certain features in your application."
11
+ spec.summary = "Use Corral to disable certain features in your application."
12
12
  spec.homepage = "http://github.com/bryanwoods/corral"
13
13
  spec.license = "MIT"
14
14
 
@@ -1,3 +1,3 @@
1
1
  module Corral
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/corral.rb CHANGED
@@ -2,7 +2,7 @@ require "corral/version"
2
2
 
3
3
  module Corral
4
4
  class Feature
5
- attr_accessor :feature, :condition, :disabled
5
+ attr_reader :condition
6
6
 
7
7
  def initialize(feature, condition, disabled)
8
8
  @feature = feature
@@ -39,7 +39,7 @@ module Corral
39
39
  end
40
40
  end
41
41
 
42
- def hide(feature, options = {})
42
+ def disable(feature, options = {})
43
43
  condition = options[:when] || options[:if]
44
44
 
45
45
  if condition && !condition.respond_to?(:call)
@@ -0,0 +1,216 @@
1
+ require 'spec_helper'
2
+
3
+ describe Corral do
4
+ include Corral
5
+
6
+ describe "#corral" do
7
+ context "when given a block" do
8
+ it "yields the block" do
9
+ corral { :cool_feature }.should == :cool_feature
10
+ end
11
+
12
+ context "when given known features" do
13
+ context "when given callable 'when' or 'if' options" do
14
+ context "when the conditions are true" do
15
+ before do
16
+ corral do
17
+ disable :everything_free, when: -> { true }
18
+ disable :torpedoes, if: -> { true }
19
+ end
20
+ end
21
+
22
+ it "is disabled" do
23
+ disabled?(:everything_free).should be_true
24
+ disabled?(:torpedoes).should be_true
25
+ end
26
+ end
27
+
28
+ context "when the conditions are not true" do
29
+ before do
30
+ corral do
31
+ disable :payment_button, when: -> { 1 > 2 }
32
+ disable :sunshine, if: -> { true == false }
33
+ end
34
+ end
35
+
36
+ it "is enabled" do
37
+ enabled?(:payment_button).should be_true
38
+ enabled?(:sunshine).should be_true
39
+ end
40
+ end
41
+ end
42
+
43
+ context "when the 'when' or 'if' condition is not callable" do
44
+ it "raises an exception" do
45
+ expect do
46
+ corral do
47
+ disable :the_sandwich, if: 1.odd?
48
+ end
49
+ end.to raise_error(RuntimeError)
50
+ end
51
+ end
52
+
53
+ context "when not given a 'when' or 'if' condition" do
54
+ it "is disabled" do
55
+ corral { :my_feature }
56
+ disabled?(:my_feature).should be_true
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ context "when not given a block" do
63
+ it "raises an error" do
64
+ expect { corral }.to raise_error(ArgumentError)
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "#enabled?" do
70
+ context "when the given feature exists" do
71
+ context "when the feature has no 'when' condition" do
72
+ before do
73
+ corral do
74
+ disable :torpedoes
75
+ end
76
+ end
77
+
78
+ it "is false" do
79
+ enabled?(:torpedoes).should be_false
80
+ end
81
+ end
82
+
83
+ context "when the feature has a 'when' condition" do
84
+ context "when the 'when' condition is true" do
85
+ before do
86
+ corral do
87
+ disable :torpedoes, when: -> { true }
88
+ end
89
+ end
90
+
91
+ it "is false" do
92
+ enabled?(:torpedoes).should be_false
93
+ end
94
+ end
95
+
96
+ context "when the 'when' condition is false" do
97
+ before do
98
+ corral do
99
+ disable :cupcakes, when: -> { false }
100
+ end
101
+ end
102
+
103
+ it "is true" do
104
+ enabled?(:cupcakes).should be_true
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ context "when the given feature does not exist" do
111
+ it "is false" do
112
+ enabled?(:unknown_feature).should be_false
113
+ end
114
+ end
115
+
116
+ context "when given an argument to test against" do
117
+ context "when the result is true" do
118
+ before do
119
+ corral do
120
+ disable :cupcakes, if: ->(person) { person == "Bryan" }
121
+ end
122
+ end
123
+
124
+ it "is false" do
125
+ enabled?(:cupcakes, "Bryan").should be_false
126
+ end
127
+ end
128
+
129
+ context "when the result is not true" do
130
+ before do
131
+ corral do
132
+ disable :cupcakes, if: ->(person) { person == "Bryan" }
133
+ end
134
+ end
135
+
136
+ it "is false" do
137
+ enabled?(:cupcakes, "George").should be_true
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ describe "#disabled?" do
144
+ context "when the given feature exists" do
145
+ context "when the feature has no 'when' condition" do
146
+ before do
147
+ corral do
148
+ disable :torpedoes
149
+ end
150
+ end
151
+
152
+ it "is true" do
153
+ disabled?(:torpedoes).should be_true
154
+ end
155
+ end
156
+
157
+ context "when the feature has a 'when' condition" do
158
+ context "when the 'when' condition is true" do
159
+ before do
160
+ corral do
161
+ disable :torpedoes, when: -> { true }
162
+ end
163
+ end
164
+
165
+ it "is true" do
166
+ disabled?(:torpedoes).should be_true
167
+ end
168
+ end
169
+
170
+ context "when the 'when' condition is false" do
171
+ before do
172
+ corral do
173
+ disable :cupcakes, when: -> { false }
174
+ end
175
+ end
176
+
177
+ it "is false" do
178
+ disabled?(:cupcakes).should be_false
179
+ end
180
+ end
181
+ end
182
+ end
183
+
184
+ context "when the given feature does not exist" do
185
+ it "is true" do
186
+ disabled?(:unknown_feature).should be_true
187
+ end
188
+ end
189
+ end
190
+
191
+ context "when given an argument to test against" do
192
+ context "when the result is true" do
193
+ before do
194
+ corral do
195
+ disable :cupcakes, if: ->(person) { person == "Bryan" }
196
+ end
197
+ end
198
+
199
+ it "is true" do
200
+ disabled?(:cupcakes, "Bryan").should be_true
201
+ end
202
+ end
203
+
204
+ context "when the result is not true" do
205
+ before do
206
+ corral do
207
+ disable :cupcakes, if: ->(person) { person == "Bryan" }
208
+ end
209
+ end
210
+
211
+ it "is false" do
212
+ disabled?(:cupcakes, "George").should be_false
213
+ end
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'corral'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corral
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -51,6 +51,7 @@ extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
53
  - .gitignore
54
+ - .rspec
54
55
  - Gemfile
55
56
  - LICENSE.txt
56
57
  - README.md
@@ -58,6 +59,8 @@ files:
58
59
  - corral.gemspec
59
60
  - lib/corral.rb
60
61
  - lib/corral/version.rb
62
+ - spec/corral_spec.rb
63
+ - spec/spec_helper.rb
61
64
  homepage: http://github.com/bryanwoods/corral
62
65
  licenses:
63
66
  - MIT
@@ -82,6 +85,8 @@ rubyforge_project:
82
85
  rubygems_version: 1.8.23
83
86
  signing_key:
84
87
  specification_version: 3
85
- summary: Use Corral to hide certain features in your application.
86
- test_files: []
88
+ summary: Use Corral to disable certain features in your application.
89
+ test_files:
90
+ - spec/corral_spec.rb
91
+ - spec/spec_helper.rb
87
92
  has_rdoc: