emailness 0.1.0.alpha.2 → 0.1.0.beta.1

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
  SHA256:
3
- metadata.gz: 41fd5b6b799bfc5f93a7e4cbdbcf2c73900811ca580f04115858ffbd06e4e03c
4
- data.tar.gz: e9f4eb4fd8b10c9ea7e3810e6f6e0cbeb0cf02cba0abb87099bc688ba1ecab49
3
+ metadata.gz: f5bce971c08e8dae66d610adc65c6987be3ec7f5a0f44bcc8d3fc8417a846f10
4
+ data.tar.gz: 17975c0103aa601c108cf23be39516fcea774d8fca5b9ab59377e28c7dcf5d3a
5
5
  SHA512:
6
- metadata.gz: cad4e4961e2b076570a968a473a96796f9293ab68e7c89631717539e93e63325598f5099adf6ce047b14056e11a0b6ebdf2b4bae0bdb3209c5565a7270ec731a
7
- data.tar.gz: 616e222f01899aea2cd02fd3ef5e19cd784a4847374cbcd19e135eb50fe88a13bfdd136b28fe748f19b62d6ea3063a4143d9cdc67c5fc77ebe1779bc2c076a40
6
+ metadata.gz: 36e9b7c4a2583f39e8c4ffd70f41f12457e94a9867db713d3a344de1ffa90e4d372eda826aebb98a279b4ca4164f115ab981a22ee8b3a51aa44487a7ac3d5b2f
7
+ data.tar.gz: 3ce9373ff951b0651788db4c62ba9ee22bf5757eb1e62c84ef991fee7f3a660a1db239200e6317b30f25d15c2feb5dfe74485d10eb661b2d0f4b3a9a0f5e6657
data/Gemfile CHANGED
@@ -10,4 +10,5 @@ gem "pry"
10
10
  gem "pry-rescue"
11
11
  gem "pry-stack_explorer"
12
12
 
13
- gem "activesupport"
13
+ gem "activesupport", require: "active_support"
14
+ gem "activemodel", require: "active_model"
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
- activesupport (6.1.0)
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.8.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.7)
19
- debug_inspector (0.0.3)
20
+ concurrent-ruby (1.1.8)
21
+ debug_inspector (1.0.0)
20
22
  diff-lcs (1.4.4)
21
- i18n (1.8.5)
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.2)
26
- pry (0.13.1)
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.5.1)
33
- binding_of_caller (~> 0.7)
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.0)
42
+ rspec-core (3.10.1)
41
43
  rspec-support (~> 3.10.0)
42
- rspec-expectations (3.10.0)
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.0)
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.0)
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 (~> 0.5.1)
64
+ pry-stack_explorer
62
65
  rake (~> 12.0)
63
66
  rspec (~> 3.0)
64
67
 
65
68
  BUNDLED WITH
66
- 2.1.4
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 sensible defaults so you can go care about more important things.
4
+ Email validation with reasonable defaults so you can go care about more important things.
5
5
 
6
- ***TODO: The Rails validator isn't finished yet.***
6
+ **Current status: Beta**
7
7
 
8
- * Strives to be trivially easy to choose and use
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 &rarr;](#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
- Add it to your model:
33
+ ### Use
34
+ In **Rails**, add it to your model:
22
35
 
23
- ```
24
- validates_emailness_of :email
25
- ```
26
-
27
- And have a great day.
36
+ ```ruby
37
+ # class Thing < ApplicationRecord
28
38
 
29
- *If this gem is what you needed but had any hesitation or cognitive load in choosing it, please let me know!*
39
+ validates_email_format_of :email
30
40
 
31
- ---
41
+ ```
32
42
 
33
- ## Test cases
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
- $ rspec
38
-
39
- Emailness::Validator
40
- valid (✔)
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
- *TODO: Update this automatically*
54
+ And have a great day.
60
55
 
61
- If you would like to add a case, simply open an issue or PR.
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
- ## Usage
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
@@ -1,10 +1,16 @@
1
- module Emailness::Validator < ActiveModel::EachValidator
1
+ class Emailness::Validator < ActiveModel::EachValidator
2
2
  def validate_each(record, attribute, value)
3
3
  return if Emailness.valid?(value)
4
4
 
5
- record.errors.add attribute, (options[:message] || "is not a valid email")
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
- if defined?(ActiveRecord::Base)
15
+ ActiveModel::Validations::HelperMethods.include(HelperMethods)
10
16
  end
@@ -1,4 +1,4 @@
1
1
  module Emailness
2
- VERSION = "0.1.0.alpha.2"
2
+ VERSION = "0.1.0.beta.1"
3
3
  # then `rake release`
4
4
  end
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.alpha.2
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: 2020-12-18 00:00:00.000000000 Z
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.1.4
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: []