email-validator 0.2.0
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/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/lib/email-validator.rb +18 -0
- data/lib/rfc822.rb +27 -0
- data/test/database.yml +3 -0
- data/test/helper.rb +17 -0
- data/test/test_email-validator.rb +39 -0
- metadata +123 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Ryan Sonnek
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= email-validator
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Ryan Sonnek. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "email-validator"
|
8
|
+
gem.summary = %Q{validate that email attribute contains valid email}
|
9
|
+
gem.description = %Q{validate that email attribute contains valid email}
|
10
|
+
gem.email = "ryan@socialcast.com"
|
11
|
+
gem.homepage = "http://github.com/wireframe/email-validator"
|
12
|
+
gem.authors = ["Ryan Sonnek"]
|
13
|
+
gem.add_runtime_dependency "activerecord", ">= 2.2.3"
|
14
|
+
gem.add_runtime_dependency "tmail", ">= 1.2"
|
15
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "email-validator #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'rfc822')
|
2
|
+
|
3
|
+
module EmailValidator
|
4
|
+
module ClassMethods
|
5
|
+
include RFC822
|
6
|
+
|
7
|
+
def validate_email_format(attribute, options = {})
|
8
|
+
options.reverse_merge! :message => 'is invalid'
|
9
|
+
|
10
|
+
validates_each([attribute], options) do |record, attr, value|
|
11
|
+
valid_email = record.send(attr).to_s.match EMAIL_ADDRESS_REGEX
|
12
|
+
record.errors.add attr, options[:message] unless valid_email
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
ActiveRecord::Base.send(:extend, EmailValidator::ClassMethods)
|
data/lib/rfc822.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# RFC822 Email Address Regex
|
2
|
+
# -———————————-
|
3
|
+
# Originally written by Cal Henderson
|
4
|
+
# c.f. http://iamcal.com/publish/articles/php/parsing_email/
|
5
|
+
#
|
6
|
+
# Translated to Ruby by Tim Fletcher, with changes suggested by Dan Kubb.
|
7
|
+
#
|
8
|
+
# Licensed under a Creative Commons Attribution-ShareAlike 2.5 License
|
9
|
+
# http://creativecommons.org/licenses/by-sa/2.5/
|
10
|
+
module RFC822
|
11
|
+
EMAIL_ADDRESS_REGEX = begin
|
12
|
+
qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'
|
13
|
+
dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'
|
14
|
+
atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-' +
|
15
|
+
'\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'
|
16
|
+
quoted_pair = '\\x5c[\\x00-\\x7f]'
|
17
|
+
domain_literal = "\\x5b(?:#{dtext}|#{quoted_pair})*\\x5d"
|
18
|
+
quoted_string = "\\x22(?:#{qtext}|#{quoted_pair})*\\x22"
|
19
|
+
domain_ref = atom
|
20
|
+
sub_domain = "(?:#{domain_ref}|#{domain_literal})"
|
21
|
+
word = "(?:#{atom}|#{quoted_string})"
|
22
|
+
domain = "#{sub_domain}(?:\\x2e#{sub_domain})*"
|
23
|
+
local_part = "#{word}(?:\\x2e#{word})*"
|
24
|
+
addr_spec = "#{local_part}\\x40#{domain}"
|
25
|
+
pattern = /\A#{addr_spec}\z/
|
26
|
+
end
|
27
|
+
end
|
data/test/database.yml
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
require 'active_record'
|
6
|
+
require 'tmail'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
10
|
+
require 'email-validator'
|
11
|
+
|
12
|
+
config = YAML::load(IO.read(File.join(File.dirname(__FILE__), 'database.yml')))
|
13
|
+
# ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
14
|
+
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite'])
|
15
|
+
|
16
|
+
class Test::Unit::TestCase
|
17
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
|
3
|
+
ActiveRecord::Schema.define(:version => 1) do
|
4
|
+
create_table :users, :force => true do |t|
|
5
|
+
t.column :email, :string
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class TestEmailValidator < Test::Unit::TestCase
|
10
|
+
class User < ActiveRecord::Base
|
11
|
+
validate_email_format :email
|
12
|
+
end
|
13
|
+
|
14
|
+
context "object with invalid email address" do
|
15
|
+
setup do
|
16
|
+
@user = User.create :email => 'mike@@@@@test.com'
|
17
|
+
end
|
18
|
+
should 'have error on email attribute' do
|
19
|
+
assert_equal 'Email is invalid', @user.errors.full_messages.to_sentence
|
20
|
+
end
|
21
|
+
end
|
22
|
+
context "object with email address containing double quotes" do
|
23
|
+
setup do
|
24
|
+
@user = User.create :email => '"mike" foo@test.com'
|
25
|
+
end
|
26
|
+
should 'have not error on email attribute' do
|
27
|
+
assert_equal 'Email is invalid', @user.errors.full_messages.to_sentence
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "object with valid email address" do
|
32
|
+
setup do
|
33
|
+
@user = User.create :email => 'foo@test.com'
|
34
|
+
end
|
35
|
+
should 'have not error on email attribute' do
|
36
|
+
assert @user.valid?, @user.errors.full_messages.to_sentence
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: email-validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ryan Sonnek
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-13 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activerecord
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 1
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 2
|
33
|
+
- 3
|
34
|
+
version: 2.2.3
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: tmail
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 11
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 2
|
49
|
+
version: "1.2"
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: shoulda
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
description: validate that email attribute contains valid email
|
67
|
+
email: ryan@socialcast.com
|
68
|
+
executables: []
|
69
|
+
|
70
|
+
extensions: []
|
71
|
+
|
72
|
+
extra_rdoc_files:
|
73
|
+
- LICENSE
|
74
|
+
- README.rdoc
|
75
|
+
files:
|
76
|
+
- .document
|
77
|
+
- .gitignore
|
78
|
+
- LICENSE
|
79
|
+
- README.rdoc
|
80
|
+
- Rakefile
|
81
|
+
- VERSION
|
82
|
+
- lib/email-validator.rb
|
83
|
+
- lib/rfc822.rb
|
84
|
+
- test/database.yml
|
85
|
+
- test/helper.rb
|
86
|
+
- test/test_email-validator.rb
|
87
|
+
has_rdoc: true
|
88
|
+
homepage: http://github.com/wireframe/email-validator
|
89
|
+
licenses: []
|
90
|
+
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options:
|
93
|
+
- --charset=UTF-8
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
hash: 3
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
version: "0"
|
114
|
+
requirements: []
|
115
|
+
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 1.3.7
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: validate that email attribute contains valid email
|
121
|
+
test_files:
|
122
|
+
- test/helper.rb
|
123
|
+
- test/test_email-validator.rb
|