Class: Rack::API::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Response

Returns a new instance of Response.



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

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#to_rackObject



10
11
12
13
14
15
16
17
18
# File 'lib/rack/api/response.rb', line 10

def to_rack
  return options.to_rack if options.respond_to?(:to_rack)

  [
    options.fetch(:status, 403),
    {"Content-Type" => "text/plain"}.merge(options.fetch(:headers, {})),
    [options.fetch(:message, "Forbidden")]
  ]
end