ruby_email 0.1.5 → 0.1.6

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: cb0c82b4013b33854d71d9f434b3b2c74ec633a5
4
- data.tar.gz: 515ce7795e8f86984d09651a2adbaa8f0f44a38d
3
+ metadata.gz: 992dcd485d48991c1e09827fefd0f396ba93099c
4
+ data.tar.gz: f4c6e74256ad4f147bc32a4b99221424f85bb8b2
5
5
  SHA512:
6
- metadata.gz: 5c8c48fc64c5eb10fcb2e4d312ff78e159774c4fe03c77c042cb490b4ccdd548a04dae0763d83b7dd2756ad82a0d0d68dbd9ae444a03a81579ba8432a21c3ec3
7
- data.tar.gz: aae07e1346703f0b7ae00031c52bc706ad845e2889a46525a095a27f7d454b9106cc5669d2c6a5c384b0eb1765d740623b2e6133441838a1b17bcf924d76638e
6
+ metadata.gz: d75c0b231723e17f9eeec5c34b8fb898f29c88c2b3a84ad72da406e2c426c7ce2d40ae1863bfd14485a49435d99e3e2dcbb0f17f2d594859c326bbd08a65cd9a
7
+ data.tar.gz: 0477f20e580eb1165a69bcc89b31c203e1fe564faadc2f60be644eb72316ea0e435b9dee5474163285c54020d89d578f765e0e963eb0291cbb70fb6f04d0da63
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ v0.1.6
2
+ * Break compatibility (100%)
3
+ * Improve architecture
4
+ * Rfc5322 designed as it
5
+ * Rfc5322 and Rfc5322::Public are now Classes (instead of modules)
6
+ * Core is now an Abstract, completed by adding the REGEXP constant in it's
7
+ children
8
+ * Update unitary tests
9
+ * Add some documentation
10
+
1
11
  v0.1.5
2
12
  * Split into files each feature (core, public, f/string)
3
13
 
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # A RFC compliant Email validator
2
2
 
