Class: RackStep::Controller
- Inherits:
-
Object
- Object
- RackStep::Controller
- Defined in:
- lib/controller.rb
Overview
Abstract controller class with some helper methods. ALL your controllers MUST use this one as a superclass.
Direct Known Subclasses
Defined Under Namespace
Modules: BasicHttpAuthentication, ErbRendering
Instance Attribute Summary collapse
-
#request ⇒ Object
The request will be injected here.
-
#response ⇒ Object
The Rack::Response object that will be delivered to the user.
-
#settings ⇒ Object
The ‘global’ app settings will be injected here.
Instance Method Summary collapse
-
#after ⇒ Object
RackStep will always execute this method after processing the request of to the specified controller.
-
#before ⇒ Object
RackStep will always execute this method before delegating the request processing to the specified controller.
-
#initialize ⇒ Controller
constructor
A new instance of Controller.
-
#process_request ⇒ Object
Once the application receives a new request, the router will decide wich controller should process that request and will execute this method for the chosen controller.
Constructor Details
#initialize ⇒ Controller
18 19 20 21 22 23 |
# File 'lib/controller.rb', line 18 def initialize @response = RackStep::Response.new @response.body = '' @response.content_type = 'application/json' @response.status = 200 end |
Instance Attribute Details
#request ⇒ Object
The request will be injected here.
7 8 9 |
# File 'lib/controller.rb', line 7 def request @request end |
#response ⇒ Object
The Rack::Response object that will be delivered to the user.
10 11 12 |
# File 'lib/controller.rb', line 10 def response @response end |
#settings ⇒ Object
The ‘global’ app settings will be injected here. This hash variable is initialized only once (singleton) and may contain references to things that should be initialize only once during the app start (eg: database connection).
16 17 18 |
# File 'lib/controller.rb', line 16 def settings @settings end |
Instance Method Details
#after ⇒ Object
RackStep will always execute this method after processing the request of to the specified controller. The user may overwrite this method. This can be used to check for logging or any piece of code that must be executed after every request for this controller. This may be usefull if the user wants to create an abstract controllers. TODO: Is this really necessary?
46 47 |
# File 'lib/controller.rb', line 46 def after end |
#before ⇒ Object
RackStep will always execute this method before delegating the request processing to the specified controller. The user may overwrite this method. This may be usefull if the user wants to create an abstract controllers. TODO: Is this really necessary?
37 38 |
# File 'lib/controller.rb', line 37 def before end |
#process_request ⇒ Object
Once the application receives a new request, the router will decide wich controller should process that request and will execute this method for the chosen controller. So this is the most important method of this class and every controller should overwrite it to implement it’s business logic.
30 31 |
# File 'lib/controller.rb', line 30 def process_request end |