Class: Ramaze::Response

Inherits:
Rack::Response
  • Object
show all
Defined in:
lib/ramaze/response.rb

Overview

Ramaze::Response is a small wrapper around Rack::Response that makes it easier to send response data to the browser from a Ramaze application.

Author:

  • Michael Fellinger

Since:

  • 01-03-2008

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body = [], status = 200, header = {}, &block) ⇒ Response

Creates a new instance of the response class and processes the specified parameters. Once this has been done it calls Rack::Response#initialize.

Parameters:

  • body (Array) (defaults to: [])

    An array containing the data for the response body.

  • status (Fixnum) (defaults to: 200)

    The HTPP status code for the response.

  • header (Hash) (defaults to: {})

    A hash containing additional headers and their values.

  • block (Proc)

Author:

  • Michael Fellinger

Since:

  • 01-03-2008



27
28
29
30
31
# File 'lib/ramaze/response.rb', line 27

def initialize(body = [], status = 200, header = {}, &block)
  modified_header = Ramaze.options.header.merge(header)
  header.merge!(modified_header)
  super
end

Class Method Details

.currentObject

Alias for Current.response

Since:

  • 01-03-2008



13
# File 'lib/ramaze/response.rb', line 13

def self.current; Current.response; end

Instance Method Details

#body=(obj) ⇒ Object

Sets the body of the response to the given object.

Parameters:

  • obj (Object)

    The object to use as the response body.

Author:

  • Michael Fellinger

Since:

  • 01-03-2008



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ramaze/response.rb', line 54

def body=(obj)
  if obj.respond_to?(:stat)
    @length = obj.stat.size
    @body   = obj
  elsif obj.respond_to?(:size)
    @body   = []
    @length = 0
    write(obj)
  else
    raise(ArgumentError, "Invalid body: %p" % obj)
  end
end

#build(new_body = nil, new_status = nil, new_header = nil) ⇒ Object

Updates the body, status and headers.

See Also:

Author:

  • Michael Fellinger

Since:

  • 01-03-2008



40
41
42
43
44
45
# File 'lib/ramaze/response.rb', line 40

def build(new_body = nil, new_status = nil, new_header = nil)
  self.header.merge!(new_header) if new_header

  self.body   = new_body   if new_body
  self.status = new_status if new_status
end