Class: RespondWith::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/respond_with/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Response

Returns a new instance of Response.



8
9
10
11
12
13
14
# File 'lib/respond_with/response.rb', line 8

def initialize(opts={})
  @app     = opts[:app]
  @params  = opts[:params]
  @object  = opts[:object]
  @request = opts[:request]
  @options = opts[:options]
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



3
4
5
# File 'lib/respond_with/response.rb', line 3

def app
  @app
end

#objectObject (readonly)

Returns the value of attribute object.



5
6
7
# File 'lib/respond_with/response.rb', line 5

def object
  @object
end

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/respond_with/response.rb', line 4

def params
  @params
end

#requestObject (readonly)

Returns the value of attribute request.



6
7
8
# File 'lib/respond_with/response.rb', line 6

def request
  @request
end

Instance Method Details

#renderObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/respond_with/response.rb', line 16

def render
  response_type = Negotiator.pick(request_types.join(", "), available_responses)

  if response_type.nil?
    @app.halt 406
  else
    @app.status(@options[:status]) if @options[:status]
    @app.content_type(response_type)
    @object.to(response_type)
  end
end