preciousss 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
@@ -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
|
data/lib/preciousss/version.rb
CHANGED
data/lib/preciousss.rb
CHANGED
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:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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-
|
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
|