ball_gag 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ball_gag (0.0.4)
4
+ ball_gag (0.0.6)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -4,6 +4,7 @@ require 'ball_gag/engine'
4
4
  require 'ball_gag/errors'
5
5
  require 'ball_gag/cloak'
6
6
  require 'ball_gag/bowling_ball'
7
+ require 'ball_gag/disable'
7
8
 
8
9
  begin
9
10
  require 'ball_gag/validations'
@@ -40,6 +40,25 @@ module BowlingBall
40
40
  BallGag.only_validate_on_attribute_changed = bool
41
41
  end
42
42
 
43
+ def enabled?
44
+ BallGag.enabled?
45
+ end
46
+
47
+ def enable! &block
48
+ if block
49
+ BallGag.enable! &block
50
+ else
51
+ BallGag.enable!
52
+ end
53
+ end
54
+
55
+ def disable! &block
56
+ if block
57
+ BallGag.disable! &block
58
+ else
59
+ BallGag.disable!
60
+ end
61
+ end
43
62
  end
44
63
  end
45
64
 
@@ -0,0 +1,37 @@
1
+ module BallGag
2
+ module Disable
3
+ module ClassMethods
4
+ def enable!
5
+ old_enabled = @enabled
6
+ @enabled = true
7
+ if block_given?
8
+ begin
9
+ yield
10
+ ensure
11
+ @enabled = old_enabled
12
+ end
13
+ end
14
+ end
15
+
16
+ def disable!
17
+ old_enabled = @enabled
18
+ @enabled = false
19
+ if block_given?
20
+ begin
21
+ yield
22
+ ensure
23
+ @enabled = old_enabled
24
+ end
25
+ end
26
+ end
27
+
28
+ def enabled?
29
+ return @enabled if @enabled == false
30
+ @enabled || true
31
+ end
32
+ end
33
+ end
34
+
35
+ extend Disable::ClassMethods
36
+ end
37
+
@@ -81,6 +81,8 @@ module BallGag
81
81
  attributes.each do |attr|
82
82
  @gagged_attributes_methods.send(:define_method,
83
83
  gagged_attribute_negative_interpellation_name(attr)) do
84
+ return true unless BallGag.enabled?
85
+
84
86
  @gagged_attribute_results ||= {}
85
87
 
86
88
  # Is the attribute dirty?
@@ -1,4 +1,4 @@
1
1
  module BallGag
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
4
4
 
@@ -8,6 +8,7 @@ describe 'BallGag cloaking' do
8
8
  BallGag.verb = nil
9
9
  BallGag.preterite = nil
10
10
  BallGag.only_validate_on_attribute_changed = false
11
+ BallGag.enable!
11
12
  end
12
13
 
13
14
  after do
@@ -153,6 +154,34 @@ describe 'BallGag cloaking' do
153
154
  BowlingBall.only_validate_on_attribute_changed = true
154
155
  BallGag.only_validate_on_attribute_changed.should be_true
155
156
  end
157
+
158
+ it 'should enable' do
159
+ BowlingBall.enable!
160
+ BowlingBall.should be_enabled
161
+ end
162
+
163
+ it 'should disable' do
164
+ BowlingBall.disable!
165
+ BowlingBall.should_not be_enabled
166
+ end
167
+
168
+ it 'should report enabled?' do
169
+ BowlingBall.should be_enabled
170
+ end
171
+
172
+ it 'should use block provided to enable!' do
173
+ BowlingBall.disable!
174
+ BowlingBall.enable! do
175
+ BowlingBall.should be_enabled
176
+ end
177
+ end
178
+
179
+ it 'should use block provided to disable!' do
180
+ BowlingBall.enable!
181
+ BowlingBall.disable! do
182
+ BowlingBall.should_not be_enabled
183
+ end
184
+ end
156
185
  end
157
186
  end
158
187
 
@@ -5,6 +5,7 @@ describe ExampleModel do
5
5
  BallGag.engine = nil
