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)
- 
  
    
      + (Object) call(env) 
    
    
  
  
  
  
  
  
  
  
  
    
initialize a new instance of the controller and call response on it.
 - 
  
    
      + (Object) renderer 
    
    
  
  
  
  
  
  
  
  
  
    
get the renderer set in the controller.
 - 
  
    
      + (Object) renderer=(renderer) 
    
    
  
  
  
  
  
  
  
  
  
    
set the renderer to use in the controller.
 
Instance Method Summary (collapse)
- 
  
    
      - (Controller) initialize(request) 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
initialize the controller.
 - 
  
    
      - (Object) renderer 
    
    
  
  
  
  
  
  
  
  
  
    
a small helper to get the actual renderer.
 - 
  
    
      - (Object) response 
    
    
  
  
  
  
  
  
  
  
  
    
build the response and return it.
 
Constructor Details
- (Controller) initialize(request)
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
+ (Object) call(env)
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.new(env)).response end  | 
  
+ (Object) renderer
get the renderer set in the controller
      19 20 21  | 
    
      # File 'lib/zero/controller.rb', line 19 def self.renderer @@renderer end  | 
  
+ (Object) renderer=(renderer)
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
- (Object) renderer
a small helper to get the actual renderer
      24 25 26  | 
    
      # File 'lib/zero/controller.rb', line 24 def renderer self.class.renderer end  | 
  
- (Object) response
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  |