Class: Hyperdrive::Response
- Inherits:
-
Object
- Object
- Hyperdrive::Response
- Defined in:
- lib/hyperdrive/response.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#http_request_method ⇒ Object
readonly
Returns the value of attribute http_request_method.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
-
#initialize(env, resource) ⇒ Response
constructor
A new instance of Response.
- #response ⇒ Object
Constructor Details
#initialize(env, resource) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/hyperdrive/response.rb', line 7 def initialize(env, resource) @resource = resource @env = env @http_request_method = env['REQUEST_METHOD'] unless request_method_supported? raise Errors::NotImplemented.new(http_request_method) end unless resource.request_method_allowed?(http_request_method) raise Errors::MethodNotAllowed.new(http_request_method) end @headers = default_headers end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
5 6 7 |
# File 'lib/hyperdrive/response.rb', line 5 def env @env end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/hyperdrive/response.rb', line 5 def headers @headers end |
#http_request_method ⇒ Object (readonly)
Returns the value of attribute http_request_method.
5 6 7 |
# File 'lib/hyperdrive/response.rb', line 5 def http_request_method @http_request_method end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
5 6 7 |
# File 'lib/hyperdrive/response.rb', line 5 def resource @resource end |
Instance Method Details
#response ⇒ Object
23 24 25 26 27 |
# File 'lib/hyperdrive/response.rb', line 23 def response @headers.merge({ 'Content-Type' => 'text/plain' }) status = (http_request_method == 'POST') ? 201 : 200 ::Rack::Response.new(resource.request_handler(http_request_method).call(env), status, headers).finish end |