email_format 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 694dda2a4da9653812f143d3d8064224ee367fca
4
+ data.tar.gz: 7ff1b8bd68f1ae304284dcc3500ae44dea2220a9
5
+ SHA512:
6
+ metadata.gz: 6b8dcbff6d81a51b8ddb4883496c253d2165b997c02f623fa05944db8760528afde2a6d09a8514e8328027ea1112d3652f645069ad53276db342f7b9afc25c29
7
+ data.tar.gz: fc75a7f00ab0d93401402cf3d19bee59e729963c64fc58488811e2069a11347ba76cf172bf5090fa8da2f9107b3c1c46ec3ff0f9c60e1c1986a3e3a1bc628e25
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in email_format.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 johnotander
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # Email Format
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".
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'email_format'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install email_format
20
+
21
+ ## Usage
22
+
23
+ Using it is as simple as using the `validates` keyword in your model:
24
+
25
+ ```ruby
26
+ class User < ActiveRecord::Base
27
+
28
+ # ...
29
+
30
+ validates :email, email_format: true
31
+
32
+ # ...
33
+
34
+ end
35
+ ```
36
+
37
+ Now the email attribute will be validated accordingly:
38
+
39
+ ```ruby
40
+ User.new('valid@email.com').valid? # => true
41
+ User.new('invalid_email@@').valid? # => false
42
+ ```
43
+
44
+ Also, the model in question doesn't need to inherit from ActiveRecord::Base, you only need to `include ActiveModel::Validations` in your class:
45
+
46
+ ```ruby
47
+ require 'email_format'
48
+
49
+ class Awesome
50
+ include ActiveModel::Validations
51
+
52
+ attr_accessor :email
53
+
54
+ validates :email, email_format: true
55
+ end
56
+
57
+ awesome = Awesome.new
58
+
59
+ awesome.email = "valid@email.com"
60
+ awesome.valid? # => true
61
+
62
+ awesome.email = "invalid_email"
63
+ awesome.valid? # => false
64
+ ```
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task default: :spec
7
+ task test: :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'email_format/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "email_format"
8
+ spec.version = EmailFormat::VERSION
9
+ spec.authors = ["johnotander"]
10
+ spec.email = ["johnotander@gmail.com"]
11
+ spec.description = %q{Validates the email format.}
12
+ spec.summary = %q{Validates the email format with the email_regex gem.}
13
+ spec.homepage = "https://github.com/johnotander/email_format"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+
25
+ spec.add_dependency "activemodel"
26
+ spec.add_dependency "email_regex"
27
+ end
@@ -0,0 +1,6 @@
1
+ require "email_regex"
2
+ require "email_format/version"
3
+ require "email_format/email_format_validator"
4
+
5
+ module EmailFormat
6
+ end
@@ -0,0 +1,7 @@
1
+ class EmailFormatValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ unless value =~ EmailRegex::EMAIL_ADDRESS_REGEX
4
+ record.errors[attribute] << (options[:message] || "is invalid")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module EmailFormat
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe EmailFormatValidator do
4
+
5
+ let(:fake_model) { FakeModel.new }
6
+
7
+ context "with valid emails" do
8
+
9
+ let(:valid_emails) { %w(valid@email.com another.valid@email.email.net) }
10
+
11
+ it "should be happy" do
12
+ valid_emails.each do |email|
13
+ fake_model.email = email
14
+ expect(fake_model.valid?).to be_true
15
+ end
16
+ end
17
+ end
18
+
19
+ context "with invalid emails" do
20
+
21
+ let(:invalid_emails) { %w(invalid_email@ another_invalid_email@@email.email) }
22
+
23
+ it "shouldn't be happy" do
24
+ invalid_emails.each do |email|
25
+ fake_model.email = email
26
+ expect(fake_model.valid?).to be_false
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec'
4
+ require 'active_model'
5
+ require 'email_format'
6
+
7
+ RSpec.configure do |config|
8
+ config.color_enabled = true
9
+ end
10
+
11
+ class FakeModel
12
+ include ActiveModel::Validations
13
+
14
+ attr_accessor :email
15
+
16
+ validates :email, email_format: true
17
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: email_format
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - johnotander
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activemodel
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: email_regex
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Validates the email format.
84
+ email:
85
+ - johnotander@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - email_format.gemspec
96
+ - lib/email_format.rb
97
+ - lib/email_format/email_format_validator.rb
98
+ - lib/email_format/version.rb
99
+ - spec/email_format_validator_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/johnotander/email_format
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.0.7
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Validates the email format with the email_regex gem.
125
+ test_files:
126
+ - spec/email_format_validator_spec.rb
127
+ - spec/spec_helper.rb