emailness 0.1.0.alpha.2 → 0.1.0.beta.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 +4 -4
- data/Gemfile +2 -1
- data/Gemfile.lock +19 -16
- data/README.md +67 -46
- data/bin/rspec +29 -0
- data/lib/emailness.rb +7 -0
- data/lib/emailness/validator.rb +10 -4
- data/lib/emailness/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5bce971c08e8dae66d610adc65c6987be3ec7f5a0f44bcc8d3fc8417a846f10
|
4
|
+
data.tar.gz: 17975c0103aa601c108cf23be39516fcea774d8fca5b9ab59377e28c7dcf5d3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36e9b7c4a2583f39e8c4ffd70f41f12457e94a9867db713d3a344de1ffa90e4d372eda826aebb98a279b4ca4164f115ab981a22ee8b3a51aa44487a7ac3d5b2f
|
7
|
+
data.tar.gz: 3ce9373ff951b0651788db4c62ba9ee22bf5757eb1e62c84ef991fee7f3a660a1db239200e6317b30f25d15c2feb5dfe74485d10eb661b2d0f4b3a9a0f5e6657
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,51 +1,53 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
emailness (0.1.0)
|
4
|
+
emailness (0.1.0.beta.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
9
|
+
activemodel (6.1.3)
|
10
|
+
activesupport (= 6.1.3)
|
11
|
+
activesupport (6.1.3)
|
10
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
13
|
i18n (>= 1.6, < 2)
|
12
14
|
minitest (>= 5.1)
|
13
15
|
tzinfo (~> 2.0)
|
14
16
|
zeitwerk (~> 2.3)
|
15
|
-
binding_of_caller (0.
|
17
|
+
binding_of_caller (1.0.0)
|
16
18
|
debug_inspector (>= 0.0.1)
|
17
19
|
coderay (1.1.3)
|
18
|
-
concurrent-ruby (1.1.
|
19
|
-
debug_inspector (0.0
|
20
|
+
concurrent-ruby (1.1.8)
|
21
|
+
debug_inspector (1.0.0)
|
20
22
|
diff-lcs (1.4.4)
|
21
|
-
i18n (1.8.
|
23
|
+
i18n (1.8.9)
|
22
24
|
concurrent-ruby (~> 1.0)
|
23
25
|
interception (0.5)
|
24
26
|
method_source (1.0.0)
|
25
|
-
minitest (5.14.
|
26
|
-
pry (0.
|
27
|
+
minitest (5.14.4)
|
28
|
+
pry (0.14.0)
|
27
29
|
coderay (~> 1.1)
|
28
30
|
method_source (~> 1.0)
|
29
31
|
pry-rescue (1.5.2)
|
30
32
|
interception (>= 0.5)
|
31
33
|
pry (>= 0.12.0)
|
32
|
-
pry-stack_explorer (0.
|
33
|
-
binding_of_caller (~> 0
|
34
|
+
pry-stack_explorer (0.6.1)
|
35
|
+
binding_of_caller (~> 1.0)
|
34
36
|
pry (~> 0.13)
|
35
37
|
rake (12.3.3)
|
36
38
|
rspec (3.10.0)
|
37
39
|
rspec-core (~> 3.10.0)
|
38
40
|
rspec-expectations (~> 3.10.0)
|
39
41
|
rspec-mocks (~> 3.10.0)
|
40
|
-
rspec-core (3.10.
|
42
|
+
rspec-core (3.10.1)
|
41
43
|
rspec-support (~> 3.10.0)
|
42
|
-
rspec-expectations (3.10.
|
44
|
+
rspec-expectations (3.10.1)
|
43
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
46
|
rspec-support (~> 3.10.0)
|
45
|
-
rspec-mocks (3.10.
|
47
|
+
rspec-mocks (3.10.2)
|
46
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
47
49
|
rspec-support (~> 3.10.0)
|
48
|
-
rspec-support (3.10.
|
50
|
+
rspec-support (3.10.2)
|
49
51
|
tzinfo (2.0.4)
|
50
52
|
concurrent-ruby (~> 1.0)
|
51
53
|
zeitwerk (2.4.2)
|
@@ -54,13 +56,14 @@ PLATFORMS
|
|
54
56
|
ruby
|
55
57
|
|
56
58
|
DEPENDENCIES
|
59
|
+
activemodel
|
57
60
|
activesupport
|
58
61
|
emailness!
|
59
62
|
pry
|
60
63
|
pry-rescue
|
61
|
-
pry-stack_explorer
|
64
|
+
pry-stack_explorer
|
62
65
|
rake (~> 12.0)
|
63
66
|
rspec (~> 3.0)
|
64
67
|
|
65
68
|
BUNDLED WITH
|
66
|
-
2.
|
69
|
+
2.2.3
|
data/README.md
CHANGED
@@ -1,72 +1,93 @@
|
|
1
1
|
# Emailness
|
2
2
|
**Care very little about email validation**
|
3
3
|
|
4
|
-
Email validation with
|
4
|
+
Email validation with reasonable defaults so you can go care about more important things.
|
5
5
|
|
6
|
-
|
6
|
+
**Current status: Beta**
|
7
7
|
|
8
|
-
|
9
|
-
* Meant to match HTML5 email validation, happily deviates from RFC 5322
|
10
|
-
* Email tags with '+' are allowed
|
11
|
-
* Two consecutive dots ('..') are not
|
12
|
-
* Cares very little about most other things
|
8
|
+
[Test Cases](#test-cases) · [Usage](#usage)
|
13
9
|
|
10
|
+
### Goals
|
11
|
+
* Be trivially easy to use (and choose)
|
12
|
+
* Catch most common entry errors without being too strict
|
13
|
+
* Meant to match HTML5 email validation, *happily deviates* from RFC 5322
|
14
14
|
|
15
|
+
### Highlights of what is allowed/not allowed
|
16
|
+
* Allowed
|
17
|
+
* **Email tags** with '+'
|
18
|
+
* Not allowed
|
19
|
+
* Two consecutive dots: '..'
|
20
|
+
* Two at signs: '@@'
|
21
|
+
|
22
|
+
See the other [test cases →](#test-cases)
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Install
|
15
27
|
Add the gem:
|
16
28
|
|
17
|
-
```
|
29
|
+
```sh
|
18
30
|
bundle add emailness
|
19
31
|
```
|
20
32
|
|
21
|
-
|
33
|
+
### Use
|
34
|
+
In **Rails**, add it to your model:
|
22
35
|
|
23
|
-
```
|
24
|
-
|
25
|
-
```
|
26
|
-
|
27
|
-
And have a great day.
|
36
|
+
```ruby
|
37
|
+
# class Thing < ApplicationRecord
|
28
38
|
|
29
|
-
|
39
|
+
validates_email_format_of :email
|
30
40
|
|
31
|
-
|
41
|
+
```
|
32
42
|
|
33
|
-
|
34
|
-
The spec file is made on purpose to be simple.
|
43
|
+
Or, in **plain Ruby**, just use the module:
|
35
44
|
|
45
|
+
```ruby
|
46
|
+
Emailness.valid?("emailness@rubygems.org") # => true|false
|
36
47
|
```
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
jon+tag@hey.com ✔
|
42
|
-
email.me@ejemplo.com.ar ✔
|
43
|
-
jon@xn--acestunbeaudomaine-6ub.qc.ca ✔
|
44
|
-
johnson.o'jonathan@email.com ✔
|
45
|
-
fancytld@tld ✔
|
46
|
-
invalid (✘)
|
47
|
-
double..dot@gmail.com ✘
|
48
|
-
local@trailing-hyphen-.com ✘
|
49
|
-
leadingdigit@9domain.com ✘
|
50
|
-
white space@example.com ✘
|
51
|
-
"even_white_space\ escaped"@example.com ✘
|
52
|
-
email@@veryat.com ✘
|
53
|
-
no guarantees (✽)
|
54
|
-
jon(is_very_smart)@email.com ✘
|
55
|
-
send.to.my.server@[::1] ✘
|
56
|
-
who-needs-dns@[172.16.11.222] ✘
|
48
|
+
|
49
|
+
### Commit
|
50
|
+
```sh
|
51
|
+
git commit [--all] -m "$MODEL: Validate email address"
|
57
52
|
```
|
58
53
|
|
59
|
-
|
54
|
+
And have a great day.
|
60
55
|
|
61
|
-
|
56
|
+
## Test Cases
|
57
|
+
|
58
|
+
### Should be valid
|
59
|
+
| Case | Example | Result |
|
60
|
+
|----------------------------|------------------------------------------|-----------|
|
61
|
+
| Tag | `jon+tag@hey.com` | ✔ valid |
|
62
|
+
| 2nd level TLD | `email.me@ejemplo.com.ar` | ✔ valid |
|
63
|
+
| IDN (xn--) | `jon@xn--acestunbeaudomaine-6ub.qc.ca` | ✔ valid |
|
64
|
+
| Single apostrophe | `johnson.o'jonathan@email.com` | ✔ valid |
|
65
|
+
| Single TLD | `fancytld@tld` | ✔ valid |
|
66
|
+
|
67
|
+
### Should be invalid
|
68
|
+
| Case | Example | Result |
|
69
|
+
|----------------------------|------------------------------------------|-----------|
|
70
|
+
| Double dot | `double..dot@gmail.com` | ✘ invalid |
|
71
|
+
| Trailing hyphen in domain | `local@trailing-hyphen-.com` | ✘ invalid |
|
72
|
+
| Leading digit in domain | `leadingdigit@9domain.com` | ✘ invalid |
|
73
|
+
| White space | `white space@example.com` | ✘ invalid |
|
74
|
+
| Escaped white space | `"even_white_space escaped"@example.com` | ✘ invalid |
|
75
|
+
| Two at-signs | `email@@veryat.com` | ✘ invalid |
|
76
|
+
|
77
|
+
### No guarantees (undefined)
|
78
|
+
| Case | Example | Current |
|
79
|
+
|---------------|----------------------------------|-----------|
|
80
|
+
| Local comment | `jon(is_very_smart)@email.com` | ✘ invalid |
|
81
|
+
| IPv6 host | `send.to.my.server@[::1]` | ✘ invalid |
|
82
|
+
| IPv4 host | `who-needs-dns@[172.16.11.222]"` | ✘ invalid |
|
83
|
+
|
84
|
+
Those examples correspond to the
|
85
|
+
[spec file](https://github.com/joallard/emailness/blob/master/spec/emailness_spec.rb), which is simple on purpose.
|
86
|
+
|
87
|
+
*TODO: Update the tables automatically*
|
62
88
|
|
63
|
-
|
64
|
-
|
65
|
-
Either use it in Rails, or vanilla:
|
89
|
+
If you would like to add a case, simply open an issue or PR.
|
66
90
|
|
67
|
-
```
|
68
|
-
Emailness.valid?(email) # true/false
|
69
|
-
```
|
70
91
|
|
71
92
|
## Contributing
|
72
93
|
Are welcome:
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/lib/emailness.rb
CHANGED
@@ -18,5 +18,12 @@ module Emailness
|
|
18
18
|
true
|
19
19
|
end
|
20
20
|
|
21
|
+
def self.const_missing(name)
|
22
|
+
return super unless name == :Validator
|
23
|
+
require "emailness/validator"
|
24
|
+
|
25
|
+
defined?(Emailness::Validator) ? Emailness::Validator : super
|
26
|
+
end
|
27
|
+
|
21
28
|
class Error < StandardError; end
|
22
29
|
end
|
data/lib/emailness/validator.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
|
-
|
1
|
+
class Emailness::Validator < ActiveModel::EachValidator
|
2
2
|
def validate_each(record, attribute, value)
|
3
3
|
return if Emailness.valid?(value)
|
4
4
|
|
5
|
-
|
5
|
+
message = options[:message] || "is not a valid email"
|
6
|
+
record.errors.add(attribute, :invalid, message: message)
|
7
|
+
end
|
8
|
+
|
9
|
+
module HelperMethods
|
10
|
+
def validates_email_format_of(*attr_names)
|
11
|
+
validates_with ::Emailness::Validator, _merge_attributes(attr_names)
|
12
|
+
end
|
6
13
|
end
|
7
|
-
end
|
8
14
|
|
9
|
-
|
15
|
+
ActiveModel::Validations::HelperMethods.include(HelperMethods)
|
10
16
|
end
|
data/lib/emailness/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emailness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Allard
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- README.md
|
37
37
|
- Rakefile
|
38
38
|
- bin/console
|
39
|
+
- bin/rspec
|
39
40
|
- bin/setup
|
40
41
|
- emailness.gemspec
|
41
42
|
- lib/emailness.rb
|
@@ -49,7 +50,7 @@ metadata:
|
|
49
50
|
homepage_uri: https://github.com/joallard/emailness
|
50
51
|
source_code_uri: https://github.com/joallard/emailness
|
51
52
|
changelog_uri: https://github.com/joallard/emailness/blob/master/CHANGELOG.md
|
52
|
-
post_install_message:
|
53
|
+
post_install_message:
|
53
54
|
rdoc_options: []
|
54
55
|
require_paths:
|
55
56
|
- lib
|
@@ -64,8 +65,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
65
|
- !ruby/object:Gem::Version
|
65
66
|
version: 1.3.1
|
66
67
|
requirements: []
|
67
|
-
rubygems_version: 3.
|
68
|
-
signing_key:
|
68
|
+
rubygems_version: 3.2.3
|
69
|
+
signing_key:
|
69
70
|
specification_version: 4
|
70
71
|
summary: Care very little about email validation
|
71
72
|
test_files: []
|