Class: Zero::Controller
- Inherits:
-
Object
- Object
- Zero::Controller
- Defined in:
- lib/zero/controller.rb
Overview
abstract class to make creation of controllers easier
This abstract class creates an interface to make it easier to write rack compatible controllers. It catches #call and creates a new instance with the environment and calls #render on it.
Class Method Summary collapse
-
.call(env) ⇒ Object
initialize a new instance of the controller and call response on it.
-
.renderer ⇒ Object
get the renderer set in the controller.
-
.renderer=(renderer) ⇒ Object
set the renderer to use in the controller.
Instance Method Summary collapse
-
#initialize(request) ⇒ Controller
constructor
initialize the controller.
-
#renderer ⇒ Object
a small helper to get the actual renderer.
-
#response ⇒ Object
build the response and return it.
Constructor Details
#initialize(request) ⇒ Controller
initialize the controller
30 31 32 33 |
# File 'lib/zero/controller.rb', line 30 def initialize(request) @request = request @response = Zero::Response.new end |
Class Method Details
.call(env) ⇒ Object
initialize a new instance of the controller and call response on it
9 10 11 |
# File 'lib/zero/controller.rb', line 9 def self.call(env) new(Zero::Request.create(env)).response end |
.renderer ⇒ Object
get the renderer set in the controller
19 20 21 |
# File 'lib/zero/controller.rb', line 19 def self.renderer @@renderer end |
.renderer=(renderer) ⇒ Object
set the renderer to use in the controller
14 15 16 |
# File 'lib/zero/controller.rb', line 14 def self.renderer=(renderer) @@renderer = renderer end |
Instance Method Details
#renderer ⇒ Object
a small helper to get the actual renderer
24 25 26 |
# File 'lib/zero/controller.rb', line 24 def renderer self.class.renderer end |
#response ⇒ Object
build the response and return it
This method calls #process if it was defined so make it easier to process the request before rendering stuff.
40 41 42 43 44 |
# File 'lib/zero/controller.rb', line 40 def response process if respond_to?(:process) render @response.to_a end |