validates_as_email 0.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.
@@ -0,0 +1,25 @@
1
+ 0.5.1 - Aug 15th 2008
2
+ * Repackaged original plugin by Ximon Eighteen for GitHub
3
+ * Gem'ified plugin
4
+
5
+ 0.1.4 - May 26th 2006
6
+ * Thijs van der Vossen fixed a plugin load issue in the test suite and
7
+ provided another test to illustrate that test@example is considered
8
+ valid by RFC822, something most people wouldn't realise.
9
+
10
+ 0.1.3 - May 9th 2006
11
+ * Thijs van der Vossen contributed some test cases.
12
+
13
+ 0.1.2 - April 24th 2006
14
+ * Dan Kubb and Tim Fletcher have updated the RFC822 regular expression
15
+ on Tims website so I've put the latest version into this plugin. The
16
+ changes prevent matching of email addresses containing line breaks.
17
+
18
+ 0.1.1 - April 23rd 2006
19
+ * Huge code cleanup & simplification by Dan Kubb.
20
+ * Credit Tim Fletcher with the Ruby version of the RFC822 regular
21
+ expression.
22
+
23
+ 0.1.0 - April 4th 2006
24
+ * First release, advertised on the Rails plugins page:
25
+ http://wiki.rubyonrails.org/rails/pages/Plugins
data/LICENSE ADDED
@@ -0,0 +1,5 @@
1
+ Licensing terms follow:
2
+
3
+ This software is placed under the Creative Commons Attribution-Share Alike 3.0 Unported License
4
+
5
+ http://creativecommons.org/licenses/by-sa/3.0/
data/README ADDED
@@ -0,0 +1,47 @@
1
+ ValidatesAsEmail
2
+ ================
3
+
4
+ This gem/plugin is a re-packaged and gem'ified version of the original plugin with credit as follows:
5
+
6
+ Ximon Eighteen <ximon.eighteen@int.greenpeace.org>
7
+ Dan Kubb <dan.kubb@autopilotmarketing.com>
8
+ Thijs van der Vossen <thijs@fngtps.com>
9
+
10
+ This Ruby on Rails plugin implements an ActiveRecord validation helper called
11
+ validates_as_email. The helper acts as if validates_format_of was used with a
12
+ regular expression that defines an RFC822 email address conformance test.
13
+
14
+ The plugin implements the regular expression here:
15
+
16
+ http://tfletcher.com/lib/rfc822.rb
17
+
18
+ Which is an implementation in Ruby of a regular expression published by Cal
19
+ Henderson for PHP here:
20
+
21
+ http://www.iamcal.com/publish/articles/php/parsing_email
22
+
23
+ Installation:
24
+ =============
25
+ gem sources -a http://gems.github.com
26
+
27
+ Install the gem(s):
28
+ sudo gem install gbdev-validates_as_email
29
+
30
+ Add to environment.rb initializer block:
31
+ config.gem 'gbdev-validates_as_email', :version => '>=0.5.0', :lib => 'validates_as_email', :source => 'http://gems.github.com'
32
+
33
+ Usage:
34
+ ======
35
+ In your model file do something like:
36
+
37
+ class MyClass < ActiveRecord::Base
38
+ validates_as_emaile :email, :message => 'Invalid Email Address', :allow_nil => true
39
+ end
40
+
41
+ Tests:
42
+ ======
43
+ Some tests have been added.
44
+
45
+ License:
46
+ ========
47
+ See the LICENSE file.
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the validates_as_email plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the validates_as_email plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'ValidatesAsEmail'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'validates_as_email'
@@ -0,0 +1,59 @@
1
+ #
2
+ # RFC822 Email Address Regex
3
+ # --------------------------
4
+ #
5
+ # Originally written by Cal Henderson
6
+ # c.f. http://iamcal.com/publish/articles/php/parsing_email/
7
+ #
8
+ # Translated to Ruby by Tim Fletcher, with changes suggested by Dan Kubb.
9
+ #
10
+ # Licensed under a Creative Commons Attribution-ShareAlike 2.5 License
11
+ # http://creativecommons.org/licenses/by-sa/2.5/
12
+ #
13
+ module RFC822
14
+ EmailAddress = begin
15
+ qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'
16
+ dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'
17
+ atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-' +
18
+ '\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'
19
+ quoted_pair = '\\x5c[\\x00-\\x7f]'
20
+ domain_literal = "\\x5b(?:#{dtext}|#{quoted_pair})*\\x5d"
21
+ quoted_string = "\\x22(?:#{qtext}|#{quoted_pair})*\\x22"
22
+ domain_ref = atom
23
+ sub_domain = "(?:#{domain_ref}|#{domain_literal})"
24
+ word = "(?:#{atom}|#{quoted_string})"
25
+ domain = "#{sub_domain}(?:\\x2e#{sub_domain})*"
26
+ local_part = "#{word}(?:\\x2e#{word})*"
27
+ addr_spec = "#{local_part}\\x40#{domain}"
28
+ pattern = /\A#{addr_spec}\z/
29
+ end
30
+ end
31
+
32
+ # Validation helper for ActiveRecord derived objects that cleanly and simply
33
+ # allows the model to check if the given string is a syntactically valid email
34
+ # address (by using the RFC822 module above).
35
+ #
36
+ # Original code by Ximon Eighteen <ximon.eightee@int.greenpeace.org> which was
37
+ # heavily based on code I can no longer find on the net, my apologies to the
38
+ # author!
39
+ #
40
+ # Huge credit goes to Dan Kubb <dan.kubb@autopilotmarketing.com> for
41
+ # submitting a patch to massively simplify this code and thereby instruct me
42
+ # in the ways of Rails too! I reflowed the patch a little to keep the line
43
+ # length to a maximum of 78 characters, an old habit.
44
+
45
+ module ActiveRecord
46
+ module Validations
47
+ module ClassMethods
48
+ def validates_as_email(*attr_names)
49
+ configuration = {
50
+ :message => 'is an invalid email',
51
+ :with => RFC822::EmailAddress,
52
+ :allow_nil => true }
53
+ configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
54
+
55
+ validates_format_of attr_names, configuration
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,44 @@
1
+ require 'test/unit'
2
+
3
+ begin
4
+ require File.dirname(__FILE__) + '/../../../../config/boot'
5
+ require 'active_record'
6
+ require 'validates_as_email'
7
+ rescue LoadError
8
+ require 'rubygems'
9
+ require 'activerecord'
10
+ require File.dirname(__FILE__) + '/../lib/validates_as_email'
11
+ end
12
+
13
+ class TestRecord < ActiveRecord::Base
14
+ def self.columns; []; end
15
+ attr_accessor :email
16
+ validates_as_email :email
17
+ end
18
+
19
+ class ValidatesAsEmailTest < Test::Unit::TestCase
20
+ def test_illegal_rfc822_email_address
21
+ addresses = [
22
+ 'Max@Job 3:14',
23
+ 'Job@Book of Job',
24
+ 'J. P. \'s-Gravezande, a.k.a. The Hacker!@example.com',
25
+ ]
26
+ addresses.each do |address|
27
+ assert !TestRecord.new(:email => address).valid?, "#{address} should be illegal."
28
+ end
29
+ end
30
+
31
+ def test_legal_rfc822_email_address
32
+ addresses = [
33
+ 'test@example',
34
+ 'test@example.com',
35
+ 'test@example.co.uk',
36
+ '"J. P. \'s-Gravezande, a.k.a. The Hacker!"@example.com',
37
+ 'me@[187.223.45.119]',
38
+ 'someone@123.com',
39
+ ]
40
+ addresses.each do |address|
41
+ assert TestRecord.new(:email => address).valid?, "#{address} should be legal."
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: validates_as_email
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
5
+ platform: ruby
6
+ authors:
7
+ - Ximon Eighteen
8
+ - Dan Kubb
9
+ - Thijs van der Vossen
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2008-08-15 00:00:00 -07:00
15
+ default_executable:
16
+ dependencies: []
17
+
18
+ description: Rails gem/plugin that implements an ActiveRecord validation helper called validates_as_email which validates email address (RFC822)
19
+ email: gems@gbdev.com
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - CHANGELOG
28
+ - LICENSE
29
+ - README
30
+ - Rakefile
31
+ - init.rb
32
+ - lib/validates_as_email.rb
33
+ - test/validates_as_email_test.rb
34
+ has_rdoc: true
35
+ homepage: http://github.com/gbdev/validates_as_email
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.3.5
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Rails gem/plugin to validate format of email addresses (RFC822)
62
+ test_files:
63
+ - test/validates_as_email_test.rb