contacts_client 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ require 'mail'
2
+ class EmailFormatValidator < ActiveModel::EachValidator
3
+ def validate_each(record,attribute,value)
4
+ begin
5
+ m = Mail::Address.new(value)
6
+ # We must check that value contains a domain and that value is an email address
7
+ r = m.domain && m.address == value
8
+ t = m.__send__(:tree)
9
+ # We need to dig into treetop
10
+ # A valid domain must have dot_atom_text elements size > 1
11
+ # user@localhost is excluded
12
+ # treetop must respond to domain
13
+ # We exclude valid email values like <user@localhost.com>
14
+ # Hence we use m.__send__(tree).domain
15
+ r &&= (t.domain.dot_atom_text.elements.size > 1)
16
+ rescue Exception => e
17
+ r = false
18
+ end
19
+ record.errors[attribute] << (options[:message] || I18n.t('errors.messages.invalid_format')) unless r
20
+ end
21
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 6
9
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dwayne Macgowan
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2013-01-25 00:00:00 -03:00
17
+ date: 2013-01-28 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -56,6 +56,7 @@ extensions: []
56
56
  extra_rdoc_files: []
57
57
 
58
58
  files:
59
+ - app/validators/email_format_validator.rb
59
60
  - app/models/date_attribute.rb
60
61
  - app/models/address.rb
61
62
  - app/models/identification.rb