Class: Waves::Response

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
lib/waves/response/response.rb,
lib/waves/response/packaged.rb,
lib/waves/response/redirects.rb,
lib/waves/response/client_errors.rb

Overview

Waves::Response represents an HTTP response and has methods for constructing a response. These include setters for content_type, content_length, location, and expires headers. You may also set the headers directly using the [] operator. See Rack::Response for documentation of any method not defined here.

Defined Under Namespace

Modules: ClientError, ClientErrors, Redirect, Redirects Classes: Packaged

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Response

Create a new response. Takes the request object. You shouldn’t need to call this directly.



13
14
15
16
# File 'lib/waves/response/response.rb', line 13

def initialize( request )
  @request = request
  @response = Rack::Response.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/waves/response/response.rb', line 50

def method_missing( name, *args, &block )
  if @response.respond_to?( name )
    # avoid having to use method missing in the future
    self.class.class_eval { def_delegator :@response, name }
    @response.send( name, *args, &block )
  else
    super
  end
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



10
11
12
# File 'lib/waves/response/response.rb', line 10

def request
  @request
end

Instance Method Details

#finishObject

Finish the response. This will send the response back to the client, so you shouldn’t attempt to further modify the response once this method is called. You don’t usually need to call it yourself, since it is called by the dispatcher once request processing is finished.



42
43
44
45
# File 'lib/waves/response/response.rb', line 42

def finish
  @response['Last-Modified'] = @last_modified.to_http_timestamp if @last_modified
  @response.finish
end

#last_modifiedObject



26
27
28
# File 'lib/waves/response/response.rb', line 26

def last_modified
  @last_modified
end

#last_modified=(timestamp) ⇒ Object



30
31
32
# File 'lib/waves/response/response.rb', line 30

def last_modified=( timestamp )
  @last_modified = timestamp
end

#rack_responseObject



18
# File 'lib/waves/response/response.rb', line 18

def rack_response; @response; end

#sessionObject

Returns the sessions associated with the request, allowing you to set values within it. The session will be created if necessary and saved when the response is complete.



36
# File 'lib/waves/response/response.rb', line 36

def session ; request.session ; end