http_router 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@ pkg
2
2
  *.gem
3
3
  .bundle
4
4
  rdoc
5
+ Gemfile.lock
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.3.1
2
+
3
+ * Node transplant in request tree building not working in all cases. (Joshua Hull, f82ae82)
4
+ * Smaller set of benchmarks to match rack-mount (Joshua Hull, ca723e9)
5
+ * Better 405 test that is order invariant. (Thanks Cored!) (Joshua Hull, 4ad40e6)
6
+
1
7
  == 0.3.0
2
8
 
3
9
  * Unescape param values (Joshua Hull, d7a6a1f)
data/benchmarks/rec2.rb CHANGED
@@ -5,31 +5,31 @@ require 'lib/http_router'
5
5
  u = HttpRouter.new
6
6
  u.add('/simple').to {|env| [200, {'Content-type'=>'text/html'}, []]}
7
7
  u.add('/simple/again').compile.to {|env| [200, {'Content-type'=>'text/html'}, []]}
8
- u.add('/simple/again/and/again').compile.to {|env| [200, {'Content-type'=>'text/html'}, []]}
8
+ #u.add('/simple/again/and/again').compile.to {|env| [200, {'Content-type'=>'text/html'}, []]}
9
9
  u.add('/dynamic/:variable').compile.to {|env| [200, {'Content-type'=>'text/html'}, []]}
10
- u.add('/rails/:controller/:action/:id').compile.to {|env| [200, {'Content-type'=>'text/html'}, []]}
11
- u.add('/greedy/:greed').matching(:greed => /.*/).compile.to {|env| [200, {'Content-type'=>'text/html'}, []]}
10
+ #u.add('/rails/:controller/:action/:id').compile.to {|env| [200, {'Content-type'=>'text/html'}, []]}
11
+ #u.add('/greedy/:greed').matching(:greed => /.*/).compile.to {|env| [200, {'Content-type'=>'text/html'}, []]}
12
12
  #u.add('/greedy/hey.:greed.html').to {|env| [200, {'Content-type'=>'text/html'}, []]}
13
13
 
14
- #puts Benchmark.measure {
15
- # ('aa'..'nn').each do |first|
16
- # ('a'..'n').each do |second|
17
- # u.add("/#{first}/#{second}").compile
18
- # end
19
- # end
14
+ puts Benchmark.measure {
15
+ ('aa'..'nn').each do |first|
16
+ ('a'..'n').each do |second|
17
+ u.add("/#{first}/#{second}").to {|env| [200, {'Content-type'=>'text/html'}, []]}
18
+ end
19
+ end
20
20
  #
21
- # puts "u.routes.size: #{u.routes.size}"
22
- #}
21
+ puts "u.routes.size: #{u.routes.size}"
22
+ }
23
23
  #
24
24
  TIMES = 50_000
25
25
 
26
26
  simple_env = Rack::MockRequest.env_for('/simple')
27
27
  simple2_env = Rack::MockRequest.env_for('/simple/again')
28
- simple3_env = Rack::MockRequest.env_for('/simple/again/and/again')
28
+ #simple3_env = Rack::MockRequest.env_for('/simple/again/and/again')
29
29
  simple_and_dynamic_env = Rack::MockRequest.env_for('/dynamic/anything')
30
- simple_and_dynamic_env1 = Rack::MockRequest.env_for('/rails/controller/action/id')
31
- simple_and_dynamic_env2 = Rack::MockRequest.env_for('/greedy/controller/action/id')
32
- simple_and_dynamic_env3 = Rack::MockRequest.env_for('/greedy/hey.hello.html')
30
+ #simple_and_dynamic_env1 = Rack::MockRequest.env_for('/rails/controller/action/id')
31
+ #simple_and_dynamic_env2 = Rack::MockRequest.env_for('/greedy/controller/action/id')
32
+ #simple_and_dynamic_env3 = Rack::MockRequest.env_for('/greedy/hey.hello.html')
33
33
 
34
34
  RBench.run(TIMES) do
35
35
 
@@ -41,21 +41,21 @@ RBench.run(TIMES) do
41
41
  u.call(simple2_env).first == 200 or raise
42
42
  end
43
43
 
44
- report "8 levels, static" do
45
- u.call(simple3_env).first == 200 or raise
46
- end
44
+ #report "8 levels, static" do
45
+ # u.call(simple3_env).first == 200 or raise
46
+ #end
47
47
 
