http_router 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -104,21 +104,21 @@ class HttpRouter
104
104
  # Returns the route object.
105
105
  def options(path, opts = {}, &app); add_with_request_method(path, :options, opts, &app); end
106
106
 
107
- def recognize(env)
108
- call(env, false)
107
+ def recognize(env, &blk)
108
+ call(env, false, &blk)
109
109
  end
110
110
 
111
111
  # Rack compatible #call. If matching route is found, and +dest+ value responds to #call, processing will pass to the matched route. Otherwise,
112
112
  # the default application will be called. The router will be available in the env under the key <tt>router</tt>. And parameters matched will
113
113
  # be available under the key <tt>router.params</tt>.
114
- def call(env, perform_call = true)
114
+ def call(env, perform_call = true, &blk)
115
115
  rack_request = ::Rack::Request.new(env)
116
116
  if redirect_trailing_slash? && (rack_request.head? || rack_request.get?) && rack_request.path_info[-1] == ?/
117
117
  response = ::Rack::Response.new
118
118
  response.redirect(request.path_info[0, request.path_info.size - 1], 302)
119
119
  response.finish
120
120
  else
121
- request = Request.new(rack_request.path_info, rack_request, perform_call)
121
+ request = Request.new(rack_request.path_info, rack_request, perform_call, &blk)
122
122
  response = catch(:success) { @root[request] }
123
123
  if response
124
124
  response
@@ -1,9 +1,10 @@
1
1
  class HttpRouter
2
2
  class Request
3
+ attr_reader :acceptance_test
3
4
  attr_accessor :path, :params, :rack_request, :extra_env, :continue
4
5
  alias_method :rack, :rack_request
5
- def initialize(path, rack_request, perform_call)
6
- @rack_request, @perform_call = rack_request, perform_call
6
+ def initialize(path, rack_request, perform_call, &acceptance_test)
7
+ @rack_request, @perform_call, @acceptance_test = rack_request, perform_call, acceptance_test
7
8
  @path = (path[0] == ?/ ? path[1, path.size] : path).split(/\//)
8
9
  @path << '' if path.size > 1 && path[-1] == ?/
9
10
  @extra_env = {}
@@ -1,6 +1,7 @@
1
1
  class HttpRouter
2
2
  class Response < Struct.new(:request, :path)
3
3
  attr_reader :params
4
+ attr_accessor :acceptance_response
4
5
  def initialize(request, path)
5
6
  super(request, path)
6
7
  @params = path.hashify_params(request.params)
@@ -271,6 +271,10 @@ class HttpRouter
271
271
  end
272
272
  response = path_obj.route.dest.call(env)
273
273
  router.pass_on_response(response) ? throw(:pass) : throw(:success, response)
274
+ elsif req.acceptance_test
275
+ response = Response.new(req, path_obj)
276
+ req.acceptance_test[response]
277
+ throw :success, response if response.acceptance_response
274
278
  else
275
279
  throw :success, Response.new(req, path_obj)
276
280
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  class HttpRouter #:nodoc
3
- VERSION = '0.7.6'
3
+ VERSION = '0.7.7'
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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 6
10
- version: 0.7.6
9
+ - 7
10
+ version: 0.7.7
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-05-10 00:00:00 -07:00
18
+ date: 2011-05-12 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency