url_regexp 0.1.2 → 0.1.3
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 +4 -4
- data/.gemrelease +2 -0
- data/.rubocop.yml +3 -1
- data/Gemfile +4 -1
- data/README.md +18 -1
- data/lib/url_regexp/host.rb +2 -1
- data/lib/url_regexp/path.rb +5 -4
- data/lib/url_regexp/path_set.rb +19 -6
- data/lib/url_regexp/query.rb +11 -4
- data/lib/url_regexp/root.rb +6 -5
- data/lib/url_regexp/scheme.rb +2 -1
- data/lib/url_regexp/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62ed69e94460e3c50d9d20160d88c50e31fe0928
|
4
|
+
data.tar.gz: 2ca60a8b537b2b446e0979f2fb575db9aecb78bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a904285e2bf5e22d4f7ad48056227814d811b986919a402a649b9a3ae878caa01eb1f819fafe6300121f68b7268c27aea62882c88a20594bc8810390cd27d00c
|
7
|
+
data.tar.gz: 69cc43725809e521e016d00a8c6e7178482835040bbf68ea48783349cb2f11561d7bd5b8885e32c43e74d717f5d63397b54d33a7911a05c69762bfec3e9b9bcf
|
data/.gemrelease
ADDED
data/.rubocop.yml
CHANGED
@@ -4,7 +4,7 @@ AllCops:
|
|
4
4
|
- 'lib/**/*'
|
5
5
|
- 'spec/**/*'
|
6
6
|
Metrics/AbcSize:
|
7
|
-
Max:
|
7
|
+
Max: 40
|
8
8
|
Metrics/LineLength:
|
9
9
|
Max: 99
|
10
10
|
Metrics/CyclomaticComplexity:
|
@@ -13,6 +13,8 @@ Metrics/PerceivedComplexity:
|
|
13
13
|
Max: 20
|
14
14
|
Metrics/MethodLength:
|
15
15
|
Max: 30
|
16
|
+
Metrics/BlockNesting:
|
17
|
+
Max: 4
|
16
18
|
Documentation:
|
17
19
|
Enabled: false
|
18
20
|
Style/SignalException:
|
data/Gemfile
CHANGED
@@ -2,8 +2,11 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gem 'simplecov'
|
4
4
|
gem 'coveralls'
|
5
|
-
|
5
|
+
# FIXME:
|
6
|
+
# Wait for the merge of https://github.com/bbatsov/rubocop/pull/2936
|
7
|
+
gem 'rubocop', '~> 0.37.0', require: false
|
6
8
|
gem 'rubocop-rspec', require: false
|
7
9
|
gem 'pry'
|
10
|
+
gem 'gem-release'
|
8
11
|
|
9
12
|
gemspec
|
data/README.md
CHANGED
@@ -36,7 +36,24 @@ root.to_regexp
|
|
36
36
|
# => /^http:\/\/www\.example\.com\/(foo|boo)\/bar(\/wow)?([?#]|$)/
|
37
37
|
```
|
38
38
|
|
39
|
-
|
39
|
+
## Options
|
40
|
+
|
41
|
+
### wildcard_threshold (default: 5)
|
42
|
+
|
43
|
+
You can change the threshold to group paths as wildcard.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
root = UrlRegexp::Root.new(wildcard_threshold: 2)
|
47
|
+
root.append('http://www.example.com/foo')
|
48
|
+
root.to_regexp
|
49
|
+
# => /^http:\/\/www\.example\.com\/foo([?#]|$)/
|
50
|
+
root.append('http://www.example.com/bar')
|
51
|
+
root.to_regexp
|
52
|
+
# => /^http:\/\/www\.example\.com\/(foo|bar)([?#]|$)/
|
53
|
+
root.append('http://www.example.com/wow')
|
54
|
+
root.to_regexp
|
55
|
+
# => /^http:\/\/www\.example\.com\/([^#?]*)([?#]|$)/
|
56
|
+
```
|
40
57
|
|
41
58
|
## Test
|
42
59
|
|
data/lib/url_regexp/host.rb
CHANGED
data/lib/url_regexp/path.rb
CHANGED
@@ -6,10 +6,11 @@ module UrlRegexp
|
|
6
6
|
attr_reader :label, :paths
|
7
7
|
attr_accessor :path_end
|
8
8
|
|
9
|
-
def initialize(label = nil, parent = nil)
|
9
|
+
def initialize(label = nil, parent = nil, options = {})
|
10
10
|
@label = label
|
11
11
|
@parent = parent
|
12
|
-
@
|
12
|
+
@options = options
|
13
|
+
@paths = PathSet.new(nil, @options)
|
13
14
|
@path_end = false
|
14
15
|
end
|
15
16
|
|
@@ -28,7 +29,7 @@ module UrlRegexp
|
|
28
29
|
|
29
30
|
def append(path)
|
30
31
|
if path == ''
|
31
|
-
@paths.append(Path.new('', self))
|
32
|
+
@paths.append(Path.new('', self, @options))
|
32
33
|
elsif @parent.nil?
|
33
34
|
_, label, rest = path.split('/', 3)
|
34
35
|
else
|
@@ -37,7 +38,7 @@ module UrlRegexp
|
|
37
38
|
if label
|
38
39
|
p = @paths.find { |pp| pp.label == label }
|
39
40
|
if p.nil?
|
40
|
-
p = Path.new(label, self)
|
41
|
+
p = Path.new(label, self, @options)
|
41
42
|
@paths.append(p)
|
42
43
|
end
|
43
44
|
if rest.nil?
|
data/lib/url_regexp/path_set.rb
CHANGED
@@ -15,8 +15,10 @@ module UrlRegexp
|
|
15
15
|
|
16
16
|
def_delegators :@set, :size, *Enumerable.public_instance_methods(false)
|
17
17
|
|
18
|
-
def initialize(set =
|
19
|
-
@set = set
|
18
|
+
def initialize(set = nil, options = {})
|
19
|
+
@set = set || Set.new
|
20
|
+
@options = options
|
21
|
+
@wildcard_threshold = options[:wildcard_threshold] || 5
|
20
22
|
end
|
21
23
|
|
22
24
|
def append(path)
|
@@ -35,11 +37,11 @@ module UrlRegexp
|
|
35
37
|
end
|
36
38
|
|
37
39
|
def &(other)
|
38
|
-
self.class.new(@set & other.set)
|
40
|
+
self.class.new(@set & other.set, @options)
|
39
41
|
end
|
40
42
|
|
41
43
|
def |(other)
|
42
|
-
self.class.new(@set & other.set)
|
44
|
+
self.class.new(@set & other.set, @options)
|
43
45
|
end
|
44
46
|
|
45
47
|
def include?(path)
|
@@ -47,14 +49,25 @@ module UrlRegexp
|
|
47
49
|
end
|
48
50
|
|
49
51
|
def to_regexp_s
|
50
|
-
if
|
52
|
+
if @wildcard_threshold < size
|
51
53
|
'([^#?]*)'
|
52
54
|
elsif 1 < size
|
53
55
|
children_paths = map(&:paths).reduce { |a, e| a & e }
|
54
56
|
if children_paths.size == 1 && all? { |p| !p.path_end }
|
55
57
|
"(#{map(&:label).join('|')})/#{children_paths.to_regexp_s}"
|
56
58
|
else
|
57
|
-
|
59
|
+
regexps = map(&:to_regexp_s)
|
60
|
+
match = ''
|
61
|
+
if regexps.size > 1
|
62
|
+
base = regexps[0]
|
63
|
+
base.split(//).each do |c|
|
64
|
+
tmp = match + c
|
65
|
+
break unless regexps[1..-1].all? { |r| r.start_with? tmp }
|
66
|
+
match = tmp
|
67
|
+
end
|
68
|
+
regexps = regexps.map { |r| r[match.size..-1] }
|
69
|
+
end
|
70
|
+
"#{match}(#{regexps.join('|')})"
|
58
71
|
end
|
59
72
|
elsif 1 == size
|
60
73
|
to_a.first.to_regexp_s
|
data/lib/url_regexp/query.rb
CHANGED
@@ -1,24 +1,31 @@
|
|
1
1
|
module UrlRegexp
|
2
2
|
class Query
|
3
|
-
def initialize
|
3
|
+
def initialize(options = {})
|
4
|
+
@include_nil = false
|
4
5
|
@queries = []
|
6
|
+
@options = options
|
5
7
|
end
|
6
8
|
|
7
9
|
def append(query)
|
8
|
-
|
9
|
-
|
10
|
+
query = query.to_s
|
11
|
+
if query.empty?
|
12
|
+
@include_nil = true
|
13
|
+
return
|
14
|
+
end
|
15
|
+
@queries << query.split('&')
|
10
16
|
end
|
11
17
|
|
12
18
|
def to_regexp_s
|
13
19
|
common_queries = @queries.reduce { |a, e| a & e } || []
|
14
20
|
common_queries = common_queries.map { |q| Regexp.quote(q) }
|
15
|
-
if 1 < common_queries.size
|
21
|
+
regexp_s = if 1 < common_queries.size
|
16
22
|
"\\?(#{common_queries.permutation.map { |qs| "(.*&)?#{qs.join('.*&')}(&.*)?" }.join('|')})"
|
17
23
|
elsif 1 == common_queries.size
|
18
24
|
"\\?(.*&)?#{common_queries.first}(&.*)?"
|
19
25
|
else
|
20
26
|
'(\\?.*)?'
|
21
27
|
end
|
28
|
+
@include_nil ? "(#{regexp_s})?" : regexp_s
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
data/lib/url_regexp/root.rb
CHANGED
@@ -4,11 +4,12 @@ end
|
|
4
4
|
|
5
5
|
module UrlRegexp
|
6
6
|
class Root < Node
|
7
|
-
def initialize
|
8
|
-
@scheme = Scheme.new
|
9
|
-
@host = Host.new
|
10
|
-
@path = Path.new
|
11
|
-
@query = Query.new
|
7
|
+
def initialize(options = {})
|
8
|
+
@scheme = Scheme.new(options)
|
9
|
+
@host = Host.new(options)
|
10
|
+
@path = Path.new(nil, nil, options)
|
11
|
+
@query = Query.new(options)
|
12
|
+
@options = options
|
12
13
|
end
|
13
14
|
|
14
15
|
def append(url)
|
data/lib/url_regexp/scheme.rb
CHANGED
data/lib/url_regexp/version.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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daisuke Taniwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -59,6 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".gemrelease"
|
62
63
|
- ".gitignore"
|
63
64
|
- ".rubocop.yml"
|
64
65
|
- ".travis.yml"
|
@@ -96,9 +97,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
97
|
version: '0'
|
97
98
|
requirements: []
|
98
99
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
100
|
+
rubygems_version: 2.6.10
|
100
101
|
signing_key:
|
101
102
|
specification_version: 4
|
102
103
|
summary: Generate regular expression for URL
|
103
104
|
test_files: []
|
104
|
-
has_rdoc:
|