http_router 0.7.0 → 0.7.1

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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Joshua Hull, http://github.com/joshbuddy/http_router
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/http_router.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.summary = "A kick-ass HTTP router for use in Rack"
11
11
  s.description = "This library allows you to recognize and build URLs in a Rack application."
12
12
  s.email = %q{joshbuddy@gmail.com}
13
- s.extra_rdoc_files = ['README.md']
13
+ s.extra_rdoc_files = ['README.md', 'LICENSE']
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.homepage = %q{http://github.com/joshbuddy/http_router}
16
16
  s.rdoc_options = ["--charset=UTF-8"]
@@ -265,7 +265,8 @@ class HttpRouter
265
265
  env["PATH_INFO"] = ''
266
266
  env["SCRIPT_NAME"] += req.rack_request.path_info
267
267
  end
268
- throw :success, @app.call(env)
268
+ response = @app.call(env)
269
+ router.pass_on_response(response) ? throw(:pass) : throw(:success, response)
269
270
  else
270
271
  throw :success, Response.new(req, path_obj)
271
272
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  class HttpRouter #:nodoc
3
- VERSION = '0.7.0'
3
+ VERSION = '0.7.1'
4
4
  end
data/lib/http_router.rb CHANGED
@@ -58,19 +58,22 @@ class HttpRouter
58
58
  #
59
59
  # Returns the route object.
60
60
  def add(path, opts = {}, &app)
61
- route = case path
62
- when Regexp
63
- RegexRoute.new(self, path, opts)
64
- else
65
- Route.new(self, path, opts)
66
- end
67
- add_route(route)
61
+ route = add_route((Regexp === path ? RegexRoute : Route).new(self, path, opts))
68
62
  route.to(app) if app
69
63
  route
70
64
  end
71
65
 
72
66
  def add_route(route)
73
67
  @routes << route
68
+ route
69
+ end
70
+
71
+ def pass_on_response(response)
72
+ response[1]['X-Cascade'] == 'pass'
73
+ end
74
+
75
+ def set_pass_on_response(&blk)
76
+ extend(Module.new{define_method(:pass_on_response, &blk)})
74
77
  end
75
78
 
76
79
  # Adds a path that only responds to the request method +GET+.
@@ -20,6 +20,23 @@ class TestRecognition < MiniTest::Unit::TestCase
20
20
  assert_body 'working', router.call(Rack::MockRequest.env_for('/'))
21
21
  end
22
22
 
23
+ def test_passing_with_cascade
24
+ passed, working = router {
25
+ add('/').to { |env| [200, {'X-Cascade' => 'pass'}, ['pass']] }
26
+ add('/').to { |env| [200, {}, ['working']] }
27
+ }
28
+ assert_body 'working', router.call(Rack::MockRequest.env_for('/'))
29
+ end
30
+
31
+ def test_passing_with_custom_pass_wrapper
32
+ passed, working = router {
33
+ add('/').to { |env| [404, {}, ['pass']] }
34
+ add('/').to { |env| [200, {}, ['working']] }
35
+ }
36
+ router.set_pass_on_response {|response| response.first == 404}
37
+ assert_body 'working', router.call(Rack::MockRequest.env_for('/'))
38
+ end
39
+
23
40
  def test_optional
24
41
  route = router {
25
42
  add 'one(/two(/three(/four)(/five)))'
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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 0
10
- version: 0.7.0
9
+ - 1
10
+ version: 0.7.1
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-04-18 00:00:00 -07:00
18
+ date: 2011-04-23 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -162,11 +162,12 @@ extensions: []
162
162
 
163
163
  extra_rdoc_files:
164
164
  - README.md
165
+ - LICENSE
165
166
  files:
166
167
  - .gitignore
167
168
  - .rspec
168
- - CHANGELOG
169
169
  - Gemfile
170
+ - LICENSE
170
171
  - README.md
171
172
  - Rakefile
172
173
  - benchmarks/gen2.rb
data/CHANGELOG DELETED
@@ -1,28 +0,0 @@
1
- == 0.3.2
2
-
3
- * Made the sinatra extension Ruby 1.9.2 compatible (Matt Aimonetti, 05fb162)
4
-
5
- == 0.3.1
6
-
7
- * Node transplant in request tree building not working in all cases. (Joshua Hull, f82ae82)
8
- * Smaller set of benchmarks to match rack-mount (Joshua Hull, ca723e9)
9
- * Better 405 test that is order invariant. (Thanks Cored!) (Joshua Hull, 4ad40e6)
10
-
11
- == 0.3.0
12
-
13
- * Unescape param values (Joshua Hull, d7a6a1f)
14
- * Removed useless test in request method adding (Joshua Hull, bcaade2)
15
-
16
- == 0.2.5
17
-
18
- * Walk entire tree looking for possible request_methods to return on 405 if a match isn't achieved. (Joshua Hull, 3e8631f)
19
- * Upgraded deps + spec running (Joshua Hull, fcefce9)
20
- * Simplified route cloning (Joshua Hull, 4b0ff59)
21
- * Added partial matching to route cloning (Joshua Hull, d1a57d8)
22
- * Merge branch 'master' of github.com:joshbuddy/http_router (Joshua Hull, 7f42a27)
23
- * Convert to Tumbler (Joshua Hull, 295e6a2)
24
- * Updates cloning (Daniel Neighman, 37178bf)
25
- * Add Rack::urlmap replacement (Joshua Hull, 2868044)
26
- * Added scheme example (Joshua Hull, f23da20)
27
- * Added static example (Joshua Hull, df54ee0)
28
-