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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e00ee5f39e4cd8652f37ca2cd51d3e9089217608
4
- data.tar.gz: 94adfb1668385c347a8875415df91d1eac1bf426
3
+ metadata.gz: f350bc548233f7897ce4c1e4c5c2905835454549
4
+ data.tar.gz: c3dc80a9fe0e099cc1ca8cb6b00fb8575616fe3b
5
5
  SHA512:
6
- metadata.gz: 79b26aa82519dfe3d6ee5215d83c8a766e080797fb2f2f6885c8736e141a39bd03db3f92371ea806d75f60dfecb3292d76ade31550f1ccd2fb3a008251bf3b5b
7
- data.tar.gz: 4d5c32620af06e77bd29d9121bfcc43da3093e8697af2a9f753eaf2731740b63ad3fe3eb35bff0ca0679910cdbcdaae8cad68bc5927b685f7245cf7154c4a22b
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
@@ -4,3 +4,5 @@ rvm:
4
4
  - 2.2
5
5
  - 2.3.0
6
6
  before_install: gem install bundler -v 1.11.2
7
+ script:
8
+ - bundle exec rake
data/Gemfile CHANGED
@@ -2,5 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'simplecov'
4
4
  gem 'coveralls'
5
+ gem 'rubocop', require: false
6
+ gem 'rubocop-rspec', require: false
7
+ gem 'pry'
5
8
 
6
9
  gemspec
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.png?branch=master
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.png?branch=master
56
- [cov-link]: https://coveralls.io/r/dtaniwaki/url_regexp?branch=master
57
- [gpa-image]: https://codeclimate.com/github/dtaniwaki/url_regexp.png?branch=master
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
- task :default => :spec
7
+ RuboCop::RakeTask.new do |task|
8
+ task.requires << 'rubocop-rspec'
9
+ end
10
+
11
+ task :default => [:spec, :rubocop]
@@ -11,11 +11,10 @@ module UrlRegexp
11
11
  def to_regexp_s
12
12
  hosts = @hosts.map { |h| Regexp.quote(h.to_s) }
13
13
  if 1 < hosts.size
14
- hosts = "(#{hosts.join('|')})"
14
+ "(#{hosts.join('|')})"
15
15
  else
16
- hosts = hosts[0]
16
+ hosts[0]
17
17
  end
18
- hosts
19
18
  end
20
19
  end
21
20
  end
@@ -1,10 +1,6 @@
1
1
  module UrlRegexp
2
2
  class Node
3
- def eql?(other)
4
- hash == other.hash
5
- end
6
-
7
- def append(node)
3
+ def append(_)
8
4
  raise NotImplementedError
9
5
  end
10
6
 
@@ -13,33 +13,37 @@ module UrlRegexp
13
13
  @path_end = false
14
14
  end
15
15
 
16
- def path_end?
17
- @path_end
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.hash].hash
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
- if @parent.nil?
29
- _, label, rest = path.split('/', 3)
30
- else
31
- label, rest = path.split('/', 2)
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 label
34
- unless p = @paths.find { |_p| _p.label == label }
35
- p = Path.new(label, self)
36
- @paths.append(p)
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
@@ -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, :hash, *Enumerable.public_instance_methods(false)
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 { |s1, s2| s1 & s2 }
31
- if children_paths.size == 1 && all? { |p| !p.path_end? }
32
- "(#{map(&:label).join("|")})/#{children_paths.to_regexp_s}"
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
 
@@ -5,19 +5,19 @@ module UrlRegexp
5
5
  end
6
6
 
7
7
  def append(query)
8
- if !query.nil?
9
- @queries << query.to_s.split('&').reject(&:empty?)
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 { |q1, q2| q1 & q2 } || []
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.map { |q| Regexp.quote(q) }.permutation.to_a.map { |qs| "(.*&)?#{qs.join('.*&')}(&.*)?" }.join('|')})"
16
+ "\\?(#{common_queries.permutation.map { |qs| "(.*&)?#{qs.join('.*&')}(&.*)?" }.join('|')})"
17
17
  elsif 1 == common_queries.size
18
- "\\?(.*&)?#{Regexp.quote(common_queries.first)}(&.*)?"
18
+ "\\?(.*&)?#{common_queries.first}(&.*)?"
19
19
  else
20
- "(\\?.*)?"
20
+ '(\\?.*)?'
21
21
  end
22
22
  end
23
23
  end
@@ -20,7 +20,13 @@ module UrlRegexp
20
20
  end
21
21
 
22
22
  def to_regexp_s
23
- "^#{@scheme.to_regexp_s}#{@host.to_regexp_s}#{@path.to_regexp_s}#{@query.to_regexp_s}(#|$)"
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
@@ -12,16 +12,15 @@ module UrlRegexp
12
12
 
13
13
  def to_regexp_s
14
14
  schemes = @schemes.map { |s| Regexp.quote(s) }
15
- s = if schemes == %w(http https)
16
- "https?://"
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.to_s}://"
20
+ "#{schemes.to_a.first}://"
21
21
  else
22
- ""
22
+ ''
23
23
  end
24
- s
25
24
  end
26
25
  end
27
26
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module UrlRegexp
2
- VERSION = "0.1.1"
4
+ VERSION = '0.1.2'.freeze
3
5
  end
data/lib/url_regexp.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "url_regexp/version"
1
+ require 'url_regexp/version'
2
2
  require 'url_regexp/root'
3
3
 
4
4
  module UrlRegexp
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.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-19 00:00:00.000000000 Z
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