email_format 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 694dda2a4da9653812f143d3d8064224ee367fca
4
- data.tar.gz: 7ff1b8bd68f1ae304284dcc3500ae44dea2220a9
3
+ metadata.gz: 1572f05a8b9ebf1fa07bd0066312b822372f44cb
4
+ data.tar.gz: 559b63ccc610d4cff6cb55555f75c9ea28c91db5
5
5
  SHA512:
6
- metadata.gz: 6b8dcbff6d81a51b8ddb4883496c253d2165b997c02f623fa05944db8760528afde2a6d09a8514e8328027ea1112d3652f645069ad53276db342f7b9afc25c29
7
- data.tar.gz: fc75a7f00ab0d93401402cf3d19bee59e729963c64fc58488811e2069a11347ba76cf172bf5090fa8da2f9107b3c1c46ec3ff0f9c60e1c1986a3e3a1bc628e25
6
+ metadata.gz: 2ea307ac3967b10f1486e1ce015abe888680b83d62a8ea5e00a701f5637d3d0e2df376a1fa43e6c0693499c707c7f9b40cb3d2b5488fa244d830d247bd47b9f1
7
+ data.tar.gz: 633d4f45495ecd04e2f12187e0b6f3d8f9afb60757dc9607d34a1dff089be7f62d58921e935d5433cf1cf7817eb8496dfd02a57a5c8e2198d1ed615e969015f9
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+
7
+ notifications:
8
+ email:
9
+ - johnotander@gmail.com
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Email Format
2
2
 
3
- This gem uses the thorough email validation check used by the [email_regex](https://github.com/dougwig/email_regex) gem written by Doug Wiegley which "provides a valid email regex that conforms to most valid RFC edges cases (disallows backticks), and allows for a few illegal patterns that are in common use".
3
+ [![Build Status](https://travis-ci.org/johnotander/email_format.svg?branch=master)](https://travis-ci.org/johnotander/email_format)
4
+
5
+ This gem uses the thorough email validation implemented by the [email_regex](https://github.com/dougwig/email_regex) gem written by Doug Wiegley which "provides a valid email regex that conforms to most valid RFC edges cases (disallows backticks), and allows for a few illegal patterns that are in common use".
4
6
 
5
7
  ## Installation
6
8
 
@@ -20,11 +22,23 @@ Or install it yourself as:
20
22
 
21
23
  ## Usage
22
24
 
25
+ ### `EmailFormat` Module
26
+
27
+ There's a `valid?` method in the `EmailFormat` module that accepts an email as an argument:
28
+
29
+ ```ruby
30
+ require 'email_format'
31
+ EmailFormat.valid?('invalid_email') # => false
32
+ EmailFormat.valid?('valid@email.com') # => true
33
+ ```
34
+
35
+ ### `ActiveModel::Validations`
36
+
23
37
  Using it is as simple as using the `validates` keyword in your model:
24
38
 
25
39
  ```ruby
26
40
  class User < ActiveRecord::Base
27
-
41
+
28
42
  # ...
29
43
 
30
44
  validates :email, email_format: true
@@ -48,9 +62,7 @@ require 'email_format'
48
62
 
49
63
  class Awesome
50
64
  include ActiveModel::Validations
51
-
52
65
  attr_accessor :email
53
-
54
66
  validates :email, email_format: true
55
67
  end
56
68
 
data/Rakefile CHANGED
@@ -4,4 +4,4 @@ require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new
5
5
 
6
6
  task default: :spec
7
- task test: :spec
7
+ task test: :spec
data/lib/email_format.rb CHANGED
@@ -3,4 +3,8 @@ require "email_format/version"
3
3
  require "email_format/email_format_validator"
4
4
 
5
5
  module EmailFormat
6
+
7
+ def self.valid?(email)
8
+ !!(email =~ EmailRegex::EMAIL_ADDRESS_REGEX)
9
+ end
6
10
  end
@@ -1,6 +1,6 @@
1
1
  class EmailFormatValidator < ActiveModel::EachValidator
2
2
  def validate_each(record, attribute, value)
3
- unless value =~ EmailRegex::EMAIL_ADDRESS_REGEX
3
+ unless EmailFormat.valid?(value)
4
4
  record.errors[attribute] << (options[:message] || "is invalid")
5
5
  end
6
6
  end
@@ -1,3 +1,3 @@
1
1
  module EmailFormat
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -18,7 +18,12 @@ describe EmailFormatValidator do
18
18
 
19
19
  context "with invalid emails" do
20
20
 
21
- let(:invalid_emails) { %w(invalid_email@ another_invalid_email@@email.email) }
21
+ let(:invalid_emails) { %w(invalid_email@
22
+ another_invalid_email@@email.email
23
+ invalid
24
+ bad@email@here
25
+ @bad_email
26
+ another@bad,email) }
22
27
 
23
28
  it "shouldn't be happy" do
24
29
  invalid_emails.each do |email|
@@ -27,4 +32,17 @@ describe EmailFormatValidator do
27
32
  end
28
33
  end
29
34
  end
30
- end
35
+
36
+ context "with allow_blank: true" do
37
+
38
+ let(:fake_model) { FakeModelWithBlankEmail.new }
39
+ let(:blank_emails) { ['', nil, ' '] }
40
+
41
+ it "should allow blank emails" do
42
+ blank_emails.each do |blank_email|
43
+ fake_model.email = blank_email
44
+ expect(fake_model.valid?).to be_true
45
+ end
46
+ end
47
+ end
48
+ end
data/spec/spec_helper.rb CHANGED
@@ -14,4 +14,12 @@ class FakeModel
14
14
  attr_accessor :email
15
15
 
16
16
  validates :email, email_format: true
17
- end
17
+ end
18
+
19
+ class FakeModelWithBlankEmail
20
+ include ActiveModel::Validations
21
+
22
+ attr_accessor :email
23
+
24
+ validates :email, email_format: true, allow_blank: true
25
+ end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - johnotander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-06 00:00:00.000000000 Z
11
+ date: 2014-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activemodel
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: email_regex
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Validates the email format.
@@ -87,7 +87,8 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
90
+ - ".gitignore"
91
+ - ".travis.yml"
91
92
  - Gemfile
92
93
  - LICENSE.txt
93
94
  - README.md
@@ -108,20 +109,21 @@ require_paths:
108
109
  - lib
109
110
  required_ruby_version: !ruby/object:Gem::Requirement
110
111
  requirements:
111
- - - '>='
112
+ - - ">="
112
113
  - !ruby/object:Gem::Version
113
114
  version: '0'
114
115
  required_rubygems_version: !ruby/object:Gem::Requirement
115
116
  requirements:
116
- - - '>='
117
+ - - ">="
117
118
  - !ruby/object:Gem::Version
118
119
  version: '0'
119
120
  requirements: []
120
121
  rubyforge_project:
121
- rubygems_version: 2.0.7
122
+ rubygems_version: 2.2.2
122
123
  signing_key:
123
124
  specification_version: 4
124
125
  summary: Validates the email format with the email_regex gem.
125
126
  test_files:
126
127
  - spec/email_format_validator_spec.rb
127
128
  - spec/spec_helper.rb
129
+ has_rdoc: