http_router 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,7 +25,6 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency 'minitest', '~> 2.0.0'
26
26
  s.add_development_dependency 'code_stats'
27
27
  s.add_development_dependency 'rake'
28
- s.add_development_dependency 'sinatra'
29
28
  s.add_development_dependency 'rbench'
30
29
  s.add_development_dependency 'phocus'
31
30
  s.add_development_dependency 'bundler', '~> 1.0.0'
@@ -57,7 +57,8 @@ class HttpRouter
57
57
  supported_methods = (@known_methods - [env['REQUEST_METHOD']]).select do |m|
58
58
  test_env = Rack::Request.new(rack_request.env.clone)
59
59
  test_env.env['REQUEST_METHOD'] = m
60
- test_request = Request.new(test_env.path_info, test_env, false)
60
+ test_env.env['HTTP_ROUTER_405_TESTING_ACCEPTANCE'] = true
61
+ test_request = Request.new(test_env.path_info, test_env, 405)
61
62
  catch(:success) { @root[test_request] }
62
63
  end
63
64
  supported_methods.empty? ? @default_app.call(env) : [405, {'Allow' => supported_methods.sort.join(", ")}, []]
@@ -62,7 +62,7 @@ class HttpRouter
62
62
  arbitrary(request_obj)
63
63
  if match_partially or request_obj.path.empty?
64
64
  @destination && @destination.each do |d|
65
- if d.route.match_partially? or request_obj.path.empty? or (@router.ignore_trailing_slash? and request_obj.path.size == 1 and request_obj.path.last == '')
65
+ if request_obj.path.empty? or d.route.match_partially? or (@router.ignore_trailing_slash? and request_obj.path.size == 1 and request_obj.path.last == '')
66
66
  if request_obj.perform_call
67
67
  env = request_obj.rack_request.dup.env
68
68
  env['router.params'] ||= {}
@@ -127,9 +127,9 @@ class HttpRouter
127
127
  next_requests
128
128
  end
129
129
 
130
- def add_arbitrary(blk, param_names)
130
+ def add_arbitrary(blk, allow_partial, param_names)
131
131
  @arbitrary ||= []
132
- @arbitrary << Arbitrary.new(@router, blk, param_names)
132
+ @arbitrary << Arbitrary.new(@router, allow_partial, blk, param_names)
133
133
  @arbitrary.last
134
134
  end
135
135
 
@@ -1,15 +1,17 @@
1
1
  class HttpRouter
2
2
  class Node
3
3
  class Arbitrary < Node
4
- def initialize(router, blk, param_names)
5
- @router, @blk, @param_names = router, blk, param_names
4
+ def initialize(router, allow_partial, blk, param_names)
5
+ @router, @allow_partial, @blk, @param_names = router, allow_partial, blk, param_names
6
6
  end
7
7
 
8
8
  def [](request)
9
- request = request.clone
10
- request.continue = proc { |state| destination(request) if state }
11
- params = @param_names.nil? ? {} : Hash[@param_names.zip(request.params)]
12
- @blk.call(request, params)
9
+ if request.path.empty? or (request.path.size == 1 and request.path[0] == '') or @allow_partial
10
+ request = request.clone
11
+ request.continue = proc { |state| destination(request) if state }
12
+ params = @param_names.nil? ? {} : Hash[@param_names.zip(request.params)]
13
+ @blk.call(request, params)
14
+ end
13
15
  end
14
16
  end
15
17
  end
@@ -49,13 +49,11 @@ class HttpRouter
49
49
  end
50
50
 
51
51
  def [](request)
52
- matched = false
53
52
  if @request_method
54
53
  val = request.rack_request.send(@request_method.to_sym)
55
54
  @linear.each { |(matcher, node)| node[request] if matcher === val }
56
55
  @lookup[val][request] if @lookup.key?(val)
57
56
  @catchall[request] if @catchall
58
- matched = @lookup.key?(val) || !@catchall.nil?
59
57
  else
60
58
  super(request)
61
59
  end
@@ -1,6 +1,5 @@
1
1
  class HttpRouter
2
2
  class Request
3
- attr_reader :perform_call
4
3
  attr_accessor :path, :params, :rack_request, :extra_env, :continue
5
4
  alias_method :rack, :rack_request
6
5
  def initialize(path, rack_request, perform_call)
@@ -11,6 +10,14 @@ class HttpRouter
11
10
  @params = []
12
11
  end
13
12
 
13
+ def perform_call
14
+ @perform_call == true
15
+ end
16
+
17
+ def testing_405?
18
+ @perform_call == 405
19
+ end
20
+
14
21
  def to_s
15
22
  "request path, #{path.inspect}"
16
23
  end
@@ -236,7 +236,7 @@ class HttpRouter
236
236
  else
237
237
  [node]
238
238
  end
239
- @arbitrary.each{|a| nodes.map!{|n| n.add_arbitrary(a, names)} } if @arbitrary
239
+ @arbitrary.each{|a| nodes.map!{|n| n.add_arbitrary(a, match_partially?, names)} } if @arbitrary
240
240
  path_obj = Path.new(self, path, names)
241
241
  nodes.each{|n| n.add_destination(path_obj)}
242
242
  path_obj
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  class HttpRouter #:nodoc
3
- VERSION = '0.6.1'
3
+ VERSION = '0.6.2'
4
4
  end
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: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 1
10
- version: 0.6.1
9
+ - 2
10
+ version: 0.6.2
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: 2011-03-20 00:00:00 -07:00
18
+ date: 2011-03-21 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -95,7 +95,7 @@ dependencies:
95
95
  type: :development
96
96
  version_requirements: *id005
97
97
  - !ruby/object:Gem::Dependency
98
- name: sinatra
98
+ name: rbench
99
99
  prerelease: false
100
100
  requirement: &id006 !ruby/object:Gem::Requirement
101
101
  none: false
@@ -109,7 +109,7 @@ dependencies:
109
109
  type: :development
110
110
  version_requirements: *id006
111
111
  - !ruby/object:Gem::Dependency
112
- name: rbench
112
+ name: phocus
113
113
  prerelease: false
114
114
  requirement: &id007 !ruby/object:Gem::Requirement
115
115
  none: false
@@ -122,24 +122,10 @@ dependencies:
122
122
  version: "0"
123
123
  type: :development
124
124
  version_requirements: *id007
125
- - !ruby/object:Gem::Dependency
126
- name: phocus
127
- prerelease: false
128
- requirement: &id008 !ruby/object:Gem::Requirement
129
- none: false
130
- requirements:
131
- - - ">="
132
- - !ruby/object:Gem::Version
133
- hash: 3
134
- segments:
135
- - 0
136
- version: "0"
137
- type: :development
138
- version_requirements: *id008
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: bundler
141
127
  prerelease: false
142
- requirement: &id009 !ruby/object:Gem::Requirement
128
+ requirement: &id008 !ruby/object:Gem::Requirement
143
129
  none: false
144
130
  requirements:
145
131
  - - ~>
@@ -151,7 +137,7 @@ dependencies:
151
137
  - 0
152
138
  version: 1.0.0
153
139
  type: :development
154
- version_requirements: *id009
140
+ version_requirements: *id008
155
141
  description: This library allows you to recognize and build URLs in a Rack application. As well it contains an interface for use within Sinatra.
156
142
  email: joshbuddy@gmail.com
157
143
  executables: []