Class: RackStep::Controller

Inherits:
Object
  • Object
show all
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

NotFoundController

Defined Under Namespace

Modules: BasicHttpAuthentication, ErbRendering

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeController

Returns a new instance of Controller.



12
13
14
15
16
17
# File 'lib/controller.rb', line 12

def initialize
  @response = RackStep::Response.new
  @response.body = ''
  @response.content_type = 'application/json'
  @response.status = 200
end

Instance Attribute Details

#requestObject

The request will be injected here.



7
8
9
# File 'lib/controller.rb', line 7

def request
  @request
end

#responseObject

The Rack::Response object that will be delivered to the user.



10
11
12
# File 'lib/controller.rb', line 10

def response
  @response
end

Instance Method Details

#afterObject

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?



40
41
# File 'lib/controller.rb', line 40

def after
end

#beforeObject

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?



31
32
# File 'lib/controller.rb', line 31

def before
end

#process_requestObject

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.



24
25
# File 'lib/controller.rb', line 24

def process_request
end