3
- Compliant to the [rfc 5322](http://www.ietf.org/rfc/rfc5322.txt) standard.
3
+ What is an [email address](https://en.wikipedia.org/wiki/Email_address) ?
4
+
5
+ - Compliant to the [rfc 5322](https://tools.ietf.org/html/rfc5322) standard.
6
+ - To do [rfc 6530](https://tools.ietf.org/html/rfc6530).
7
+
4
8
 
5
9
  ## Installation
6
10
 
@@ -20,17 +24,26 @@ gem 'ruby_email'
20
24
  ```ruby
21
25
  require 'ruby_email'
22
26
 
27
+ # Pure Rfc5322
28
+ RubyEmail::Rfc322.validates? "toto@tata" # => true
29
+ RubyEmail::Rfc322.match "toto@tata" # => #<MatchData "toto@tata" local:"toto" domain:"tata">
30
+ RubyEmail::Rfc322.validates? "toto" # => false
31
+ RubyEmail::Rfc322.match "toto" # => nil
32
+
33
+ # Rfc5322 + Internet basic usage
34
+ RubyEmail::Rfc322::Public.validates? "toto@tata.com" # => true
35
+ RubyEmail::Rfc322::Public.match "toto@tata.com" # => #<MatchData "toto@tata" local:"toto" domain:"tata.com">
36
+
37
+ # Rfc5322 Strings
38
+ require 'ruby_email/rfc5322/string'
23
39
  "local@domain".is_email? # => true
24
- RubyEmail.validates? "toto@tata" # => true
25
- RubyEmail.match "toto@tata" # => #<MatchData "toto@tata" local:"toto" domain:"tata">
26
40
  "local".is_email? # => false
27
- RubyEmail.validates? "toto" # => false
28
- RubyEmail.match "toto" # => nil
29
41
 
42
+ # Rfc5322 Strings + Internet basic usage
43
+ require 'ruby_email/rfc5322/public/string'
30
44
  "local@domain.root".is_public_email? # => true
31
45
  "local@domain".is_public_email? # => false
32
- RubyEmail::Public.validates? "toto@tata.com" # => true
33
- RubyEmail::Public.match "toto@tata.com" # => #<MatchData "toto@tata" local:"toto" domain:"tata.com">
46
+
34
47
  ```
35
48
 
36
49
 
@@ -38,8 +51,8 @@ RubyEmail::Public.match "toto@tata.com" # => #<MatchData "toto@tata" local:"toto
38
51
 
39
52
  ```ruby
40
53
  class Model < ActiveRecord::Base
41
- # validates :email, format: RubyEmail::REGEXP # valid on an intranet ...
42
- validates :email, format: RubyEmail::Public::REGEXP
54
+ # validates :email, format: RubyEmail::Rfc322::REGEXP # valid on an intranet ...
55
+ validates :email, format: RubyEmail::Rfc322::Public::REGEXP
43
56
  end
44
57
  ```
45
58
 
@@ -1,37 +1,28 @@
1
- # http://www.ietf.org/rfc/rfc5322.txt
2
1
  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
2
 
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
3
+ # Abstract class to inherit and complete by adding the REGEXP constant
4
+ class Core
5
+ # Check if the {::String} is a valid email.
6
+ # @param str [::String] string to match
7
+ # @raise [ArgumentError] if str is not a String
8
+ # @return [TrueClass or FalseClass]
9
+ def self.validates? str
10
+ !!match(str)
11
+ end
19
12
 
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
13
+ # Check if the string is a valid email and details how
14
+ # @param str [::String] string to match
15
+ # @raise [ArgumentError] if str is not a String
16
+ # @return [MatchData or NilClass] matched email with the keys "local" and "domain"
17
+ def self.match str
18
+ raise ArgumentError, "Cannot validate a `#{str.class}`. Only `String` can be." unless str.is_a?(String)
19
+ str.match regexp
20
+ end
28
21
 
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
22
+ # @return [Regexp] constant to erase in the children
23
+ def self.regexp
24
+ self::REGEXP
25
+ #raise NoMethodError, "Not implemented in #{self.class}"
35
26
  end
36
27
 
37
28
  end
@@ -1,5 +1,5 @@
1
1
  require_relative '../public'
2
2
 
3
3
  class String
4
- include RubyEmail::Public::String
4
+ include RubyEmail::Rfc5322::Public::String
5
5
  end
@@ -0,0 +1,21 @@
1
+ require_relative '../rfc5322'
2
+
3
+ module RubyEmail
4
+ class Rfc5322
5
+
6
+ # Internet realist version of {Rfc5322}. It requires a root domain.
7
+ class Public < Rfc5322
8
+ VALIDE = "(?<local>#{DOT_ATOM_TEXT})@(?<domain>#{DOT_ATOM_TEXT}\\.#{DOT_ATOM_TEXT})"
9
+ REGEXP = Regexp.new "\\A#{VALIDE}\\Z"
10
+
11
+ module String
12
+ # Check if the current [::String] instance is a valid email
13
+ # @return [TrueClass or FalseClass]
14
+ def is_public_email?
15
+ RubyEmail::Rfc5322::Public.validates? self
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ require_relative '../rfc5322'
2
+
3
+ class String
4
+ include RubyEmail::Rfc5322::String
5
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'core'
2
+
3
+ module RubyEmail
4
+
5
+ # http://www.ietf.org/rfc/rfc5322.txt
6
+ # The Rfc5322 designe an email with the format local@domain, wher local and
7
+ # domain are a string of US-ASCII characters, without some symboles.
8
+ class Rfc5322 < Core
9
+ # one valid character (not . because used to separe domains)
10
+ ATEXT = '([A-Za-z0-9!#\$%&\'*\+\-/=\?\^_`\{\}\|~])'
11
+ # a valid string
12
+ ATOM = "#{ATEXT}+"
13
+ # a valid string with subdomains, separated by dots
14
+ DOT_ATOM_TEXT = "(#{ATOM})(\\.#{ATOM})*"
15
+ # email grammar
16
+ VALIDE = "(?<local>#{DOT_ATOM_TEXT})@(?<domain>#{DOT_ATOM_TEXT})"
17
+ # regexp to validate complete email
18
+ REGEXP = Regexp.new "\\A#{VALIDE}\\Z"
19
+ module String
20
+ # Check if the current [::String] instance is a valid email
21
+ # @return [TrueClass or FalseClass]
22
+ def is_email?
23
+ RubyEmail::Rfc5322.validates? self
24
+ end
25
+ end
26
+ end
27
+
28
+ end
data/lib/ruby_email.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require_relative 'ruby_email/core'
2
- require_relative 'ruby_email/core/string'
3
2
 
4
- require_relative 'ruby_email/public'
5
- require_relative 'ruby_email/public/string'
3
+ require_relative 'ruby_email/rfc5322'
4
+
5
+ require_relative 'ruby_email/rfc5322/public'
6
+
7
+ #require_relative 'ruby_email/rfc5322/string'
8
+ #require_relative 'ruby_email/rfc5322/public/string'
data/ruby_email.gemspec CHANGED
@@ -9,9 +9,10 @@ Gem::Specification.new do |s|
9
9
  s.files = %w(
10
10
  lib/ruby_email.rb
11
11
  lib/ruby_email/core.rb
12
- lib/ruby_email/core/string.rb
13
- lib/ruby_email/public.rb
14
- lib/ruby_email/public/string.rb
12
+ lib/ruby_email/rfc5322.rb
13
+ lib/ruby_email/rfc5322/string.rb
14
+ lib/ruby_email/rfc5322/public.rb
15
+ lib/ruby_email/rfc5322/public/string.rb
15
16
 
16
17
  README.md
17
18
  CHANGELOG
data/test/unit_test.rb CHANGED
@@ -7,65 +7,72 @@ require_relative '../lib/ruby_email'
7
7
  class TestRubyEmail < Test::Unit::TestCase
8
8
 
9
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")
10
+ assert RubyEmail::Rfc5322.validates?("toto@toto")
11
+ assert RubyEmail::Rfc5322.validates?("toto@toto.toto")
12
+ assert RubyEmail::Rfc5322.validates?("toto@toto.toto.toto")
13
+ assert RubyEmail::Rfc5322.validates?("toto@toto.toto.toto.toto")
14
14
  end
15
15
 
16
16
  def test_simple_false
17
- assert !RubyEmail.validates?("t")
18
- assert !RubyEmail.validates?("t@")
19
- assert !RubyEmail.validates?("@t")
17
+ assert !RubyEmail::Rfc5322.validates?("t")
18
+ assert !RubyEmail::Rfc5322.validates?("t@")
19
+ assert !RubyEmail::Rfc5322.validates?("@t")
20
20
  end
21
21
 
22
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")
23
+ assert RubyEmail::Rfc5322.validates?("i'am%toto@here")
24
+ assert RubyEmail::Rfc5322.validates?("ich-bin-toto@___")
25
+ assert RubyEmail::Rfc5322.validates?("arthur+spam@mail.com")
26
26
  end
27
27
 
28
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")
29
+ assert !RubyEmail::Rfc5322.validates?("i have @ some things")
30
+ assert !RubyEmail::Rfc5322.validates?("toto;toto@toto;toto")
31
+ assert !RubyEmail::Rfc5322.validates?("toto,toto@toto,toto")
32
+ assert !RubyEmail::Rfc5322.validates?("toto()toto@toto()toto")
33
+ assert !RubyEmail::Rfc5322.validates?("toto[]toto@toto[]toto")
34
+ assert !RubyEmail::Rfc5322.validates?("toto:toto@toto:toto")
35
+ assert !RubyEmail::Rfc5322.validates?("toto<>toto@toto<>toto")
36
+ assert !RubyEmail::Rfc5322.validates?("toto\\toto@toto\\toto")
37
+ assert !RubyEmail::Rfc5322.validates?("toto\"toto@toto\"toto")
38
38
  end
39
39
 
40
40
  def test_match
41
- m = RubyEmail.match "toto@toto.toto.toto.toto"
41
+ m = RubyEmail::Rfc5322.match "toto@toto.toto.toto.toto"
42
42
  assert m.names & %w(local domain)
43
43
  assert_equal "toto", m["local"]
44
44
  assert_equal "toto.toto.toto.toto", m["domain"]
45
45
  end
46
46
 
47
47
  def test_string
48
- assert !"toto".is_email?
48
+ assert_raise { "toto@toto".is_email? }
49
+ require_relative '../lib/ruby_email/rfc5322/string'
49
50
  assert "toto@toto".is_email?
51
+ assert !"toto".is_email?
50
52
  end
51
53
 
52
54
  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 }
55
+ assert_raise { RubyEmail::Rfc5322.match 1 }
56
+ assert_raise { RubyEmail::Rfc5322.validates? 1.0 }
57
+ assert_raise { RubyEmail::Rfc5322.validates? /toto/ }
58
+ assert_raise { RubyEmail::Rfc5322.validates? :ok }
59
+ assert_raise { RubyEmail::Rfc5322.validates? Class }
58
60
  end
59
61
 
60
62
  end
61
63
 
62
64
  class TestRubyEmailPublic < Test::Unit::TestCase
63
65
  def test_simpe
64
- assert RubyEmail::Public.validates?("toto@toto.toto")
65
- assert RubyEmail::Public.validates?("toto@toto.toto.toto")
66
- assert RubyEmail::Public.validates?("toto@toto.toto.toto.toto")
67
- assert !RubyEmail::Public.validates?("toto@toto")
68
- assert RubyEmail::Public.match("toto@toto.toto")
66
+ assert RubyEmail::Rfc5322::Public.validates?("toto@toto.toto")
67
+ assert RubyEmail::Rfc5322::Public.validates?("toto@toto.toto.toto")
68
+ assert RubyEmail::Rfc5322::Public.validates?("toto@toto.toto.toto.toto")
69
+ assert !RubyEmail::Rfc5322::Public.validates?("toto@toto")
70
+ assert RubyEmail::Rfc5322::Public.match("toto@toto.toto")
71
+ end
72
+
73
+ def test_string
74
+ assert_raise { "toto@toto.toto".is_public_email? }
75
+ require_relative '../lib/ruby_email/rfc5322/public/string'
69
76
  assert "toto@toto.toto".is_public_email?
70
77
  assert !"toto@toto".is_public_email?
71
78
  end
data/version CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nephos (poulet_a)
@@ -61,9 +61,10 @@ files:
61
61
  - Rakefile
62
62
  - lib/ruby_email.rb
63
63
  - lib/ruby_email/core.rb
64
- - lib/ruby_email/core/string.rb
65
- - lib/ruby_email/public.rb
66
- - lib/ruby_email/public/string.rb
64
+ - lib/ruby_email/rfc5322.rb
65
+ - lib/ruby_email/rfc5322/public.rb
66
+ - lib/ruby_email/rfc5322/public/string.rb
67
+ - lib/ruby_email/rfc5322/string.rb
67
68
  - ruby_email.gemspec
68
69
  - test/unit_test.rb
69
70
  - version
metadata.gz.sig CHANGED
Binary file
@@ -1,5 +0,0 @@
1
- require_relative '../core'
2
-
3
- class String
4
- include RubyEmail::String
5
- end
@@ -1,43 +0,0 @@
1
- require_relative 'core'
2
-
3
- # http://www.ietf.org/rfc/rfc5322.txt
4
- module RubyEmail
5
-
6
- # Only valid on the public internet. "toto@toto" is not valid, but "toto@toto.toto" is good
7
- module Public
8
- # one valid character (not . because used to separe domains)
9
- ATEXT = '([A-Za-z0-9!#\$%&\'*\+\-/=\?\^_`\{\}\|~])'
10
- ATOM = "#{ATEXT}+"
11
- DOT_ATOM_TEXT = "(#{ATOM})(\\.#{ATOM})*"
12
- VALIDE = "(?<local>#{DOT_ATOM_TEXT})@(?<domain>#{DOT_ATOM_TEXT}\\.#{DOT_ATOM_TEXT})"
13
- REGEXP = Regexp.new "\\A#{VALIDE}\\Z"
14
-
15
- # Check if the {::String} is a valid email on internet
16
- # @param str [::String] string to match
17
- # @raise [ArgumentError] if str is not a String
18
- # @return [TrueClass or FalseClass]
19
- def self.validates? str
20
- !!match(str)
21
- end
22
-
23
- # Check if the string is a valid email on internet and details how
24
- # @param str [::String] string to match
25
- # @raise [ArgumentError] if str is not a String
26
- # @return [MatchData or NilClass] matched email with the keys "local" and "domain"
27
- def self.match str
28
- raise ArgumentError, "Cannot validate a `#{str.class}`. Only `String` can be." unless str.is_a?(String)
29
- str.match(REGEXP)
30
- end
31
-
32
- # included by {::String}
33
- module String
34
- # Check if the current [::String] instance is a valid email on internet
35
- # @return [TrueClass or FalseClass]
36
- def is_public_email?
37
- RubyEmail::Public.validates? self
38
- end
39
- end
40
-
41
- end
42
-
43
- end