url_regexp 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +19 -0
- data/.travis.yml +2 -0
- data/Gemfile +3 -0
- data/README.md +20 -6
- data/Rakefile +6 -1
- data/lib/url_regexp/host.rb +2 -3
- data/lib/url_regexp/node.rb +1 -5
- data/lib/url_regexp/path.rb +21 -17
- data/lib/url_regexp/path_set.rb +32 -11
- data/lib/url_regexp/query.rb +7 -7
- data/lib/url_regexp/root.rb +7 -1
- data/lib/url_regexp/scheme.rb +4 -5
- data/lib/url_regexp/version.rb +3 -1
- data/lib/url_regexp.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f350bc548233f7897ce4c1e4c5c2905835454549
|
4
|
+
data.tar.gz: c3dc80a9fe0e099cc1ca8cb6b00fb8575616fe3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d0c2c0083914456cbf852a57ae904d2432063ef89fb1e1b335c79790180cfb181dcd50e5237f769d58ea8afde9a5834c0c2fe66e8005c1ea8077ced9f7d72bd
|
7
|
+
data.tar.gz: 95b44f1711e304625684f70cf7a4fad0c5c383b2b2ac4b3465c6c7b5d30a49d76f7d97c9a0083e1360e63c728acf3497aa3dcb86583815d5b13f2990081d2c7a
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
AllCops:
|
3
|
+
Include:
|
4
|
+
- 'lib/**/*'
|
5
|
+
- 'spec/**/*'
|
6
|
+
Metrics/AbcSize:
|
7
|
+
Max: 32
|
8
|
+
Metrics/LineLength:
|
9
|
+
Max: 99
|
10
|
+
Metrics/CyclomaticComplexity:
|
11
|
+
Max: 20
|
12
|
+
Metrics/PerceivedComplexity:
|
13
|
+
Max: 20
|
14
|
+
Metrics/MethodLength:
|
15
|
+
Max: 30
|
16
|
+
Documentation:
|
17
|
+
Enabled: false
|
18
|
+
Style/SignalException:
|
19
|
+
EnforcedStyle: only_raise
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -24,14 +24,28 @@ e.g.
|
|
24
24
|
root = UrlRegexp::Root.new
|
25
25
|
root.append('http://www.example.com/foo/bar')
|
26
26
|
root.to_regexp
|
27
|
-
# => /^http:\/\/www\.example\.com\/foo\/bar(
|
27
|
+
# => /^http:\/\/www\.example\.com\/foo\/bar([?#]|$)/
|
28
28
|
root.append('http://www.example.com/foo/bar/wow')
|
29
29
|
root.to_regexp
|
30
|
-
# => /^http:\/\/www\.example\.com\/foo\/bar(\/wow)?(
|
30
|
+
# => /^http:\/\/www\.example\.com\/foo\/bar(\/wow)?([?#]|$)/
|
31
|
+
root.append('http://www.example.com/boo/bar')
|
32
|
+
root.to_regexp
|
33
|
+
# => /^http:\/\/www\.example\.com\/(foo\/bar(\/wow)?|boo\/bar)([?#]|$)/
|
34
|
+
root.append('http://www.example.com/boo/bar/wow')
|
35
|
+
root.to_regexp
|
36
|
+
# => /^http:\/\/www\.example\.com\/(foo|boo)\/bar(\/wow)?([?#]|$)/
|
31
37
|
```
|
32
38
|
|
33
39
|
You can set the options globally and locally. Locally set option overwrites the one globally set. Just add any settings necessary for your mailers from the list below.
|
34
40
|
|
41
|
+
## Test
|
42
|
+
|
43
|
+
```bash
|
44
|
+
bundle exec rake
|
45
|
+
```
|
46
|
+
|
47
|
+
It will execute `rspec` and `rubocop`.
|
48
|
+
|
35
49
|
## Contributing
|
36
50
|
|
37
51
|
1. Fork it
|
@@ -48,12 +62,12 @@ Copyright (c) 2016 Daisuke Taniwaki. See [LICENSE](LICENSE) for details.
|
|
48
62
|
|
49
63
|
[gem-image]: https://badge.fury.io/rb/url_regexp.svg
|
50
64
|
[gem-link]: http://badge.fury.io/rb/url_regexp
|
51
|
-
[build-image]: https://secure.travis-ci.org/dtaniwaki/url_regexp.
|
65
|
+
[build-image]: https://secure.travis-ci.org/dtaniwaki/url_regexp.svg?branch=master
|
52
66
|
[build-link]: http://travis-ci.org/dtaniwaki/url_regexp?branch=master
|
53
67
|
[deps-image]: https://gemnasium.com/dtaniwaki/url_regexp.svg?branch=master
|
54
68
|
[deps-link]: https://gemnasium.com/dtaniwaki/url_regexp?branch=master
|
55
|
-
[cov-image]: https://coveralls.io/repos/dtaniwaki/url_regexp/badge.
|
56
|
-
[cov-link]: https://coveralls.io/
|
57
|
-
[gpa-image]: https://codeclimate.com/github/dtaniwaki/url_regexp.
|
69
|
+
[cov-image]: https://coveralls.io/repos/github/dtaniwaki/url_regexp/badge.svg?branch=master
|
70
|
+
[cov-link]: https://coveralls.io/github/dtaniwaki/url_regexp?branch=master
|
71
|
+
[gpa-image]: https://codeclimate.com/github/dtaniwaki/url_regexp.svg?branch=master
|
58
72
|
[gpa-link]: https://codeclimate.com/github/dtaniwaki/url_regexp?branch=master
|
59
73
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rspec/core/rake_task"
|
3
|
+
require 'rubocop/rake_task'
|
3
4
|
|
4
5
|
RSpec::Core::RakeTask.new(:spec)
|
5
6
|
|
6
|
-
|
7
|
+
RuboCop::RakeTask.new do |task|
|
8
|
+
task.requires << 'rubocop-rspec'
|
9
|
+
end
|
10
|
+
|
11
|
+
task :default => [:spec, :rubocop]
|
data/lib/url_regexp/host.rb
CHANGED
data/lib/url_regexp/node.rb
CHANGED
data/lib/url_regexp/path.rb
CHANGED
@@ -13,33 +13,37 @@ module UrlRegexp
|
|
13
13
|
@path_end = false
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
16
|
+
def ==(other)
|
17
|
+
self.class == other.class &&
|
18
|
+
@label == other.label &&
|
19
|
+
@paths == other.paths &&
|
20
|
+
@path_end == other.path_end
|
18
21
|
end
|
19
22
|
|
23
|
+
alias eql? ==
|
24
|
+
|
20
25
|
def hash
|
21
|
-
[@label, @paths
|
26
|
+
[@label, @paths, @path_end].hash
|
22
27
|
end
|
23
28
|
|
24
29
|
def append(path)
|
25
30
|
if path == ''
|
26
31
|
@paths.append(Path.new('', self))
|
32
|
+
elsif @parent.nil?
|
33
|
+
_, label, rest = path.split('/', 3)
|
27
34
|
else
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
35
|
+
label, rest = path.split('/', 2)
|
36
|
+
end
|
37
|
+
if label
|
38
|
+
p = @paths.find { |pp| pp.label == label }
|
39
|
+
if p.nil?
|
40
|
+
p = Path.new(label, self)
|
41
|
+
@paths.append(p)
|
32
42
|
end
|
33
|
-
if
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
if rest.nil?
|
39
|
-
p.path_end = true
|
40
|
-
else
|
41
|
-
p.append(rest)
|
42
|
-
end
|
43
|
+
if rest.nil?
|
44
|
+
p.path_end = true
|
45
|
+
else
|
46
|
+
p.append(rest)
|
43
47
|
end
|
44
48
|
end
|
45
49
|
end
|
data/lib/url_regexp/path_set.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
require_relative './node'
|
2
2
|
|
3
3
|
module UrlRegexp
|
4
|
+
class Set < ::Set
|
5
|
+
def include?(o)
|
6
|
+
# Comparing keys directly is faster than rehash everytime for few items
|
7
|
+
# @hash.rehash
|
8
|
+
# super(o)
|
9
|
+
@hash.keys.include?(o)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
4
13
|
class PathSet < Node
|
5
|
-
include Enumerable
|
6
14
|
extend Forwardable
|
7
15
|
|
8
|
-
def_delegators :@set, :size,
|
16
|
+
def_delegators :@set, :size, *Enumerable.public_instance_methods(false)
|
9
17
|
|
10
18
|
def initialize(set = Set.new)
|
11
19
|
@set = set
|
@@ -15,28 +23,41 @@ module UrlRegexp
|
|
15
23
|
set << path
|
16
24
|
end
|
17
25
|
|
26
|
+
def ==(other)
|
27
|
+
self.class == other.class &&
|
28
|
+
@set.to_a == other.set.to_a
|
29
|
+
end
|
30
|
+
|
31
|
+
alias eql? ==
|
32
|
+
|
33
|
+
def hash
|
34
|
+
@set.hash
|
35
|
+
end
|
36
|
+
|
18
37
|
def &(other)
|
19
|
-
self.class.new(set & other.set)
|
38
|
+
self.class.new(@set & other.set)
|
20
39
|
end
|
21
40
|
|
22
41
|
def |(other)
|
23
|
-
self.class.new(set & other.set)
|
42
|
+
self.class.new(@set & other.set)
|
43
|
+
end
|
44
|
+
|
45
|
+
def include?(path)
|
46
|
+
@set.include?(path)
|
24
47
|
end
|
25
48
|
|
26
49
|
def to_regexp_s
|
27
50
|
if 5 < size
|
28
|
-
|
51
|
+
'([^#?]*)'
|
29
52
|
elsif 1 < size
|
30
|
-
children_paths = map(&:paths).reduce { |
|
31
|
-
if children_paths.size == 1 && all? { |p| !p.path_end
|
32
|
-
"(#{map(&:label).join(
|
53
|
+
children_paths = map(&:paths).reduce { |a, e| a & e }
|
54
|
+
if children_paths.size == 1 && all? { |p| !p.path_end }
|
55
|
+
"(#{map(&:label).join('|')})/#{children_paths.to_regexp_s}"
|
33
56
|
else
|
34
|
-
"(#{map(&:to_regexp_s).join(
|
57
|
+
"(#{map(&:to_regexp_s).join('|')})"
|
35
58
|
end
|
36
59
|
elsif 1 == size
|
37
60
|
to_a.first.to_regexp_s
|
38
|
-
else
|
39
|
-
nil
|
40
61
|
end
|
41
62
|
end
|
42
63
|
|
data/lib/url_regexp/query.rb
CHANGED
@@ -5,19 +5,19 @@ module UrlRegexp
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def append(query)
|
8
|
-
if
|
9
|
-
|
10
|
-
end
|
8
|
+
return if query.nil?
|
9
|
+
@queries << query.to_s.split('&').reject(&:empty?)
|
11
10
|
end
|
12
11
|
|
13
12
|
def to_regexp_s
|
14
|
-
common_queries = @queries.reduce { |
|
13
|
+
common_queries = @queries.reduce { |a, e| a & e } || []
|
14
|
+
common_queries = common_queries.map { |q| Regexp.quote(q) }
|
15
15
|
if 1 < common_queries.size
|
16
|
-
"\\?(#{common_queries.
|
16
|
+
"\\?(#{common_queries.permutation.map { |qs| "(.*&)?#{qs.join('.*&')}(&.*)?" }.join('|')})"
|
17
17
|
elsif 1 == common_queries.size
|
18
|
-
"\\?(.*&)?#{
|
18
|
+
"\\?(.*&)?#{common_queries.first}(&.*)?"
|
19
19
|
else
|
20
|
-
|
20
|
+
'(\\?.*)?'
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/url_regexp/root.rb
CHANGED
@@ -20,7 +20,13 @@ module UrlRegexp
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def to_regexp_s
|
23
|
-
|
23
|
+
s = '^' +
|
24
|
+
@scheme.to_regexp_s +
|
25
|
+
@host.to_regexp_s +
|
26
|
+
@path.to_regexp_s +
|
27
|
+
@query.to_regexp_s +
|
28
|
+
'(#|$)'
|
29
|
+
s.sub('(\\?.*)?(#|$)', '([?#]|$)')
|
24
30
|
end
|
25
31
|
end
|
26
32
|
end
|
data/lib/url_regexp/scheme.rb
CHANGED
@@ -12,16 +12,15 @@ module UrlRegexp
|
|
12
12
|
|
13
13
|
def to_regexp_s
|
14
14
|
schemes = @schemes.map { |s| Regexp.quote(s) }
|
15
|
-
|
16
|
-
|
15
|
+
if schemes == %w(http https)
|
16
|
+
'https?://'
|
17
17
|
elsif 1 < @schemes.size
|
18
18
|
"(#{schemes.join('|')})://"
|
19
19
|
elsif 1 == @schemes.size
|
20
|
-
"#{schemes.to_a.first
|
20
|
+
"#{schemes.to_a.first}://"
|
21
21
|
else
|
22
|
-
|
22
|
+
''
|
23
23
|
end
|
24
|
-
s
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
data/lib/url_regexp/version.rb
CHANGED
data/lib/url_regexp.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: url_regexp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daisuke Taniwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
|
+
- ".rubocop.yml"
|
63
64
|
- ".travis.yml"
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE
|