lib/usher/interface/rack.rb in usher-0.6.0 vs lib/usher/interface/rack.rb in usher-0.6.1

- old
+ new

@@ -34,14 +34,13 @@ self.map(path, options.merge!(:conditions => {:request_method => "DELETE"}), &block) end end attr_reader :router - attr_accessor :app def initialize(app = nil, &blk) - @app = app || lambda { |env| ::Rack::Response.new("No route found", 404).finish } + @_app = app || lambda { |env| ::Rack::Response.new("No route found", 404).finish } @router = Usher.new(:request_methods => [:request_method, :host, :port, :scheme], :generator => Usher::Util::Generators::URL.new) instance_eval(&blk) if blk end def dup @@ -54,15 +53,16 @@ end def add(path, options = nil) @router.add_route(path, options) end - + alias_method :path, :add + # default { |env| ... } # default DefaultApp def default(app = nil, &block) - @app = app ? app : block + @_app = app ? app : block end # shortcuts for adding routes for HTTP methods, for example: # add("/url", :conditions => {:request_method => "POST"}}) # is the same as: @@ -133,22 +133,24 @@ # 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) - unless response - app - else - respondant = response.path.route.destination - respondant = app unless respondant.respond_to?(:call) - respondant - end + response && response.destination || _app end # Consume the path from path_info to script_name def consume_path!(request, response) request.env["SCRIPT_NAME"] = (request.env["SCRIPT_NAME"] + response.matched_path) || "" request.env["PATH_INFO"] = response.remaining_path || "" end + + def default_app + _app + end + + private + attr_reader :_app + end end end