Class: Resourceful::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/plugins/make_resourceful/lib/resourceful/response.rb

Overview

This is the class of the object passed to the Builder#response_for method. It shouldn’t be used by users.

The Response collects format procs and returns them with the format method, in the order they were given. For example:

response.html { redirect_to '/' }
response.xml { render :xml => current_object.to_xml }
response.js
response.formats #=> [[:html, #<Proc>], [:xml, #<Proc>], [:js, #<Proc>]]

Note that the :js response is the empty proc - the same as proc {}.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new Response with no format data.



24
25
26
# File 'lib/vendor/plugins/make_resourceful/lib/resourceful/response.rb', line 24

def initialize
  @formats = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, &block) ⇒ Object

Used to dispatch the individual format methods.



29
30
31
# File 'lib/vendor/plugins/make_resourceful/lib/resourceful/response.rb', line 29

def method_missing(name, &block)
  @formats.push([name, block || proc {}]) unless @formats.any? {|n,b| n == name}
end

Instance Attribute Details

#formatsObject (readonly)

Returns a list of pairs of formats and procs representing the formats passed to the response object. See class description.



21
22
23
# File 'lib/vendor/plugins/make_resourceful/lib/resourceful/response.rb', line 21

def formats
  @formats
end