validates_decency_of 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -10,7 +10,8 @@ begin
10
10
  gem.email = "seamus@abshere.net"
11
11
  gem.homepage = "http://github.com/seamusabshere/validates_decency_of"
12
12
  gem.authors = ["Seamus Abshere"]
13
- gem.add_dependency 'activerecord', '~>2.3.4'
13
+ gem.add_dependency 'activesupport', '>=2.3.4'
14
+ gem.add_dependency 'activerecord', '>=2.3.4'
14
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
16
  end
16
17
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.0
1
+ 1.5.1
@@ -1,3 +1,6 @@
1
+ require 'active_support'
2
+ require 'active_record'
3
+
1
4
  # Uses George Carlin's list of "seven dirty words" to "check for decency" (ahem)
2
5
  # http://en.wikipedia.org/wiki/Seven_dirty_words
3
6
  # Future versions will support adding/removing from this list
@@ -10,7 +13,6 @@
10
13
  # Configuration Options
11
14
  #
12
15
  # [<tt>:message</tt>] A custom error message (default is: "is invalid")
13
- #
14
16
  module ValidatesDecencyOf
15
17
  INDECENT_WORDS = %w(shit piss fuck cunt cocksucker motherfucker tits)
16
18
  def self.indecent?(str)
@@ -18,14 +20,36 @@ module ValidatesDecencyOf
18
20
  INDECENT_WORDS.any? { |c| essence.include? c }
19
21
  end
20
22
 
21
- def validates_decency_of(*attribute_names)
22
- options = { :message => 'is invalid' }
23
- options.merge!(attribute_names.pop) if attribute_names.last.kind_of?(Hash)
24
- options.merge! :on => :save
25
- validates_each(attribute_names, options) do |record, attribute_name, value|
26
- record.errors.add attribute_name, options[:message] if ValidatesDecencyOf.indecent? value
23
+ if ActiveRecord::VERSION::MAJOR == 2
24
+ module ClassMethods
25
+ def validates_decency_of(*attribute_names)
26
+ options = { :message => 'is indecent' }
27
+ options.merge!(attribute_names.pop) if attribute_names.last.kind_of?(Hash)
28
+ options.merge! :on => :save
29
+ validates_each(attribute_names, options) do |record, attribute_name, value|
30
+ record.errors.add attribute_name, options[:message] if ValidatesDecencyOf.indecent? value
31
+ end
32
+ end
33
+ end
34
+ elsif ActiveRecord::VERSION::MAJOR == 3
35
+ class DecencyValidator < ActiveModel::EachValidator
36
+ def validate(record)
37
+ message = options[:message] || 'is indecent'
38
+ attributes.each do |name|
39
+ if ValidatesDecencyOf.indecent? record.send(name)
40
+ record.errors.add name, message
41
+ end
42
+ end
43
+ end
44
+ end
45
+ module ClassMethods
46
+ def validates_decency_of(*attr_names)
47
+ validates_with DecencyValidator, _merge_attributes(attr_names)
48
+ end
27
49
  end
50
+ else
51
+ raise "Needs activerecord 2 or 3"
28
52
  end
29
53
  end
30
54
 
31
- ActiveRecord::Base.extend ValidatesDecencyOf
55
+ ActiveRecord::Base.extend ValidatesDecencyOf::ClassMethods
@@ -28,7 +28,14 @@ class TestValidatesDecencyOf < Test::Unit::TestCase
28
28
 
29
29
  def test_should_disallow_indecent_strings
30
30
  assert_equal false, @indecent.valid?
31
- assert @indecent.errors.on(:title)
32
- assert @indecent.errors.on(:description)
31
+ if ActiveRecord::VERSION::MAJOR == 2
32
+ assert @indecent.errors.on(:title).present?
33
+ assert @indecent.errors.on(:description).present?
34
+ elsif ActiveRecord::VERSION::MAJOR == 3
35
+ assert @indecent.errors[:title].present?
36
+ assert @indecent.errors[:description].present?
37
+ else
38
+ raise "don't know what to do"
39
+ end
33
40
  end
34
41
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_decency_of
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 5
8
+ - 1
9
+ version: 1.5.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - Seamus Abshere
@@ -9,19 +14,37 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-03-15 00:00:00 -04:00
17
+ date: 2010-04-07 00:00:00 -04:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
- name: activerecord
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 3
30
+ - 4
31
+ version: 2.3.4
17
32
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: activerecord
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
20
38
  requirements:
21
- - - ~>
39
+ - - ">="
22
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 3
44
+ - 4
23
45
  version: 2.3.4
24
- version:
46
+ type: :runtime
47
+ version_requirements: *id002
25
48
  description: Rails plugin that uses George Carlin's list of seven dirty words (aka swear words, aka cuss words) to check for decency on ActiveRecord model attributes.
26
49
  email: seamus@abshere.net
27
50
  executables: []
@@ -36,14 +59,10 @@ files:
36
59
  - README
37
60
  - Rakefile
38
61
  - VERSION
39
- - init.rb
40
- - install.rb
41
62
  - lib/validates_decency_of.rb
42
- - rails/init.rb
43
63
  - tasks/validates_decency_of_tasks.rake
44
64
  - test/test_helper.rb
45
65
  - test/test_validates_decency_of.rb
46
- - uninstall.rb
47
66
  has_rdoc: true
48
67
  homepage: http://github.com/seamusabshere/validates_decency_of
49
68
  licenses: []
@@ -57,18 +76,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
76
  requirements:
58
77
  - - ">="
59
78
  - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
60
81
  version: "0"
61
- version:
62
82
  required_rubygems_version: !ruby/object:Gem::Requirement
63
83
  requirements:
64
84
  - - ">="
65
85
  - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
66
88
  version: "0"
67
- version:
68
89
  requirements: []
69
90
 
70
91
  rubyforge_project:
71
- rubygems_version: 1.3.5
92
+ rubygems_version: 1.3.6
72
93
  signing_key:
73
94
  specification_version: 3
74
95
  summary: Rails plugin that uses George Carlin's list of seven dirty words (aka swear words, aka cuss words) to check for decency on ActiveRecord model attributes.
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'validates_decency_of'
data/install.rb DELETED
@@ -1 +0,0 @@
1
- # Install hook code here
@@ -1 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'init')
@@ -1 +0,0 @@
1
- # Uninstall hook code here