rails_email_validator 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -1,3 +1,4 @@
1
+
1
2
  require 'active_model'
2
3
 
3
4
  class EmailValidator < ActiveModel::EachValidator
@@ -18,22 +19,24 @@ class EmailValidator < ActiveModel::EachValidator
18
19
 
19
20
  # main validator for email
20
21
  def validate_each(record, attribute, value)
21
- # split local and domain part
22
- (local_part, domain_part) = value.split('@', 2)
22
+ unless value.blank?
23
+ # split local and domain part
24
+ (local_part, domain_part) = value.split('@', 2)
23
25
 
24
- # pre var
25
- valid = true
26
+ # pre var
27
+ valid = true
26
28
 
27
- # check syntax
28
- valid = false unless local_part =~ /\A[A-Za-z0-9.!\#$%&'*+-\/=?^_`{|}~]+\Z/
29
- valid = false unless domain_part =~ /\A((?:[-a-zA-Z0-9]+\.)+[a-zA-Z]{2,})\Z/
29
+ # check syntax
30
+ valid = false unless local_part =~ /\A[A-Za-z0-9.!\#$%&'*+-\/=?^_`{|}~]+\Z/
31
+ valid = false unless domain_part =~ /\A((?:[-a-zA-Z0-9]+\.)+[a-zA-Z]{2,})\Z/
30
32
 
31
- # check mx
32
- if valid and validate_mx?
33
- valid = false unless has_mx? domain_part
34
- end
33
+ # check mx
34
+ if valid and validate_mx?
35
+ valid = false unless has_mx? domain_part
36
+ end
35
37
 
36
- # email valid
37
- record.errors.add(attribute, :invalid) unless valid
38
+ # email valid
39
+ record.errors.add(attribute, :invalid) unless valid
40
+ end
38
41
  end
39
42
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails_email_validator}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marco Scholl"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Marco Scholl
@@ -140,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - ">="
142
142
  - !ruby/object:Gem::Version
143
- hash: 91075652247731073
143
+ hash: 4213132792556836098
144
144
  segments:
145
145
  - 0
146
146
  version: "0"