mail_validator 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mail_validator.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010-2011 Gabriel Sobrinho
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.
@@ -0,0 +1,17 @@
1
+ h1. MailValidator
2
+
3
+ This gem is based on *gbdev* works in "http://github.com/gbdev/validates_as_email":http://github.com/gbdev/validates_as_email
4
+
5
+ h2. Installation
6
+
7
+ <pre>gem "mail_validator"</pre>
8
+
9
+ h2. Usage
10
+
11
+ <pre>class Person < ActiveRecord::Base
12
+ validates :email, :mail => true
13
+ end</pre>
14
+
15
+ h2. License
16
+
17
+ Copyright (c) 2010-2011 Gabriel Sobrinho, released under the MIT license
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ task :default => :test
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << 'test'
10
+ t.pattern = 'test/**/*_test.rb'
11
+ end
File without changes
@@ -0,0 +1,7 @@
1
+ class MailValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ if value !~ /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
4
+ record.errors.add(attribute, options[:message])
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |s|
3
+ s.name = "mail_validator"
4
+ s.version = "0.2.0"
5
+ s.platform = Gem::Platform::RUBY
6
+ s.authors = ["Gabriel Sobrinho"]
7
+ s.email = ["gabriel.sobrinho@gmail.com"]
8
+ s.homepage = "https://github.com/sobrinho/mail_validator"
9
+ s.summary = %q{Mail validation for ActiveModel}
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
+ s.require_paths = ["lib"]
15
+
16
+ s.add_dependency(%q<activemodel>, [">= 3.0"])
17
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ class MailValidatorTest < Test::Unit::TestCase
4
+ def test_illegal_addresses
5
+ assert_invalid 'Max@Job 3:14'
6
+ assert_invalid 'Job@Book of Job'
7
+ assert_invalid "J. P. 's-Gravezande, a.k.a. The Hacker!@example.com"
8
+ end
9
+
10
+ def test_legal_addresses
11
+ assert_valid 'test@example.com'
12
+ assert_valid 'test@example.co.uk'
13
+ assert_valid 'someone@123.com'
14
+ end
15
+
16
+ protected
17
+
18
+ def assert_valid(email)
19
+ assert person(:email => email).valid?
20
+ end
21
+
22
+ def assert_invalid(email)
23
+ assert person(:email => email).invalid?
24
+ end
25
+
26
+ def person(attributes = {})
27
+ Person.new(attributes)
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_model'
4
+ require 'mail_validator'
5
+ require 'ostruct'
6
+
7
+ class Person < OpenStruct
8
+ include ActiveModel::Validations
9
+ validates :email, :mail => true
10
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mail_validator
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.2.0
6
+ platform: ruby
7
+ authors:
8
+ - Gabriel Sobrinho
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-21 00:00:00 -03:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activemodel
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "3.0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description:
28
+ email:
29
+ - gabriel.sobrinho@gmail.com
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - MIT-LICENSE
40
+ - README.textile
41
+ - Rakefile
42
+ - config/environment.rb
43
+ - lib/mail_validator.rb
44
+ - mail_validator.gemspec
45
+ - test/mail_validator_test.rb
46
+ - test/test_helper.rb
47
+ has_rdoc: true
48
+ homepage: https://github.com/sobrinho/mail_validator
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.5.2
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Mail validation for ActiveModel
75
+ test_files:
76
+ - test/mail_validator_test.rb
77
+ - test/test_helper.rb