48
48
  report "4 levels, 1 dynamic" do
49
49
  u.call(simple_and_dynamic_env).first == 200 or raise
50
50
  end
51
51
 
52
- report "8 levels, 3 dynamic" do
53
- u.call(simple_and_dynamic_env1).first == 200 or raise
54
- end
55
-
56
- report "4 levels, 1 greedy" do
57
- u.call(simple_and_dynamic_env2).first == 200 or raise
58
- end
52
+ #report "8 levels, 3 dynamic" do
53
+ # u.call(simple_and_dynamic_env1).first == 200 or raise
54
+ #end
55
+ #
56
+ #report "4 levels, 1 greedy" do
57
+ # u.call(simple_and_dynamic_env2).first == 200 or raise
58
+ #end
59
59
 
60
60
  end
61
61
 
@@ -121,6 +121,7 @@ class HttpRouter
121
121
  next_node = current_node.dup
122
122
  current_node.reset!
123
123
  current_node.request_method = method
124
+ current_node.catchall ||= next_node
124
125
  redo
125
126
  end
126
127
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  class HttpRouter #:nodoc
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  end
@@ -124,7 +124,11 @@ describe "HttpRouter#recognize" do
124
124
  @router.recognize(Rack::MockRequest.env_for('/test', :method => 'GET')).destination.should == :get
125
125
  @router.recognize(Rack::MockRequest.env_for('/test', :method => 'DELETE')).destination.should == :delete
126
126
  @router.recognize(Rack::MockRequest.env_for('/test', :method => 'PUT')).status.should == 405
127
- @router.recognize(Rack::MockRequest.env_for('/test', :method => 'PUT')).headers['Allow'].should == "DELETE, GET, POST"
127
+ methods = @router.recognize(Rack::MockRequest.env_for('/test', :method => 'PUT')).headers['Allow'].split(/,\s+/)
128
+ methods.should include('DELETE')
129
+ methods.should include('GET')
130
+ methods.should include('POST')
131
+ methods.size.should == 3
128
132
  @router.recognize(Rack::MockRequest.env_for('/test.html', :method => 'POST')).destination.should == :post
129
133
  @router.recognize(Rack::MockRequest.env_for('/test.html', :method => 'GET')).destination.should == :get
130
134
  @router.recognize(Rack::MockRequest.env_for('/test.html', :method => 'DELETE')).destination.should == :delete
@@ -153,6 +157,18 @@ describe "HttpRouter#recognize" do
153
157
  @router.recognize(Rack::MockRequest.env_for('/test', :method => 'PUT')).route.named.should == :test_catchall
154
158
  end
155
159
 
160
+ it "should try multiple request method restrictions in both orders" do
161
+ @router.add("/test").host('host2').to(:host2)
162
+ @router.add("/test").post.to(:post)
163
+ @router.add("/test").host('host2').get.to(:host2_get)
164
+ @router.add("/test").post.host('host2').to(:host2_post)
165
+
166
+ @router.recognize(Rack::MockRequest.env_for('http://host2/test', :method => 'PUT')).dest.should == :host2
167
+ @router.recognize(Rack::MockRequest.env_for('http://host1/test', :method => 'POST')).dest.should == :post
168
+ @router.recognize(Rack::MockRequest.env_for('http://host2/test', :method => 'GET')).dest.should == :host2_get
169
+ @router.recognize(Rack::MockRequest.env_for('http://host2/test', :method => 'POST')).dest.should == :host2_post
170
+ end
171
+
156
172
  it "should try both specific and non-specifc routes" do
157
173
  @router.post("/test").host('host1').to(:post_host1)
158
174
  @router.add("/test").host('host2').to(:any_post2)
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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hull
@@ -15,10 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-27 00:00:00 -04:00
18
+ date: 2010-06-30 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
+ prerelease: false
22
23
  version_requirements: &id001 !ruby/object:Gem::Requirement
23
24
  none: false
24
25
  requirements:
@@ -30,10 +31,10 @@ dependencies:
30
31
  - 0
31
32
  version: "1.0"
32
33
  requirement: *id001
33
- name: rack
34
- prerelease: false
35
34
  type: :runtime
35
+ name: rack
36
36
  - !ruby/object:Gem::Dependency
37
+ prerelease: false
37
38
  version_requirements: &id002 !ruby/object:Gem::Requirement
38
39
  none: false
39
40
  requirements:
@@ -46,10 +47,10 @@ dependencies:
46
47
  - 1
