Class: Fastr::Controller

Inherits:
Object
  • Object
show all
Includes:
Async, Cookie, Deferrable, Filter, Template
Defined in:
lib/fastr/controller.rb

Overview

All controllers in a Fastr application should inherit from this class.

Sample Controller

class HomeController < Fastr::Controller
  def index
    [200, {"Content-Type" => "text/plain"}, ["Hello, World!"]]
  end
end

Response headers

You can add response headers directly by accessing the instance attribute #headers.

self.headers['My-Header'] = 'value'

Cookies

You can access cookies in the request by accessing the instance attribute #cookies.

self.cookies['MYCOOKIE']

Params

You can access the parameters in the request by accessing the instance attribute #params.

self.params['paramSentInRequest']

Author:

  • Chris Moos

Constant Summary

Constants included from Template

Template::EXTENSIONS, Template::TEMPLATE_CACHE

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from Async

#async_resp, #render_async

Methods included from Filter

execute_filter, #filter_continue, #filter_stop, get_filters, get_filters_for_action, included, run_after_filters, run_before_filters, run_filter?

Methods included from Log

create_logger, included, level=

Methods included from Cookie

#set_cookie

Methods included from Deferrable

#defer_response

Methods included from Template

#engine_for, included, register_extensions, #render, #render_json, #render_template, #render_template_to_string, #render_text, #template_extensions

Instance Attribute Details

#appFastr::Application

The application for the controller's current request.

Returns:


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

def app
  @app
end

#cookiesHash

Cookies sent in the request

Returns:

  • (Hash)

56
57
58
# File 'lib/fastr/controller.rb', line 56

def cookies
  @cookies
end

#envHash

The current Rack environment for the request.

Returns:

  • (Hash)

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

def env
  @env
end

#get_paramsHash

GET parameters.

Returns:

  • (Hash)

61
62
63
# File 'lib/fastr/controller.rb', line 61

def get_params
  @get_params
end

#headersHash

Headers to send in the response.

Returns:

  • (Hash)

51
52
53
# File 'lib/fastr/controller.rb', line 51

def headers
  @headers
end

#paramsHash

The params for this request.

Returns:

  • (Hash)

41
42
43
# File 'lib/fastr/controller.rb', line 41

def params
  @params
end

#post_paramsHash

POST parameters.

Returns:

  • (Hash)

66
67
68
# File 'lib/fastr/controller.rb', line 66

def post_params
  @post_params
end

Class Method Details

.inherited(kls) ⇒ Object


74
75
76
# File 'lib/fastr/controller.rb', line 74

def self.inherited(kls)
  kls.instance_eval('include Fastr::Log')
end