require 'rapid_runty/router/routes' module RapidRunty class Application attr_reader :routes def initialize @routes = RapidRunty::Router::Routes.new end # Core response method. Process the request and return the correct # response or status message. # # @param env # @param [Rack::Request] request # @param [Rack::Response] response def handle(env, request, response) verb, path = route_args(request).values route = routes.find_route(verb, path) if route.nil? not_found(response, path) else param = "{Rack::Utils.build_nested_query(route.placeholders)}" env['QUERY_STRING'] << param env.merge!(route.options) response.write dispatch(env, route, response) end end ## # Dispatch the Controller and it's action to be rendered def dispatch(env, route, response) kontroller, action = route.options.values controller = Object.const_get("#{kontroller.camel_case}Controller") controller.new(env, response).public_send(action) end ## # Default 404 error # # @param [Rack::Response] # # @return [Rack::Response] def not_found(response, path) response.status = 404 response.write "