ball_gag 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ball_gag (0.0.2)
4
+ ball_gag (0.0.4)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/ball_gag.gemspec CHANGED
@@ -20,4 +20,6 @@ Gem::Specification.new do |s|
20
20
 
21
21
  # specify any dependencies here; for example:
22
22
  s.add_development_dependency 'rspec'
23
+ s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'activemodel'
23
25
  end
@@ -24,13 +24,13 @@ module BallGag
24
24
  end
25
25
 
26
26
  def preterite= preterite
27
- set_preterite preterite
28
27
  @preterite_negative = false
28
+ set_preterite preterite
29
29
  end
30
30
 
31
31
  def negative_preterite= preterite
32
- set_preterite preterite
33
32
  @preterite_negative = true
33
+ set_preterite preterite
34
34
  end
35
35
 
36
36
  def preterite_negative?
@@ -39,8 +39,10 @@ module BallGag
39
39
 
40
40
  private
41
41
  def set_preterite preterite
42
- undefine_old_preterite_validators @preterite
43
- define_preterite_validators preterite
42
+ if defined?(ActiveModel::EachValidator)
43
+ undefine_old_preterite_validators @preterite
44
+ define_preterite_validators preterite
45
+ end
44
46
 
45
47
  @preterite = preterite
46
48
  end
@@ -48,8 +50,10 @@ module BallGag
48
50
  def define_preterite_validators preterite
49
51
  return unless preterite
50
52
 
51
- Kernel.const_set(validator_name(preterite), Class.new(GaggedValidator))
52
- Kernel.const_set(not_validator_name(preterite), Class.new(NotGaggedValidator))
53
+ new_validators = [ Class.new(GaggedValidator), Class.new(NotGaggedValidator) ]
54
+ new_validators.reverse! if BallGag.preterite_negative?
55
+ Kernel.const_set(validator_name(preterite), new_validators[0])
56
+ Kernel.const_set(not_validator_name(preterite), new_validators[1])
53
57
  end
54
58
 
55
59
  def undefine_old_preterite_validators preterite
@@ -13,7 +13,9 @@ class GaggedValidator < ActiveModel::EachValidator
13
13
  end
14
14
 
15
15
  def default_message
16
- "is not #{BallGag.preterite}"
16
+ BallGag.preterite_negative? ?
17
+ "is #{BallGag.preterite}" :
18
+ "is not #{BallGag.preterite}"
17
19
  end
18
20
 
19
21
  def neg_method_name attribute
@@ -34,7 +36,9 @@ class NotGaggedValidator < GaggedValidator
34
36
  end
35
37
 
36
38
  def default_message
37
- "is #{BallGag.preterite}"
39
+ BallGag.preterite_negative? ?
40
+ "is not #{BallGag.preterite}" :
41
+ "is #{BallGag.preterite}"
38
42
  end
39
43
  end
40
44
 
@@ -1,4 +1,4 @@
1
1
  module BallGag
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
4
4
 
data/spec/cloak_spec.rb CHANGED
@@ -105,14 +105,23 @@ describe 'BallGag cloaking' do
105
105
  instance.errors[:words].should include 'is censored'
106
106
  end
107
107
 
108
- specify 'negative preterite should not alter meaning of extant validators' do
108
+ specify 'negative preterite should create inverse validator' do
109
+ BallGag.negative_preterite = 'acceptable'
110
+ ExampleActiveModel.gag(:words) { |words| false }
111
+ ExampleActiveModel.validates :words, acceptable: true
112
+ instance = ExampleActiveModel.new
113
+ instance.valid?
114
+ instance.errors[:words].should include 'is not acceptable'
115
+ end
116
+
117
+ specify 'negative preterite should alter message but not meaning of extant validators' do
109
118
  BallGag.negative_preterite = 'acceptable'
110
119
 
111
120
  ExampleActiveModel.gag(:words) { |words| false }
112
121
  ExampleActiveModel.validates :words, not_gagged: true
113
122
  instance = ExampleActiveModel.new
114
123
  instance.valid?
115
- instance.errors[:words].should include 'is acceptable'
124
+ instance.errors[:words].should include 'is not acceptable'
116
125
  end
117
126
  end
118
127
 
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.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70253003020680 !ruby/object:Gem::Requirement
16
+ requirement: &70274670743440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,29 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70253003020680
24
+ version_requirements: *70274670743440
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70274670742620 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70274670742620
36
+ - !ruby/object:Gem::Dependency
37
+ name: activemodel
38
+ requirement: &70274670741600 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70274670741600
25
47
  description: Validate user input using pluggable back-ends
26
48
  email:
27
49
  - duncan@dweebd.com