47
48
  version: 0.2.1
48
49
  requirement: *id002
49
- name: url_mount
50
- prerelease: false
51
50
  type: :runtime
51
+ name: url_mount
52
52
  - !ruby/object:Gem::Dependency
53
+ prerelease: false
53
54
  version_requirements: &id003 !ruby/object:Gem::Requirement
54
55
  none: false
55
56
  requirements:
@@ -60,10 +61,10 @@ dependencies:
60
61
  - 0
61
62
  version: "0"
62
63
  requirement: *id003
63
- name: rspec
64
- prerelease: false
65
64
  type: :development
65
+ name: rspec
66
66
  - !ruby/object:Gem::Dependency
67
+ prerelease: false
67
68
  version_requirements: &id004 !ruby/object:Gem::Requirement
68
69
  none: false
69
70
  requirements:
@@ -74,10 +75,10 @@ dependencies:
74
75
  - 0
75
76
  version: "0"
76
77
  requirement: *id004
77
- name: rake
78
- prerelease: false
79
78
  type: :development
79
+ name: rake
80
80
  - !ruby/object:Gem::Dependency
81
+ prerelease: false
81
82
  version_requirements: &id005 !ruby/object:Gem::Requirement
82
83
  none: false
83
84
  requirements:
@@ -88,10 +89,10 @@ dependencies:
88
89
  - 0
89
90
  version: "0"
90
91
  requirement: *id005
91
- name: sinatra
92
- prerelease: false
93
92
  type: :development
93
+ name: sinatra
94
94
  - !ruby/object:Gem::Dependency
95
+ prerelease: false
95
96
  version_requirements: &id006 !ruby/object:Gem::Requirement
96
97
  none: false
97
98
  requirements:
@@ -102,10 +103,10 @@ dependencies:
102
103
  - 0
103
104
  version: "0"
104
105
  requirement: *id006
105
- name: rbench
106
- prerelease: false
107
106
  type: :development
107
+ name: rbench
108
108
  - !ruby/object:Gem::Dependency
109
+ prerelease: false
109
110
  version_requirements: &id007 !ruby/object:Gem::Requirement
110
111
  none: false
111
112
  requirements:
@@ -118,9 +119,8 @@ dependencies:
118
119
  - 11
119
120
  version: 0.0.11
120
121
  requirement: *id007
121
- name: tumbler
122
- prerelease: false
123
122
  type: :development
123
+ name: tumbler
124
124
  description: A kick-ass HTTP router for use in Rack & Sinatra
125
125
  email: joshbuddy@gmail.com
126
126
  executables: []
@@ -133,7 +133,6 @@ files:
133
133
  - .gitignore
134
134
  - CHANGELOG
135
135
  - Gemfile
136
- - Gemfile.lock
137
136
  - README.rdoc
138
137
  - Rakefile
139
138
  - Tumbler
data/Gemfile.lock DELETED
@@ -1,59 +0,0 @@
1
- ---
2
- dependencies:
3
- url_mount:
4
- group:
5
- - :default
6
- version: ">= 0.2.1"
7
- rake:
8
- group:
9
- - :development
10
- version: ">= 0"
11
- tumbler:
12
- group:
13
- - :development
14
- version: ">= 0.0.11"
15
- rspec:
16
- group:
17
- - :development
18
- version: ">= 0"
19
- rack:
20
- group:
21
- - :default
22
- version: ">= 1.0"
23
- sinatra:
24
- group:
25
- - :development
26
- version: ">= 0"
27
- rbench:
28
- group:
29
- - :development
30
- version: ">= 0"
31
- specs:
32
- - rake:
33
- version: 0.8.7
34
- - blockenspiel:
35
- version: 0.3.3
36
- - bundler:
37
- version: 0.9.26
38
- - callsite:
39
- version: 0.0.2
40
- - json:
41
- version: 1.4.3
42
- - rack:
43
- version: 1.2.1
44
- - rbench:
45
- version: 0.2.3
46
- - rspec:
47
- version: 1.3.0
48
- - sinatra:
49
- version: "1.0"
50
- - versionomy:
51
- version: 0.4.0
52
- - tumbler:
53
- version: 0.0.11
54
- - url_mount:
55
- version: 0.2.1
56
- hash: df813dada9b96e269c9f2dc81627e29f1dcec5f4
57
- sources:
58
- - Rubygems:
59
- uri: http://gemcutter.org