lib/usher/interface/rack_interface.rb in usher-0.5.5 vs lib/usher/interface/rack_interface.rb in usher-0.5.6

- old
+ new

@@ -60,40 +60,52 @@ response = @router.recognize(request = Rack::Request.new(env), request.path_info) after_match(env, response) if response determine_respondant(response).call(env) end - def generate(route, params = nil, options = nil) - @usher.generator.generate(route, params, options) + def generate(route, options = nil) + @router.generator.generate(route, options) end # Allows a hook to be placed for sub classes to make use of between matching # and calling the application # # @api plugin def after_match(env, response) - env['usher.params'] ||= {} - params = response.path.route.default_values || {} - response.params.each{|hk| params[hk.first] = hk.last} - env['usher.params'].merge!(params) - - # consume the path_info to the script_name response.remaining_path - env["SCRIPT_NAME"] << response.matched_path || "" - env["PATH_INFO"] = response.remaining_path || "" + params = response.path.route.default_values ? + response.path.route.default_values.merge(Hash[response.params]) : + Hash[response.params] + + env['usher.params'] ? + env['usher.params'].merge!(params) : + env['usher.params'] = params + + # consume the path_info to the script_name + # response.remaining_path + consume_path!(env, response) if response.partial_match? end # Determines which application to respond with. # # Within the request when determine respondant is called # If there is a matching route to an application, that # application is called, Otherwise the middleware application is called. # # @api private def determine_respondant(response) - return app if response.nil? - respondant = response.path.route.destination - respondant = app unless respondant.respond_to?(:call) - respondant + unless response + app + else + respondant = response.path.route.destination + respondant = app unless respondant.respond_to?(:call) + respondant + end + end + + # Consume the path from path_info to script_name + def consume_path!(env, response) + env["SCRIPT_NAME"] = (env["SCRIPT_NAME"] + response.matched_path) || "" + env["PATH_INFO"] = response.remaining_path || "" end end end end