Module: SimplesIdeias::ValidatesEmailWhitelistOf
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/validates_email_whitelist_of.rb,
lib/rails2/validates_email_whitelist_of.rb
Constant Summary collapse
- EMAIL_FORMAT =
/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
Instance Method Summary collapse
- #validates_email_blacklist_of(*attr_names) ⇒ Object
- #validates_email_whitelist_of(*attr_names) ⇒ Object
Instance Method Details
#validates_email_blacklist_of(*attr_names) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rails2/validates_email_whitelist_of.rb', line 24 def validates_email_blacklist_of(*attr_names) = { :on => :save, :allow_nil => false, :allow_blank => false, :blacklist => [] } .update(attr_names.pop) if attr_names.last.kind_of?(Hash) validates_each(attr_names, ) do |record, attr_name, value| if value.to_s =~ EMAIL_FORMAT = ::I18n.t(:invalid_blacklist, :scope => 'activerecord.errors.messages') record.errors.add(attr_name, ) if [:blacklist].include?($2) else = ::I18n.translate([:message], :default => [:"activerecord.errors.messages.invalid_email", "is not a valid address"]) record.errors.add(attr_name, ) end end end |
#validates_email_whitelist_of(*attr_names) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rails2/validates_email_whitelist_of.rb', line 3 def validates_email_whitelist_of(*attr_names) = { :on => :save, :allow_nil => false, :allow_blank => false, :whitelist => [] } .update(attr_names.pop) if attr_names.last.kind_of?(Hash) validates_each(attr_names, ) do |record, attr_name, value| if value.to_s =~ EMAIL_FORMAT = ::I18n.t(:invalid_whitelist, :scope => 'activerecord.errors.messages') record.errors.add(attr_name, ) unless [:whitelist].include?($2) else = ::I18n.translate([:message], :default => [:"activerecord.errors.messages.invalid_email", "is not a valid address"]) record.errors.add(attr_name, ) end end end |