forked from brodock/validates_as_email
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compatibility fix with validation_reflection
- Loading branch information
Showing
1 changed file
with
30 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
# Validation helper for ActiveRecord derived objects that cleanly and simply | ||
# allows the model to check if the given string is a syntactically valid email | ||
# address (by using the RFC822 module in rfc822.rb). | ||
# | ||
# Original code by Ximon Eighteen <ximon.eightee@int.greenpeace.org> which was | ||
# heavily based on code I can no longer find on the net, my apologies to the | ||
# author! | ||
# | ||
# Huge credit goes to Dan Kubb <dan.kubb@autopilotmarketing.com> for | ||
# submitting a patch to massively simplify this code and thereby instruct me | ||
# in the ways of Rails too! I reflowed the patch a little to keep the line | ||
# length to a maximum of 78 characters, an old habit. | ||
|
||
module ActiveRecord | ||
module Validations | ||
module ClassMethods | ||
def validates_as_email *attr_names | ||
configuration = { | ||
:message => :invalid_email, | ||
:with => RFC822::EmailAddress, | ||
:allow_nil => false | ||
} | ||
configuration.update(attr_names.extract_options!) | ||
|
||
validates_format_of attr_names, configuration | ||
end | ||
end | ||
end | ||
end | ||
# Validation helper for ActiveRecord derived objects that cleanly and simply | ||
# allows the model to check if the given string is a syntactically valid email | ||
# address (by using the RFC822 module in rfc822.rb). | ||
# | ||
# Original code by Ximon Eighteen <ximon.eightee@int.greenpeace.org> which was | ||
# heavily based on code I can no longer find on the net, my apologies to the | ||
# author! | ||
# | ||
# Huge credit goes to Dan Kubb <dan.kubb@autopilotmarketing.com> for | ||
# submitting a patch to massively simplify this code and thereby instruct me | ||
# in the ways of Rails too! I reflowed the patch a little to keep the line | ||
# length to a maximum of 78 characters, an old habit. | ||
|
||
module ActiveRecord | ||
module Validations | ||
module ClassMethods | ||
def validates_as_email *attr_names | ||
config = { | ||
:message => :invalid_email, | ||
:with => RFC822::EmailAddress, | ||
:allow_nil => false | ||
}.update attr_names.extract_options! | ||
|
||
attr_names.each do |attr_name| | ||
validates_format_of attr_name, config | ||
end | ||
end | ||
end | ||
end | ||
end |