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



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

#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

#settingsObject

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

#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?



46
47
# File 'lib/controller.rb', line 46

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?



37
38
# File 'lib/controller.rb', line 37

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.



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

def process_request
end