Module: EmailAddressValidator
- Defined in:
- lib/email_address_validator.rb,
lib/email_address_validator/version.rb
Defined Under Namespace
Classes: DomainParser, RFC2822Parser, RFC822Parser
Constant Summary collapse
- LIBPATH =
:stopdoc:
::File.(::File.dirname(__FILE__)) + ::File::SEPARATOR
- PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
- VERSION =
"2.0.0"
Class Method Summary collapse
-
.libpath(*args) ⇒ Object
Returns the library path for the module.
-
.path(*args) ⇒ Object
Returns the lpath for the module.
-
.require_all_libs_relative_to(fname, dir = nil) ⇒ Object
Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in.
-
.validate(addr, validate_domain = false) ⇒ Object
Shorthand for +EmailAddressParser.validate_2822.
-
.validate_2822(addr, validate_domain = false) ⇒ Object
Validates an email address according to RFC 2822 This validates addresses against the full spec, which may not be what you want.
-
.validate_2822_addr(addr, validate_domain = false) ⇒ Object
Validates
addragainst the addr_spec portion of RFC 2822. -
.validate_822(addr, validate_domain = false) ⇒ Object
Validates legacy address according to RFC 822, the original email grammar.
-
.validate_822_addr(addr, validate_domain = false) ⇒ Object
Validates only the addr_spec portion an address according to RFC 822.
-
.validate_addr(addr, validate_domain = false) ⇒ Object
Shorthand for +EmailAddressParser.validate_2822_addr.
-
.validate_domain(domain) ⇒ Object
Validates a domain name.
Class Method Details
.libpath(*args) ⇒ Object
Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/email_address_validator.rb', line 11 def self.libpath( *args ) rv = args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten) if block_given? begin $LOAD_PATH.unshift LIBPATH rv = yield ensure $LOAD_PATH.shift end end return rv end |
.path(*args) ⇒ Object
Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/email_address_validator.rb', line 28 def self.path( *args ) rv = args.empty? ? PATH : ::File.join(PATH, args.flatten) if block_given? begin $LOAD_PATH.unshift PATH rv = yield ensure $LOAD_PATH.shift end end return rv end |
.require_all_libs_relative_to(fname, dir = nil) ⇒ Object
Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.
46 47 48 49 50 51 52 |
# File 'lib/email_address_validator.rb', line 46 def self.require_all_libs_relative_to( fname, dir = nil ) dir ||= ::File.basename(fname, '.*') search_me = ::File.( ::File.join(::File.dirname(fname), dir, '**', '*.rb')) Dir.glob(search_me).sort.each {|rb| require rb} end |
.validate(addr, validate_domain = false) ⇒ Object
Shorthand for +EmailAddressParser.validate_2822
70 71 72 |
# File 'lib/email_address_validator.rb', line 70 def self.validate(addr, validate_domain=false) validate_2822 addr, validate_domain end |
.validate_2822(addr, validate_domain = false) ⇒ Object
Validates an email address according to RFC 2822 This validates addresses against the full spec, which may not be what you want.
77 78 79 80 81 |
# File 'lib/email_address_validator.rb', line 77 def self.validate_2822(addr, validate_domain=false) parser = RFC2822Parser.new(addr) parser.validate_domain = validate_domain parser.parse end |
.validate_2822_addr(addr, validate_domain = false) ⇒ Object
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
63 64 65 66 67 |
# File 'lib/email_address_validator.rb', line 63 def self.validate_2822_addr(addr, validate_domain=false) parser = RFC2822Parser.new(addr, "only_addr_spec") parser.validate_domain = validate_domain parser.parse end |
.validate_822(addr, validate_domain = false) ⇒ Object
Validates legacy address according to RFC 822, the original email grammar.
85 86 87 88 89 |
# File 'lib/email_address_validator.rb', line 85 def self.validate_822(addr, validate_domain=false) parser = RFC822Parser.new(addr) parser.validate_domain = validate_domain parser.parse end |
.validate_822_addr(addr, validate_domain = false) ⇒ Object
Validates only the addr_spec portion an address according to RFC 822
92 93 94 95 96 |
# File 'lib/email_address_validator.rb', line 92 def self.validate_822_addr(addr, validate_domain=false) parser = RFC822Parser.new(addr, "only_addr_spec") parser.validate_domain = validate_domain parser.parse end |
.validate_addr(addr, validate_domain = false) ⇒ Object
Shorthand for +EmailAddressParser.validate_2822_addr
55 56 57 |
# File 'lib/email_address_validator.rb', line 55 def self.validate_addr(addr, validate_domain=false) validate_2822_addr addr, validate_domain end |
.validate_domain(domain) ⇒ Object
Validates a domain name
99 100 101 102 |
# File 'lib/email_address_validator.rb', line 99 def self.validate_domain(domain) parser = DomainParser.new(addr) parser.parse end |