Class: RapidRunty::Application
- Defined in:
- lib/rapid_runty/application.rb,
lib/rapid_runty/router/base_route.rb
Overview
Main framework Application class. Entry point for all requests.
Example:
class Application < RapidRunty::Application
end
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
-
#call(env) ⇒ status, ...
Returns a rack compatible response.
-
#dispatch(env, route, request) ⇒ Object
Dispatch the Controller and it’s action to be rendered.
-
#handle(env, request) ⇒ Object
Core response method.
-
#initialize ⇒ Application
constructor
A new instance of Application.
-
#not_found(path) ⇒ Rack::Response
Default 404 error.
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
7 8 9 |
# File 'lib/rapid_runty/router/base_route.rb', line 7 def initialize @routes = RapidRunty::Router::Routes.new end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
5 6 7 |
# File 'lib/rapid_runty/router/base_route.rb', line 5 def routes @routes end |
Instance Method Details
#call(env) ⇒ status, ...
Returns a rack compatible response.
Retrieves the controller and action from request URL making a new controller and send it to the action.
23 24 25 26 |
# File 'lib/rapid_runty/application.rb', line 23 def call(env) request = Rack::Request.new(env) handle(env, request) end |
#dispatch(env, route, request) ⇒ Object
Dispatch the Controller and it’s action to be rendered
33 34 35 36 37 38 |
# File 'lib/rapid_runty/router/base_route.rb', line 33 def dispatch(env, route, request) kontroller, action = route..values controller = Object.const_get("#{kontroller.camel_case}Controller") controller.new(env, request).call_action(action) end |
#handle(env, request) ⇒ Object
Core response method. Process the request and return the correct response or status message.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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.) dispatch(env, route, request) end end |
#not_found(path) ⇒ Rack::Response
Default 404 error
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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 |