walid 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: ac5cf865f56a068687d16058df49873456f98406
4
+ data.tar.gz: 25088f560295b0abaf1b167eee361e3c6de8f8d8
5
+ SHA512:
6
+ metadata.gz: 666bb224a3b81d2a6f18a77067768294b35e2daf6abbce4adf45a5ebe9d30b48f92cc29f736a9c9ff97bf88a36bde145cb68dbac002fc754f20fec2e453d92dc
7
+ data.tar.gz: 860f68a63afb2603204c1bc79e1f4aa283683b8f5715fc90b431e36f72dc75ac373708139a1795b8935a0cf239b4a1caba9d68ed08a86e00fa217ba48ada102e
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.overcommit.yml ADDED
@@ -0,0 +1,31 @@
1
+ # Use this file to configure the Overcommit hooks you wish to use. This will
2
+ # extend the default configuration defined in:
3
+ # https://github.com/causes/overcommit/blob/master/config/default.yml
4
+ #
5
+ # At the topmost level of this YAML file is a key representing type of hook
6
+ # being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
7
+ # customize each hook, such as whether to only run it on certain files (via
8
+ # `include`), whether to only display output if it fails (via `quiet`), etc.
9
+ #
10
+ # For a complete list of hooks, see:
11
+ # https://github.com/causes/overcommit/tree/master/lib/overcommit/hook
12
+ #
13
+ # For a complete list of options that you can use to customize hooks, see:
14
+ # https://github.com/causes/overcommit#configuration
15
+ #
16
+ # Uncomment the following lines to make the configuration take effect.
17
+
18
+ #PreCommit:
19
+ # Rubocop:
20
+ # on_warn: fail # Treat all warnings as failures
21
+ #
22
+ # TrailingWhitespace:
23
+ # exclude:
24
+ # - '**/db/structure.sql' # Ignore trailing whitespace in generated files
25
+ #
26
+ #PostCheckout:
27
+ # ALL: # Special hook name that customizes all hooks of this type
28
+ # quiet: true # Change all post-checkout hooks to only display output on failure
29
+ #
30
+ # IndexTags:
31
+ # enabled: true # Generate a tags file with `ctags` each time HEAD changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in walid.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Łukasz Niemier
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,31 @@
1
+ # Walid
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'walid'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install walid
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/walid/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/*_test.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task default: :test
data/lib/walid.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'parslet'
2
+
3
+ require 'walid/version'
4
+ require 'walid/parser'
@@ -0,0 +1,31 @@
1
+ module Walid
2
+ # Validate email adresses
3
+ #
4
+ # Validate email addresses based on RFC5321 and RFC5322 (with updates)
5
+ #
6
+ # Options:
7
+ #
8
+ # - quotes (default: false) - allow quotings in local part (i.e. lo."lol")
9
+ # - utf (default: false) - allow UTF-8 characters in address
10
+ # - ip (default: false) - allow IP addresses as domain part
11
+ class EmailValidator < ActiveModel::EachValidator
12
+ def validate_each(record, attribute, value)
13
+ @local, _, @domain = value.rpartition('@')
14
+
15
+ record.errors.add(attribute, 'Invalid email format.') if check_local
16
+ end
17
+
18
+ private
19
+
20
+ def check_local
21
+ @lparser ||= Parser::EmailLocalPart.new
22
+
23
+ parsed = @lparser.parse(@local)
24
+ parts = parsed.map(&:keys).unique
25
+
26
+ !(options[:quotes] && parts.include?(:q))
27
+ rescue
28
+ false
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,6 @@
1
+ module Walid
2
+ module Parser
3
+ autoload :Domain, 'walid/parser/domain'
4
+ autoload :EmailLocalPart, 'walid/parser/email_local_part'
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ module Walid
2
+ module Parser
3
+ class Domain < Parslet::Parser
4
+ rule(:domain) { (label | domain) >> str('.') >> label }
5
+ rule(:label) do
6
+ match('[[:alpha:]]') >> (ldh_str.maybe >> let_dig).maybe
7
+ end
8
+ rule(:let_dig) { match('[[:alnum:]]') }
9
+
10
+ root(:domain)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ require 'parslet'
2
+
3
+ module Walid
4
+ module Parser
5
+ # Parse local part of email address
6
+ class EmailLocalPart < Parslet::Parser
7
+ rule(:local_part) { dot_string | quoted_string }
8
+
9
+ rule(:dot_string) { string >> (str('.') >> string).repeat(0) }
10
+
11
+ rule(:string) { atom | quoted_string }
12
+
13
+ rule(:atom) { match('[\w+=-]').repeat(1).as(:a) }
14
+ rule(:quoted_string) do
15
+ str('"') >> q_content.repeat(0).as(:q) >> str('"')
16
+ end
17
+
18
+ rule(:q_content) { q_pair | q_text }
19
+
20
+ rule(:q_text) { match('\w') | str(' ') | match('[(),:;<>@\[\]]') }
21
+ rule(:q_pair) { str('\\') >> match(/[ \\]/) }
22
+
23
+ root(:local_part)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Walid
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'minitest'
2
+ require 'minitest/spec'
3
+ require 'minitest/pride'
data/walid.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'walid/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'walid'
8
+ spec.version = Walid::VERSION
9
+ spec.authors = ['Łukasz Niemier']
10
+ spec.email = ['lukasz@niemier.pl']
11
+ spec.summary = 'Extra ActiveRecord validators.'
12
+ spec.description = <<-DOC
13
+ Set of ActiveRecord validators for stuff like e-mails,
14
+ URIs, post codes, etc.
15
+ DOC
16
+ spec.homepage = ''
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0")
20
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'activemodel', '~> 4.1'
25
+ spec.add_dependency 'parslet', '~> 1.6.1'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.6'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'minitest', '~> 5.4.0'
30
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: walid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - "Łukasz Niemier"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: parslet
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 5.4.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 5.4.0
83
+ description: |2
84
+ Set of ActiveRecord validators for stuff like e-mails,
85
+ URIs, post codes, etc.
86
+ email:
87
+ - lukasz@niemier.pl
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".overcommit.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/walid.rb
99
+ - lib/walid/email_validator.rb
100
+ - lib/walid/parser.rb
101
+ - lib/walid/parser/domain.rb
102
+ - lib/walid/parser/email_local_part.rb
103
+ - lib/walid/version.rb
104
+ - test/test_helper.rb
105
+ - walid.gemspec
106
+ homepage: ''
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.1
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Extra ActiveRecord validators.
130
+ test_files:
131
+ - test/test_helper.rb