http_router 0.3.7 → 0.3.8

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.
@@ -7,7 +7,6 @@ Gem::Specification.new do |s|
7
7
  s.version = HttpRouter::VERSION
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.authors = ["Joshua Hull"]
10
- s.date = '2010-07-31'
11
10
  s.summary = "A kick-ass HTTP router for use in Rack & Sinatra"
12
11
  s.description = "This library allows you to recognize and build URLs in a Rack application. As well it contains an interface for use within Sinatra."
13
12
  s.email = %q{joshbuddy@gmail.com}
@@ -205,29 +205,37 @@ class HttpRouter
205
205
 
206
206
  def find_on_request_methods(request, alternate_request_methods)
207
207
  if @request_method
208
+ request_method_satisfied = false
208
209
  request_value = request.send(request_method)
209
210
  if @linear && !@linear.empty?
210
211
  next_node = @linear.find do |(regexp, node)|
211
212
  regexp === request_value
212
213
  end
214
+ request_method_satisfied = true if next_node
213
215
  next_node &&= next_node.last.find_on_request_methods(request, alternate_request_methods)
214
216
  return next_node if next_node
215
217
  end
216
- if @lookup and next_node = (@lookup[request_value] && @lookup[request_value].find_on_request_methods(request, alternate_request_methods))
217
- return next_node
218
- elsif next_node = (@catchall && @catchall.find_on_request_methods(request, alternate_request_methods))
219
- return next_node
218
+ if @lookup and next_node = @lookup[request_value]
219
+ request_method_satisfied = true
220
+ next_node = next_node.find_on_request_methods(request, alternate_request_methods)
221
+ return next_node if next_node
222
+ end
223
+ if @catchall
224
+ request_method_satisfied = true
225
+ next_node = @catchall.find_on_request_methods(request, alternate_request_methods)
226
+ return next_node if next_node
227
+ end
228
+ if @request_method == :request_method
229
+ alternate_request_methods.concat(@lookup.keys)
230
+ alternate_request_methods.request_method_found ||= request_method_satisfied
220
231
  end
221
232
  end
222
-
233
+
223
234
  if @arbitrary_node
224
235
  @arbitrary_node.find_on_arbitrary(request)
225
236
  elsif @value
226
237
  self
227
238
  else
228
- if request_method == :request_method
229
- alternate_request_methods.concat(@lookup.keys)
230
- end
231
239
  nil
232
240
  end
233
241
  end
@@ -1,5 +1,9 @@
1
1
  class HttpRouter
2
2
  class Root < Node
3
+ class AlternativeRequestMethods < Array
4
+ attr_accessor :request_method_found
5
+ end
6
+
3
7
  def add_path(path)
4
8
  node = path.parts.inject(self) { |node, part| node.add(part) }
5
9
  node
@@ -10,7 +14,8 @@ class HttpRouter
10
14
  parts = router.split(path)
11
15
  parts << '' if path[path.size - 1] == ?/
12
16
  params = []
13
- alternate_request_methods = []
17
+ alternate_request_methods = AlternativeRequestMethods.new
18
+ alternate_request_methods.request_method_found = false
14
19
  process_response(
15
20
  find_on_parts(request, parts, params, alternate_request_methods),
16
21
  parts,
@@ -34,10 +39,10 @@ class HttpRouter
34
39
  nil
35
40
  end
36
41
  else
37
- if alternate_request_methods.empty?
42
+ if alternate_request_methods.request_method_found or alternate_request_methods.empty?
38
43
  nil
39
44
  else
40
- Response.unmatched(405, {"Allow" => alternate_request_methods.join(", ")})
45
+ Response.unmatched(405, {"Allow" => alternate_request_methods.uniq.join(", ")})
41
46
  end
42
47
  end
43
48
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  class HttpRouter #:nodoc
3
- VERSION = '0.3.7'
3
+ VERSION = '0.3.8'
4
4
  end
@@ -82,7 +82,6 @@ describe "HttpRouter#recognize" do
82
82
  response = @router.recognize(Rack::MockRequest.env_for('http://lovelove:8081/test'))
83
83
  response.dest.should == :test3
84
84
  end
85
-
86
85
  end
87
86
 
88
87
  context("with trailing slashes") do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_router
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 7
10
- version: 0.3.7
9
+ - 8
10
+ version: 0.3.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hull
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-31 00:00:00 -07:00
18
+ date: 2010-08-05 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency