PageRenderTime 81ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/email-validator.rb

https://github.com/wireframe/email-validator
Ruby | 23 lines | 18 code | 5 blank | 0 comment | 0 complexity | 0dbe8bffb0d786f712ff0802ec769e93 MD5 | raw file
  1. require 'email-validator/version'
  2. require 'active_support/concern'
  3. require 'active_record'
  4. require File.join(File.dirname(__FILE__), 'rfc822')
  5. module EmailValidator
  6. extend ActiveSupport::Concern
  7. module ClassMethods
  8. include RFC822
  9. def validate_email_format(attribute, options = {})
  10. options.reverse_merge! :message => 'is invalid'
  11. validates_each([attribute], options) do |record, attr, value|
  12. valid_email = record.send(attr).to_s.match EMAIL_ADDRESS_REGEX
  13. record.errors.add attr, options[:message] unless valid_email
  14. end
  15. end
  16. end
  17. end
  18. ActiveRecord::Base.send(:include, EmailValidator)