6
6
  BallGag.verb = nil
7
7
  BallGag.preterite = nil
8
+ BallGag.enable!
8
9
  ExampleModel.clear_gagged_attributes
9
10
  end
10
11
 
@@ -278,7 +279,7 @@ describe ExampleModel do
278
279
 
279
280
  describe 'error cases' do
280
281
  context 'when gagged with no callable and no engine is configured' do
281
- it 'should raise when gag is checekd' do
282
+ it 'should raise when gag is checked' do
282
283
  ExampleModel.gag :words
283
284
 
284
285
  -> { ExampleModel.new.words_gagged? }.
@@ -301,5 +302,69 @@ describe ExampleModel do
301
302
  end
302
303
  end
303
304
  end
305
+
306
+ describe 'global enable/disable' do
307
+ it 'should respond to enable!' do
308
+ BallGag.should respond_to(:enable!)
309
+ end
310
+
311
+ it 'should respond to disable!' do
312
+ BallGag.should respond_to(:disable!)
313
+ end
314
+
315
+ it 'should respond to enabled?' do
316
+ BallGag.should respond_to(:enabled?)
317
+ end
318
+
319
+ it 'should initially be enabled' do
320
+ BallGag.should be_enabled
321
+ end
322
+
323
+ it 'should be disabled after disable!' do
324
+ BallGag.disable!
325
+ BallGag.should_not be_enabled
326
+ end
327
+
328
+ context 'when disabled' do
329
+ before(:each) do
330
+ BallGag.disable!
331
+ end
332
+
333
+ it 'should not report attribute as gagged' do
334
+ ExampleModel.gag :words, ->(*) { false }
335
+ ExampleModel.new.words_gagged?.should be_false
336
+ end
337
+
338
+ it 'should not call callable' do
339
+ callable = ->(*) { false }
340
+ ExampleModel.gag :words, callable
341
+ callable.should_not_receive(:call)
342
+ ExampleModel.new.words_gagged?
343
+ end
344
+ end
345
+
346
+ context 'when disabled with a block' do
347
+ it 'should not report attribute as gagged' do
348
+ ExampleModel.gag :words, ->(*) { false }
349
+ instance = ExampleModel.new
350
+ BallGag.disable! do
351
+ instance.words_gagged?.should be_false
352
+ end
353
+ instance.words_gagged?.should be_true
354
+ end
355
+ end
356
+
357
+ context 'when enabled with a block' do
358
+ it 'should call callable' do
359
+ ExampleModel.gag :words, ->(*) { false }
360
+ instance = ExampleModel.new
361
+ BallGag.disable!
362
+ BallGag.enable! do
363
+ instance.words_gagged?.should be_true
364
+ end
365
+ instance.words_gagged?.should be_false
366
+ end
367
+ end
368
+ end
304
369
  end
305
370
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ball_gag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-13 00:00:00.000000000 Z
12
+ date: 2012-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70215291665000 !ruby/object:Gem::Requirement
16
+ requirement: &70135835371000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70215291665000
24
+ version_requirements: *70135835371000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70215291664360 !ruby/object:Gem::Requirement
27
+ requirement: &70135835370140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70215291664360
35
+ version_requirements: *70135835370140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activemodel
38
- requirement: &70215291663520 !ruby/object:Gem::Requirement
38
+ requirement: &70135835369160 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70215291663520
46
+ version_requirements: *70135835369160
47
47
  description: Validate user input using pluggable back-ends
48
48
  email:
49
49
  - duncan@dweebd.com
@@ -62,6 +62,7 @@ files:
62
62
  - lib/ball_gag.rb
63
63
  - lib/ball_gag/bowling_ball.rb
64
64
  - lib/ball_gag/cloak.rb
65
+ - lib/ball_gag/disable.rb
65
66
  - lib/ball_gag/engine.rb
66
67
  - lib/ball_gag/errors.rb
67
68
  - lib/ball_gag/gag.rb