Class Sinatra::EventContext
In: lib/sinatra/context.rb
Parent: Object

Methods

body   error   header   headers   params   redirect   session   status  

Included Modules

Sinatra::Renderer

Attributes

request  [R] 

Public Instance methods

Sets or returns the body Usage

  body 'test'

or

  body do
    'test'
  end

both are the same

[Source]

    # File lib/sinatra/context.rb, line 32
32:     def body(value = nil, &block)
33:       @body = value if value
34:       @body = block.call if block
35:       @body
36:     end

Renders an exception to body and sets status to 500

[Source]

    # File lib/sinatra/context.rb, line 39
39:     def error(value = nil)
40:       if value
41:         status 500
42:         @error = value
43:         erb :error, :views_directory => SINATRA_ROOT + '/files/'
44:       end
45:       @error
46:     end
header(value = nil)

Alias for headers

Sets or returns response headers

Usage

  header 'Content-Type' => 'text/html'
  header 'Foo' => 'Bar'

or

  headers 'Content-Type' => 'text/html',
          'Foo' => 'Bar'

Whatever blows your hair back

[Source]

    # File lib/sinatra/context.rb, line 58
58:     def headers(value = nil)
59:       @headers.merge!(value) if value
60:       @headers
61:     end

Returns a Hash of params. Keys are symbolized

[Source]

    # File lib/sinatra/context.rb, line 70
70:     def params
71:       @params ||= @request.params.symbolize_keys
72:     end

Redirect to a url

[Source]

    # File lib/sinatra/context.rb, line 75
75:     def redirect(path)
76:       logger.info "Redirecting to: #{path}"
77:       status 302
78:       header 'Location' => path
79:     end

Returns a Hash of session data. Keys are symbolized

[Source]

    # File lib/sinatra/context.rb, line 65
65:     def session
66:       request.env['rack.session']
67:     end

Sets or returns the status

[Source]

    # File lib/sinatra/context.rb, line 18
18:     def status(value = nil)
19:       @status = value if value
20:       @status || 200
21:     end

[Validate]