lib/rapid_runty/application.rb in rapid_runty-0.1.0 vs lib/rapid_runty/application.rb in rapid_runty-0.1.1

- old
+ new

@@ -1,15 +1,29 @@ +require "rapid_runty/routing" +require "rapid_runty/controller" + module RapidRunty # Main framework Application class. Entry point for all requests. + # + # Example: + # + # class Application < RapidRunty::Application + # end class Application ## # Returns a rack compatible response. # + # Retrieves the controller and action from request URL making a new + # controller and send it to the action. + # + # @param env [Hash] Rack environment Hash that includes CGI-like headers + # # @return [status, {headers}, [response]] array def call(env) - @req = Rack::Request.new(env) - path = @req.path_info - return [500, {}, []] if path == "/favicon.ico" - [200, { "Content-Type" => "text/html" }, ["Hello"]] + return [500, {}, []] if env["PATH_INFO"] == "/favicon.ico" + controller_class, action = get_controller_action(env) + controller = controller_class.new(env) + response = controller.send(action) + [200, { "Content-Type" => "text/html" }, [response]] end end end