Class: RackStep::App
- Inherits:
-
Object
- Object
- RackStep::App
- Defined in:
- lib/rackstep.rb
Overview
Abstract class with the base of a RackStep app. This class MUST be extended by the user.
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Stores the received request which will then be injected into the user controllers.
Class Method Summary collapse
-
.add_route(verb, path, controller) ⇒ Object
This method was created to make it easier for the user to add routes, but it will delegate to the router singleton class.
-
.call(env) ⇒ Object
Static method called from config.ru (“run App”).
Instance Method Summary collapse
-
#initialize(env) ⇒ App
constructor
Initialize the request instance variable and add a default “not found” route.
-
#process_request ⇒ Object
TODO: Code Climate says this method is too big.
-
#router ⇒ Object
Access the Router, a singleton class that stores all the registred routes.
Constructor Details
#initialize(env) ⇒ App
Initialize the request instance variable and add a default “not found” route.
35 36 37 38 39 40 |
# File 'lib/rackstep.rb', line 35 def initialize(env) @request = Rack::Request.new(env) # Adding default routes to handle page not found (404). router.add_route_for_all_verbs('notfound', RackStep::NotFoundController) end |
Instance Attribute Details
#request ⇒ Object (readonly)
Stores the received request which will then be injected into the user controllers.
21 22 23 |
# File 'lib/rackstep.rb', line 21 def request @request end |
Class Method Details
.add_route(verb, path, controller) ⇒ Object
This method was created to make it easier for the user to add routes, but it will delegate to the router singleton class.
63 64 65 66 |
# File 'lib/rackstep.rb', line 63 def self.add_route(verb, path, controller) router = Router.instance router.add_route(verb, path, controller) end |
.call(env) ⇒ Object
Static method called from config.ru (“run App”).
29 30 31 32 |
# File 'lib/rackstep.rb', line 29 def self.call(env) response = new(env).process_request return response.status, response.headers, response.body end |
Instance Method Details
#process_request ⇒ Object
TODO: Code Climate says this method is too big.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rackstep.rb', line 43 def process_request verb = request.request_method path = request.path # In RackStep, each request is processed by a controller. The router # is responsable to find, based on the given path and http verb, # the apropriate controller to handle the request. route = router.find_route_for(path, verb) controller = route.controller.new controller.request = request controller.send(:before) controller.send(:process_request) controller.send(:after) response = controller.response return response end |
#router ⇒ Object
Access the Router, a singleton class that stores all the registred routes.
24 25 26 |
# File 'lib/rackstep.rb', line 24 def router Router.instance end |