lib/plezi/router/router.rb in plezi-0.14.1 vs lib/plezi/router/router.rb in plezi-0.14.2

- old
+ new

@@ -11,12 +11,14 @@ @app = nil module_function def new(app) - puts 'Plezi as Middleware' - @app = ((app == Plezi.app) ? nil : app) + if app && app != call_method + puts 'Plezi as Middleware' + @app = app + end Plezi.app end def call(env) request = Rack::Request.new(env) @@ -34,20 +36,26 @@ response = Rack::Response.new response.write ::Plezi::Base::Err500Ctrl.new._pl_respond(request, response, request.params) return response.finish end + # returns the `call` method. Used repeatedly in middleware mode and only once in application mode. + def call_method + @call_method ||= Plezi::Base::Router.method(:call) + end + def route(path, controller) path = path.chomp('/'.freeze) unless path == '/'.freeze case controller when :client controller = ::Plezi::Base::Router::ADClient when :assets controller = ::Plezi::Base::Assets path << '/*'.freeze unless path[-1] == '*'.freeze when Regexp path << '/*'.freeze unless path[-1] == '*'.freeze + return @routes << RouteRewrite.new(path, controller) end @routes << Route.new(path, controller) end def list @@ -109,10 +117,10 @@ url << r.prefix url.clear if url == '/'.freeze while names.any? && params[name[0]] url << "/#{Rack::Utils.escape params[names.shift]}" end - url = '/'.dup if url.empty? + url << '/'.freeze if url.empty? (url << '?') << Rack::Utils.build_nested_query(params) if params.any? url end end end