Permalink
Browse files

Reorganization for rename to EmailAddressValidator

  • Loading branch information...
1 parent bc73708 commit 02f25f69fa7af1dcc1dbb134109cfa8fe55b0352 @andrewvc andrewvc committed Mar 24, 2011
View
@@ -9,9 +9,9 @@ task :default => 'test:run'
task 'gem:release' => 'test:run'
task "parser" do
- sh "kpeg -s -o lib/rfc-822/parser.rb -f email.kpeg"
- sh "kpeg -s -o lib/rfc-822/parser2822.rb -f rfc2822.kpeg"
- sh "kpeg -s -o lib/rfc-822/domain_parser.rb -f domain.kpeg"
+ sh "kpeg -s -o lib/email-address-validator/rfc822-parser.rb -f grammars/rfc822.kpeg"
+ sh "kpeg -s -o lib/email-address-validator/rfc2822-parser.rb -f grammars/rfc2822.kpeg"
+ sh "kpeg -s -o lib/email-address-validator/domain-parser.rb -f grammars/domain.kpeg"
end
Bones {
View
@@ -1,7 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(
- File.join(File.dirname(__FILE__), %w[.. lib rfc-822]))
-
-# Put your code here
-
@@ -1,4 +1,4 @@
-%% name = RFC822::DomainParser
+%% name = EmailAddressValidator::DomainParser
domain = < subdomain > &{ text.size < 255 }
@@ -1,4 +1,4 @@
-%% name = RFC822::Parser2822
+%% name = EmailAddressValidator::RFC2822Parser
%% { attr_accessor :validate_domain }
@@ -1,4 +1,4 @@
-%% name = RFC822::Parser
+%% name = EmailAddressValidator::RFC822Parser
%% { attr_accessor :validate_domain }
@@ -1,5 +1,4 @@
-
-module RFC822
+module EmailAddressValidator
# :stopdoc:
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
@@ -54,37 +53,46 @@ def self.require_all_libs_relative_to( fname, dir = nil )
Dir.glob(search_me).sort.each {|rb| require rb}
end
-
- def self.validate(addr, validate_domain=false)
- parser = Parser.new(addr)
+ # Validates +addr+ against the addr_spec portion of RFC 2822.
+ # This is what most people actually want out of an email validator
+ # You very well may want to set validate_domain to true as well,
+ # as RFC2822 doesn't explicitly require valid domains
+ def self.validate_2822_addr(addr, validate_domain=false)
+ parser = RFC2822Parser.new(addr, "only_addr_spec")
parser.validate_domain = validate_domain
parser.parse
end
- def self.validate_addr(addr, validate_domain=false)
- parser = Parser.new(addr, "only_addr_spec")
+ # Validates an email address according to RFC 2822
+ # This validates addresses against the full spec, which
+ # may not be what you want.
+ def self.validate_2822(addr, validate_domain=false)
+ parser = RFC2822Parser.new(addr)
parser.validate_domain = validate_domain
parser.parse
end
- def self.validate_modern(addr, validate_domain=false)
- parser = Parser2822.new(addr)
+ # Validates legacy address according to RFC 822, the original
+ # email grammar.
+ def self.validate_822(addr, validate_domain=false)
+ parser = RFC822Parser.new(addr)
parser.validate_domain = validate_domain
parser.parse
end
- def self.validate_modern_addr(addr, validate_domain=false)
- parser = Parser2822.new(addr, "only_addr_spec")
+ # Validates only the addr_spec portion an address according to RFC 822
+ def self.validate_822_addr(addr, validate_domain=false)
+ parser = RFC822Parser.new(addr, "only_addr_spec")
parser.validate_domain = validate_domain
parser.parse
end
+ # Validates a domain name
def self.validate_domain(domain)
parser = DomainParser.new(addr)
parser.parse
end
-end # module RFC822
-
-RFC822.require_all_libs_relative_to(__FILE__)
+end
+EmailAddressValidator.require_all_libs_relative_to(__FILE__)
@@ -1,4 +1,4 @@
-class RFC822::DomainParser
+class EmailAddressValidator::DomainParser
# STANDALONE START
def setup_parser(str, debug=false)
@string = str
@@ -11,6 +11,9 @@ def setup_parser(str, debug=false)
setup_foreign_grammar
end
+ def setup_foreign_grammar
+ end
+
# This is distinct from setup_parser so that a standalone parser
# can redefine #initialize and still have access to the proper
# parser setup code.
@@ -1,4 +1,4 @@
-class RFC822::Parser2822
+class EmailAddressValidator::RFC2822Parser
# STANDALONE START
def setup_parser(str, debug=false)
@string = str
@@ -11,6 +11,9 @@ def setup_parser(str, debug=false)
setup_foreign_grammar
end
+ def setup_foreign_grammar
+ end
+
# This is distinct from setup_parser so that a standalone parser
# can redefine #initialize and still have access to the proper
# parser setup code.
@@ -1,4 +1,4 @@
-class RFC822::Parser
+class EmailAddressValidator::RFC822Parser
# STANDALONE START
def setup_parser(str, debug=false)
@string = str
@@ -11,6 +11,9 @@ def setup_parser(str, debug=false)
setup_foreign_grammar
end
+ def setup_foreign_grammar
+ end
+
# This is distinct from setup_parser so that a standalone parser
# can redefine #initialize and still have access to the proper
# parser setup code.
@@ -1,7 +1,7 @@
require File.join(File.dirname(__FILE__), %w[spec_helper])
-describe RFC822 do
+describe EmailAddressValidator do
VALID_COMMON =
["simple@example.com", "\"Abc\@def\"@example.com",
"\"Fred Bloggs\"@example.com", "\"Joe\\Blow\"@example.com",
@@ -55,31 +55,31 @@
VALID.each do |addr|
it "should recognize <#{addr}> as valid" do
- RFC822.validate(addr).should be_true
+ EmailAddressValidator.validate_822(addr).should be_true
end
end
INVALID.each do |addr|
it "should recognize <#{addr}> as invalid" do
- RFC822.validate(addr).should be_false
+ EmailAddressValidator.validate_822(addr).should be_false
end
end
VALID_ADDRSPEC.each do |addr|
it "should recognize <#{addr}> as valid" do
- RFC822.validate_addr(addr).should be_true
+ EmailAddressValidator.validate_822_addr(addr).should be_true
end
end
VALID_DOMAIN_COMMON.each do |addr|
it "should validate the domain of <#{addr}> as valid" do
- RFC822.validate(addr, true).should be_true
+ EmailAddressValidator.validate_822(addr, true).should be_true
end
end
INVALID_DOMAIN_COMMON.each do |addr|
it "should validate the domain of <#{addr}> as invalid" do
- RFC822.validate(addr, true).should be_false
+ EmailAddressValidator.validate_822(addr, true).should be_false
end
end
@@ -89,31 +89,31 @@
VALID_MODERN.each do |addr|
it "should recognize modern <#{addr}> as valid" do
- RFC822.validate_modern(addr).should be_true
+ EmailAddressValidator.validate_2822_addr(addr).should be_true
end
end
INVALID_MODERN.each do |addr|
it "should recognize modern <#{addr}> as invalid" do
- RFC822.validate_modern(addr).should be_false
+ EmailAddressValidator.validate_2822_addr(addr).should be_false
end
end
VALID_ADDRSPEC.each do |addr|
it "should recognize modern <#{addr}> as valid" do
- RFC822.validate_modern_addr(addr).should be_true
+ EmailAddressValidator.validate_2822_addr(addr).should be_true
end
end
VALID_DOMAIN_COMMON.each do |addr|
it "should validate the domain of <#{addr}> as valid" do
- RFC822.validate_modern(addr, true).should be_true
+ EmailAddressValidator.validate_2822(addr, true).should be_true
end
end
INVALID_DOMAIN_COMMON.each do |addr|
it "should validate the domain of <#{addr}> as invalid" do
- RFC822.validate(addr, true).should be_false
+ EmailAddressValidator.validate_822(addr, true).should be_false
end
end
View
@@ -1,2 +1,2 @@
require File.expand_path(
- File.join(File.dirname(__FILE__), %w[.. lib rfc-822]))
+ File.join(File.dirname(__FILE__), %w[.. lib email_address_validator]))

0 comments on commit 02f25f6

Please sign in to comment.