preciousss 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ require 'mail'
2
+
3
+ # http://my.rails-royce.org/2010/07/21/email-validation-in-ruby-on-rails-without-regexp/
4
+ class EmailFormatValidator < ActiveModel::EachValidator
5
+
6
+ def validate_each(record,attribute,value)
7
+ begin
8
+ m = Mail::Address.new(value)
9
+ # We must check that value contains a domain and that value is an email address
10
+ r = m.domain && m.address == value
11
+ t = m.__send__(:tree)
12
+ # We need to dig into treetop
13
+ # A valid domain must have dot_atom_text elements size > 1
14
+ # user@localhost is excluded
15
+ # treetop must respond to domain
16
+ # We exclude valid email values like <user@localhost.com>
17
+ # Hence we use m.__send__(tree).domain
18
+ r &&= (t.domain.dot_atom_text.elements.size > 1)
19
+ rescue Exception => e
20
+ r = false
21
+ end
22
+ record.errors[attribute] << (options[:message] || :invalid) unless r
23
+ end
24
+
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Preciousss
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
data/lib/preciousss.rb CHANGED
@@ -14,6 +14,8 @@ module Preciousss
14
14
 
15
15
  include Preciousss::Controllers::Helpers
16
16
  end
17
+
18
+ require 'preciousss/validators/email_format_validator'
17
19
  end
18
20
 
19
21
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: preciousss
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - sodercober
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-04 00:00:00 +00:00
18
+ date: 2011-03-07 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -35,6 +35,7 @@ files:
35
35
  - Rakefile
36
36
  - lib/preciousss.rb
37
37
  - lib/preciousss/controllers/helpers.rb
38
+ - lib/preciousss/validators/email_format_validator.rb
38
39
  - lib/preciousss/version.rb
39
40
  - lib/preciousss/view_helpers/action_view.rb
40
41
  - preciousss.gemspec