class RapidRunty::Application

Main framework Application class. Entry point for all requests.

Example:

class Application < RapidRunty::Application
end

Attributes

routes[R]

Public Class Methods

new() click to toggle source
# File lib/rapid_runty/router/base_route.rb, line 7
def initialize
  @routes = RapidRunty::Router::Routes.new
end

Public Instance Methods

call(env) click to toggle source

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]]

# File lib/rapid_runty/application.rb, line 23
def call(env)
  request = Rack::Request.new(env)
  handle(env, request)
end
dispatch(env, route, request) click to toggle source

Dispatch the Controller and it's action to be rendered

# File lib/rapid_runty/router/base_route.rb, line 33
def dispatch(env, route, request)
  kontroller, action = route.options.values

  controller = Object.const_get("#{kontroller.camel_case}Controller")
  controller.new(env, request).call_action(action)
end
handle(env, request) click to toggle source

Core response method. Process the request and return the correct response or status message.

@param env @param [Rack::Request] request @param [Rack::Response] response

# File lib/rapid_runty/router/base_route.rb, line 17
def handle(env, request)
  verb, path = route_args(request).values

  route = routes.find_route(verb, path)
  if route.nil?
    not_found(path)
  else
    param = "&#{Rack::Utils.build_nested_query(route.placeholders)}"
    env['QUERY_STRING'] << param
    env.merge!(route.options)
    dispatch(env, route, request)
  end
end
not_found(path) click to toggle source

Default 404 error

@param [Rack::Response]

@return [Rack::Response]

# File lib/rapid_runty/router/base_route.rb, line 46
def not_found(path)
  [
    404,
    {},
    [
      "
      <html>
        <head>
          <body>
            <h1>404 Page not found for #{path}</h1>
          </body>
        </head>
      </html>
      "
    ]
  ]

end

Private Instance Methods

route_args(request) click to toggle source
# File lib/rapid_runty/router/base_route.rb, line 67
def route_args(request)
  {
    verb: request.request_method.downcase.to_sym,
    path: Rack::Utils.unescape(request.path_info)
  }
end