http_router 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -2
- data/Rakefile +7 -3
- data/lib/http_router.rb +11 -30
- data/lib/http_router/node/path.rb +6 -1
- data/lib/http_router/node/spanning_regex.rb +2 -2
- data/lib/http_router/route.rb +3 -1
- data/lib/http_router/route_helper.rb +11 -20
- data/lib/http_router/version.rb +1 -1
- data/test/test_misc.rb +6 -0
- metadata +73 -46
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: afb349e4d4bfdd4a1d17f69c7447304b1150ff74
|
4
|
+
data.tar.gz: 1c784865657a739153919fb02b33620e9b1daaa4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40163e582745fabb018c8ce4a7da8ca36a6ea3ee4dc06d88fe8c571e5435a8cf2a39e5f18d00f0a301eff2ba86b178b883f858dcb2febddb38b82df4ad37ae6e
|
7
|
+
data.tar.gz: 925003de1d9d4455099a42e645d5d4915f7bdaf7129ecccc07168832804130cc2932be9c29f86edec126af4bcc205ecdac06a256ec5fd85caa486660ca943e8d
|
data/Gemfile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gemspec
|
3
|
+
gemspec
|
data/Rakefile
CHANGED
@@ -161,11 +161,15 @@ namespace :test do
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
-
|
164
|
+
begin
|
165
|
+
require 'rake/rdoctask'
|
166
|
+
rescue
|
167
|
+
require 'rdoc/task'
|
168
|
+
end
|
165
169
|
desc "Generate documentation"
|
166
170
|
Rake::RDocTask.new do |rd|
|
167
|
-
rd.main = "README.
|
168
|
-
rd.rdoc_files.include("README.
|
171
|
+
rd.main = "README.md"
|
172
|
+
rd.rdoc_files.include("README.md", "lib/**/*.rb")
|
169
173
|
rd.rdoc_dir = 'rdoc'
|
170
174
|
end
|
171
175
|
|
data/lib/http_router.rb
CHANGED
@@ -24,6 +24,8 @@ class HttpRouter
|
|
24
24
|
TooManyParametersException = Class.new(RuntimeError)
|
25
25
|
# Raised when there are left over options
|
26
26
|
LeftOverOptions = Class.new(RuntimeError)
|
27
|
+
# Raised when there are duplicate param names specified in a Path
|
28
|
+
AmbiguousVariableException = Class.new(RuntimeError)
|
27
29
|
|
28
30
|
RecognizeResponse = Struct.new(:matches, :acceptable_methods)
|
29
31
|
|
@@ -104,41 +106,20 @@ class HttpRouter
|
|
104
106
|
end
|
105
107
|
end
|
106
108
|
|
109
|
+
# Creates helper methods for each supported HTTP verb, except GET, which is
|
110
|
+
# a special case that accepts both GET and HEAD requests.
|
111
|
+
Route::VALID_HTTP_VERBS_WITHOUT_GET.each do |request_method|
|
112
|
+
request_method_symbol = request_method.downcase.to_sym
|
113
|
+
define_method(request_method_symbol) do |path, opts = {}, &app|
|
114
|
+
add_with_request_method(path, request_method_symbol, opts, &app)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
107
118
|
# Adds a path that only responds to the request method +GET+.
|
108
119
|
#
|
109
120
|
# Returns the route object.
|
110
121
|
def get(path, opts = {}, &app); add_with_request_method(path, [:get, :head], opts, &app); end
|
111
122
|
|
112
|
-
# Adds a path that only responds to the request method +POST+.
|
113
|
-
#
|
114
|
-
# Returns the route object.
|
115
|
-
def post(path, opts = {}, &app); add_with_request_method(path, :post, opts, &app); end
|
116
|
-
|
117
|
-
# Adds a path that only responds to the request method +DELETE+.
|
118
|
-
#
|
119
|
-
# Returns the route object.
|
120
|
-
def delete(path, opts = {}, &app); add_with_request_method(path, :delete, opts, &app); end
|
121
|
-
|
122
|
-
# Adds a path that only responds to the request method +PUT+.
|
123
|
-
#
|
124
|
-
# Returns the route object.
|
125
|
-
def put(path, opts = {}, &app); add_with_request_method(path, :put, opts, &app); end
|
126
|
-
|
127
|
-
# Adds a path that only responds to the request method +PATCH+.
|
128
|
-
#
|
129
|
-
# Returns the route object.
|
130
|
-
def patch(path, opts = {}, &app); add_with_request_method(path, :patch, opts, &app); end
|
131
|
-
|
132
|
-
# Adds a path that only responds to the request method +OPTIONS+.
|
133
|
-
#
|
134
|
-
# Returns the route object.
|
135
|
-
def trace(path, opts = {}, &app); add_with_request_method(path, :trace, opts, &app); end
|
136
|
-
|
137
|
-
# Adds a path that only responds to the request method +OPTIONS+.
|
138
|
-
#
|
139
|
-
# Returns the route object.
|
140
|
-
def conenct(path, opts = {}, &app); add_with_request_method(path, :conenct, opts, &app); end
|
141
|
-
|
142
123
|
# Performs recoginition without actually calling the application and returns an array of all
|
143
124
|
# matching routes or nil if no match was found.
|
144
125
|
def recognize(env, &callback)
|
@@ -6,7 +6,8 @@ class HttpRouter
|
|
6
6
|
def initialize(router, parent, route, path, param_names = [])
|
7
7
|
@route, @path, @param_names, @dynamic = route, path, param_names, !param_names.empty?
|
8
8
|
@route.add_path(self)
|
9
|
-
|
9
|
+
|
10
|
+
raise AmbiguousVariableException, "You have duplicate variable names present: #{duplicates.join(', ')}" if param_names.uniq.size != param_names.size
|
10
11
|
super router, parent
|
11
12
|
router.uncompile
|
12
13
|
end
|
@@ -46,6 +47,10 @@ class HttpRouter
|
|
46
47
|
def inspect_label
|
47
48
|
"Path: #{path.inspect} for route #{route.name || 'unnamed route'} to #{route.dest.inspect}"
|
48
49
|
end
|
50
|
+
|
51
|
+
def duplicates
|
52
|
+
param_names.group_by { |e| e }.select { |k, v| v.size > 1 }.map(&:first)
|
53
|
+
end
|
49
54
|
end
|
50
55
|
end
|
51
56
|
end
|
@@ -12,10 +12,10 @@ class HttpRouter
|
|
12
12
|
request.path = remaining_path.split('/')
|
13
13
|
#{node_to_code}
|
14
14
|
request.path = _#{whole_path_var}
|
15
|
-
request.params.slice!(#{-params_count
|
15
|
+
request.params.slice!(#{-params_count}, #{params_count})
|
16
16
|
end
|
17
17
|
"
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
|
-
end
|
21
|
+
end
|
data/lib/http_router/route.rb
CHANGED
@@ -2,7 +2,9 @@ require 'set'
|
|
2
2
|
|
3
3
|
class HttpRouter
|
4
4
|
class Route
|
5
|
-
|
5
|
+
# The list of HTTP request methods supported by HttpRouter.
|
6
|
+
VALID_HTTP_VERBS = %w{GET POST PUT DELETE HEAD OPTIONS TRACE PATCH OPTIONS LINK UNLINK}
|
7
|
+
VALID_HTTP_VERBS_WITHOUT_GET = VALID_HTTP_VERBS - %w{GET}
|
6
8
|
|
7
9
|
attr_reader :default_values, :router, :match_partially, :other_hosts, :paths, :request_methods, :name
|
8
10
|
attr_accessor :match_partially, :router, :host, :user_agent, :ignore_trailing_slash,
|
@@ -46,7 +46,9 @@ class HttpRouter
|
|
46
46
|
methods = [methods] unless methods.is_a?(Array)
|
47
47
|
methods.each do |method|
|
48
48
|
method = method.to_s.upcase
|
49
|
-
|
49
|
+
unless Route::VALID_HTTP_VERBS.include?(method)
|
50
|
+
raise ArgumentError, "Unsupported HTTP request method: #{method}"
|
51
|
+
end
|
50
52
|
@request_methods << method
|
51
53
|
end
|
52
54
|
end
|
@@ -77,28 +79,17 @@ class HttpRouter
|
|
77
79
|
self
|
78
80
|
end
|
79
81
|
|
80
|
-
|
81
|
-
|
82
|
-
|
82
|
+
# Creates helper methods for each supported HTTP verb.
|
83
|
+
Route::VALID_HTTP_VERBS_WITHOUT_GET.each do |request_method|
|
84
|
+
define_method(request_method.downcase) do
|
85
|
+
add_request_method(request_method)
|
86
|
+
self
|
87
|
+
end
|
83
88
|
end
|
84
89
|
|
85
90
|
def get
|
86
|
-
add_request_method
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
def post
|
91
|
-
add_request_method "POST"
|
92
|
-
self
|
93
|
-
end
|
94
|
-
|
95
|
-
def put
|
96
|
-
add_request_method "PUT"
|
97
|
-
self
|
98
|
-
end
|
99
|
-
|
100
|
-
def delete
|
101
|
-
add_request_method "DELETE"
|
91
|
+
add_request_method("GET")
|
92
|
+
add_request_method("HEAD")
|
102
93
|
self
|
103
94
|
end
|
104
95
|
|
data/lib/http_router/version.rb
CHANGED
data/test/test_misc.rb
CHANGED
@@ -87,6 +87,12 @@ class TestMisc < MiniTest::Unit::TestCase
|
|
87
87
|
assert_raises(HttpRouter::InvalidRouteException) { r.path(:route) }
|
88
88
|
end
|
89
89
|
|
90
|
+
def test_ambigiuous_parameters_in_route
|
91
|
+
r = router
|
92
|
+
r.add("/abc/:id/test/:id", :name => :route).default_destination
|
93
|
+
assert_raises(HttpRouter::AmbiguousVariableException) { r.path(:route, :id => 'fail') }
|
94
|
+
end
|
95
|
+
|
90
96
|
def test_public_interface
|
91
97
|
methods = HttpRouter.public_instance_methods.map(&:to_sym)
|
92
98
|
assert methods.include?(:url_mount)
|
metadata
CHANGED
@@ -1,126 +1,155 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_router
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
5
|
-
prerelease:
|
4
|
+
version: 0.11.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Joshua Hull
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-02-23 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rack
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 1.0.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: url_mount
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
31
|
- - ~>
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: 0.2.1
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.1
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: minitest
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
45
|
- - ~>
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: 2.0.0
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.0
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: code_stats
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
type: :development
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: rake
|
60
|
-
requirement:
|
61
|
-
none: false
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
62
72
|
requirements:
|
63
73
|
- - ~>
|
64
74
|
- !ruby/object:Gem::Version
|
65
75
|
version: 0.8.7
|
66
76
|
type: :development
|
67
77
|
prerelease: false
|
68
|
-
version_requirements:
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.8.7
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rbench
|
71
|
-
requirement:
|
72
|
-
none: false
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
73
86
|
requirements:
|
74
|
-
- -
|
87
|
+
- - '>='
|
75
88
|
- !ruby/object:Gem::Version
|
76
89
|
version: '0'
|
77
90
|
type: :development
|
78
91
|
prerelease: false
|
79
|
-
version_requirements:
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
80
97
|
- !ruby/object:Gem::Dependency
|
81
98
|
name: json
|
82
|
-
requirement:
|
83
|
-
none: false
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
84
100
|
requirements:
|
85
|
-
- -
|
101
|
+
- - '>='
|
86
102
|
- !ruby/object:Gem::Version
|
87
103
|
version: '0'
|
88
104
|
type: :development
|
89
105
|
prerelease: false
|
90
|
-
version_requirements:
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
91
111
|
- !ruby/object:Gem::Dependency
|
92
112
|
name: phocus
|
93
|
-
requirement:
|
94
|
-
none: false
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
95
114
|
requirements:
|
96
|
-
- -
|
115
|
+
- - '>='
|
97
116
|
- !ruby/object:Gem::Version
|
98
117
|
version: '0'
|
99
118
|
type: :development
|
100
119
|
prerelease: false
|
101
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
102
125
|
- !ruby/object:Gem::Dependency
|
103
126
|
name: bundler
|
104
|
-
requirement:
|
105
|
-
none: false
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
106
128
|
requirements:
|
107
|
-
- -
|
129
|
+
- - '>='
|
108
130
|
- !ruby/object:Gem::Version
|
109
131
|
version: '0'
|
110
132
|
type: :development
|
111
133
|
prerelease: false
|
112
|
-
version_requirements:
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
113
139
|
- !ruby/object:Gem::Dependency
|
114
140
|
name: thin
|
115
|
-
requirement:
|
116
|
-
none: false
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
117
142
|
requirements:
|
118
|
-
- - =
|
143
|
+
- - '='
|
119
144
|
- !ruby/object:Gem::Version
|
120
145
|
version: 1.2.8
|
121
146
|
type: :development
|
122
147
|
prerelease: false
|
123
|
-
version_requirements:
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.2.8
|
124
153
|
description: This library allows you to recognize and build URLs in a Rack application.
|
125
154
|
email: joshbuddy@gmail.com
|
126
155
|
executables: []
|
@@ -195,26 +224,25 @@ files:
|
|
195
224
|
- test/test_trailing_slash.rb
|
196
225
|
homepage: http://github.com/joshbuddy/http_router
|
197
226
|
licenses: []
|
227
|
+
metadata: {}
|
198
228
|
post_install_message:
|
199
229
|
rdoc_options:
|
200
230
|
- --charset=UTF-8
|
201
231
|
require_paths:
|
202
232
|
- lib
|
203
233
|
required_ruby_version: !ruby/object:Gem::Requirement
|
204
|
-
none: false
|
205
234
|
requirements:
|
206
|
-
- -
|
235
|
+
- - '>='
|
207
236
|
- !ruby/object:Gem::Version
|
208
237
|
version: '0'
|
209
238
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
|
-
none: false
|
211
239
|
requirements:
|
212
|
-
- -
|
240
|
+
- - '>='
|
213
241
|
- !ruby/object:Gem::Version
|
214
242
|
version: '0'
|
215
243
|
requirements: []
|
216
244
|
rubyforge_project: http_router
|
217
|
-
rubygems_version: 1.
|
245
|
+
rubygems_version: 2.1.11
|
218
246
|
signing_key:
|
219
247
|
specification_version: 3
|
220
248
|
summary: A kick-ass HTTP router for use in Rack
|
@@ -231,4 +259,3 @@ test_files:
|
|
231
259
|
- test/test_mounting.rb
|
232
260
|
- test/test_recognition.rb
|
233
261
|
- test/test_trailing_slash.rb
|
234
|
-
has_rdoc:
|