Class: Ramaze::Response
- Inherits:
-
Rack::Response
- Object
- Rack::Response
- Ramaze::Response
- 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.
Class Method Summary collapse
-
.current ⇒ Object
Alias for Current.response.
Instance Method Summary collapse
-
#body=(obj) ⇒ Object
Sets the body of the response to the given object.
-
#build(new_body = nil, new_status = nil, new_header = nil) ⇒ Object
Updates the body, status and headers.
-
#initialize(body = [], status = 200, header = {}, &block) ⇒ Response
constructor
Creates a new instance of the response class and processes the specified parameters.
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.
27 28 29 30 31 |
# File 'lib/ramaze/response.rb', line 27 def initialize(body = [], status = 200, header = {}, &block) modified_header = Ramaze..header.merge(header) header.merge!(modified_header) super end |
Class Method Details
.current ⇒ Object
Alias for Current.response
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.
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.
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 |