Skip to content

Commit

Permalink
Compatibility fix with validation_reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
sobrinho committed Oct 3, 2009
1 parent e58cb45 commit 14a9890
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions lib/validates_as_email/validates_as_email.rb
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

0 comments on commit 14a9890

Please sign in to comment.