ruby_email 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG +14 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +13 -0
- data/README.md +29 -0
- data/Rakefile +16 -0
- data/lib/ruby_email.rb +42 -0
- data/ruby_email.gemspec +34 -0
- data/test/unit_test.rb +60 -0
- data/version +1 -0
- data.tar.gz.sig +0 -0
- metadata +91 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 695c3ef1a1b8f15a41b409e40c21a9faf29916cf
|
4
|
+
data.tar.gz: 9e4ca4b2e7dd6e295e6e6e883d1873a1b4adbda4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c16f25b5502ac66803ee478512a8e917ab9701c262a2ff6029a126b0cc63803ded73d6fb34bf867a7fc1534e0597742e69145064426a589d8a0715df00d60798
|
7
|
+
data.tar.gz: 9be99178fe6a3b6bf55e5ae39fcd02a53fcb66347845d68bbfaf5bccd0a178593a05e84277f7618f4ab185d7418eee5299628f5067289222052d0874ad8ef9a5
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/CHANGELOG
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
v0.1.3
|
2
|
+
* Rename the gem to be standard compliant
|
3
|
+
|
4
|
+
v0.1.2
|
5
|
+
* Add documentation
|
6
|
+
|
7
|
+
v0.1.1
|
8
|
+
* Fix readme and changelog
|
9
|
+
|
10
|
+
v0.1
|
11
|
+
* Initialize git
|
12
|
+
* Create regexp and basic helpers
|
13
|
+
* Gemfile and dependancies
|
14
|
+
* Create unitary test (cover 100%)
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# A RFC compliant Email validator
|
2
|
+
|
3
|
+
Compliant to the [rfc 5322](http://www.ietf.org/rfc/rfc5322.txt) standard.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require 'ruby_email'
|
9
|
+
|
10
|
+
"local@domain".is_email? # => true
|
11
|
+
RubyEmail.validates? "toto@tata" # => true
|
12
|
+
RubyEmail.match "toto@tata" # => #<MatchData "toto@tata" local:"toto" domain:"tata">
|
13
|
+
"local".is_email? # => false
|
14
|
+
RubyEmail.validates? "toto" # => false
|
15
|
+
RubyEmail.match "toto" # => nil
|
16
|
+
```
|
17
|
+
|
18
|
+
## Unitary tests
|
19
|
+
|
20
|
+
```sh
|
21
|
+
rake test
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributes !
|
25
|
+
|
26
|
+
Find a bug ? Want a new feature ?
|
27
|
+
Create a clear pull request and we'll see :)
|
28
|
+
|
29
|
+
- Nephos (poulet_a)
|
data/Rakefile
ADDED
data/lib/ruby_email.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# http://www.ietf.org/rfc/rfc5322.txt
|
2
|
+
module RubyEmail
|
3
|
+
# one valid character (not . because used to separe domains)
|
4
|
+
ATEXT = '([A-Za-z0-9!#\$%&\'*\+\-/=\?\^_`\{\}\|~])'
|
5
|
+
ATOM = "#{ATEXT}+"
|
6
|
+
DOT_ATOM_TEXT = "(#{ATOM})(\\.#{ATOM})*"
|
7
|
+
# email grammar
|
8
|
+
VALIDE = "(?<local>#{DOT_ATOM_TEXT})@(?<domain>#{DOT_ATOM_TEXT})"
|
9
|
+
# regexp to validate complete email
|
10
|
+
REGEXP = Regexp.new "\\A#{VALIDE}\\Z"
|
11
|
+
|
12
|
+
# Check if the {::String} is a valid email
|
13
|
+
# @param str [::String] string to match
|
14
|
+
# @raise [ArgumentError] if str is not a String
|
15
|
+
# @return [TrueClass or FalseClass]
|
16
|
+
def self.validates? str
|
17
|
+
!!match(str)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Check if the string is a valid email and details how
|
21
|
+
# @param str [::String] string to match
|
22
|
+
# @raise [ArgumentError] if str is not a String
|
23
|
+
# @return [MatchData or NilClass] matched email with the keys "local" and "domain"
|
24
|
+
def self.match str
|
25
|
+
raise ArgumentError, "Cannot validate a `#{str.class}`. Only `String` can be." unless str.is_a?(String)
|
26
|
+
str.match(REGEXP)
|
27
|
+
end
|
28
|
+
|
29
|
+
# included by {::String}
|
30
|
+
module String
|
31
|
+
# Check if the current [::String] instance is a valid email
|
32
|
+
# @return [TrueClass or FalseClass]
|
33
|
+
def is_email?
|
34
|
+
RubyEmail.validates? self
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
class String
|
41
|
+
include RubyEmail::String
|
42
|
+
end
|
data/ruby_email.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'ruby_email'
|
3
|
+
s.version = File.read("version")
|
4
|
+
s.date = Time.now.getgm.to_s.split.first
|
5
|
+
s.summary = File.read("CHANGELOG").match(/^v[^\n]+\n((\t[^\n]+\n)+)/m)[1].split("\t").join
|
6
|
+
s.description = 'A RFC compliant email validator'
|
7
|
+
s.authors = ['Nephos (poulet_a)']
|
8
|
+
s.email = ['arthur.poulet@mailoo.org']
|
9
|
+
s.files = %w(
|
10
|
+
lib/ruby_email.rb
|
11
|
+
|
12
|
+
README.md
|
13
|
+
CHANGELOG
|
14
|
+
|
15
|
+
Rakefile
|
16
|
+
Gemfile
|
17
|
+
Gemfile.lock
|
18
|
+
ruby_email.gemspec
|
19
|
+
version
|
20
|
+
|
21
|
+
test/unit_test.rb
|
22
|
+
)
|
23
|
+
s.executables = %w(
|
24
|
+
)
|
25
|
+
s.homepage = 'https://github.com/Nephos/RubyEmail'
|
26
|
+
s.license = 'WTFPL'
|
27
|
+
|
28
|
+
s.cert_chain = ['certs/nephos.pem']
|
29
|
+
s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $0 =~ /gem\z/
|
30
|
+
|
31
|
+
# s.add_dependency 'nephos', '~> 1.0'
|
32
|
+
s.add_dependency 'nomorebeer', '~> 1.1'
|
33
|
+
|
34
|
+
end
|
data/test/unit_test.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
|
5
|
+
require_relative '../lib/ruby_email'
|
6
|
+
|
7
|
+
class TestRubyEmail < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def test_simple_true
|
10
|
+
assert RubyEmail.validates?("toto@toto")
|
11
|
+
assert RubyEmail.validates?("toto@toto.toto")
|
12
|
+
assert RubyEmail.validates?("toto@toto.toto.toto")
|
13
|
+
assert RubyEmail.validates?("toto@toto.toto.toto.toto")
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_simple_false
|
17
|
+
assert !RubyEmail.validates?("t")
|
18
|
+
assert !RubyEmail.validates?("t@")
|
19
|
+
assert !RubyEmail.validates?("@t")
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_plus_true
|
23
|
+
assert RubyEmail.validates?("i'am%toto@here")
|
24
|
+
assert RubyEmail.validates?("ich-bin-toto@___")
|
25
|
+
assert RubyEmail.validates?("arthur+spam@mail.com")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_plus_false
|
29
|
+
assert !RubyEmail.validates?("i have @ some things")
|
30
|
+
assert !RubyEmail.validates?("toto;toto@toto;toto")
|
31
|
+
assert !RubyEmail.validates?("toto,toto@toto,toto")
|
32
|
+
assert !RubyEmail.validates?("toto()toto@toto()toto")
|
33
|
+
assert !RubyEmail.validates?("toto[]toto@toto[]toto")
|
34
|
+
assert !RubyEmail.validates?("toto:toto@toto:toto")
|
35
|
+
assert !RubyEmail.validates?("toto<>toto@toto<>toto")
|
36
|
+
assert !RubyEmail.validates?("toto\\toto@toto\\toto")
|
37
|
+
assert !RubyEmail.validates?("toto\"toto@toto\"toto")
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_match
|
41
|
+
m = RubyEmail.match "toto@toto.toto.toto.toto"
|
42
|
+
assert m.names & %w(local domain)
|
43
|
+
assert_equal "toto", m["local"]
|
44
|
+
assert_equal "toto.toto.toto.toto", m["domain"]
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_string
|
48
|
+
assert !"toto".is_email?
|
49
|
+
assert "toto@toto".is_email?
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_exceptions
|
53
|
+
assert_raise { RubyEmail.match 1 }
|
54
|
+
assert_raise { RubyEmail.validates? 1.0 }
|
55
|
+
assert_raise { RubyEmail.validates? /toto/ }
|
56
|
+
assert_raise { RubyEmail.validates? :ok }
|
57
|
+
assert_raise { RubyEmail.validates? Class }
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
data/version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.3
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_email
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nephos (poulet_a)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRYwFAYDVQQDDA1hcnRo
|
14
|
+
dXIucG91bGV0MRkwFwYKCZImiZPyLGQBGRYJY3J5cHRvbGFiMRMwEQYKCZImiZPy
|
15
|
+
LGQBGRYDbmV0MB4XDTE1MTAwMzIxNTQyMFoXDTE2MTAwMjIxNTQyMFowSDEWMBQG
|
16
|
+
A1UEAwwNYXJ0aHVyLnBvdWxldDEZMBcGCgmSJomT8ixkARkWCWNyeXB0b2xhYjET
|
17
|
+
MBEGCgmSJomT8ixkARkWA25ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
18
|
+
ggEBANn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|
+
date: 2016-04-29 00:00:00.000000000 Z
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: nomorebeer
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.1'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.1'
|
50
|
+
description: A RFC compliant email validator
|
51
|
+
email:
|
52
|
+
- arthur.poulet@mailoo.org
|
53
|
+
executables: []
|
54
|
+
extensions: []
|
55
|
+
extra_rdoc_files: []
|
56
|
+
files:
|
57
|
+
- CHANGELOG
|
58
|
+
- Gemfile
|
59
|
+
- Gemfile.lock
|
60
|
+
- README.md
|
61
|
+
- Rakefile
|
62
|
+
- lib/ruby_email.rb
|
63
|
+
- ruby_email.gemspec
|
64
|
+
- test/unit_test.rb
|
65
|
+
- version
|
66
|
+
homepage: https://github.com/Nephos/RubyEmail
|
67
|
+
licenses:
|
68
|
+
- WTFPL
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.5.1
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: "* Initialize git"
|
90
|
+
test_files: []
|
91
|
+
has_rdoc:
|
metadata.gz.sig
ADDED
Binary file
|