Class: Hyperdrive::Endpoint
- Inherits:
-
Object
- Object
- Hyperdrive::Endpoint
- Defined in:
- lib/hyperdrive/endpoint.rb
Class Attribute Summary collapse
-
.env ⇒ Object
readonly
Returns the value of attribute env.
-
.headers ⇒ Object
Returns the value of attribute headers.
-
.media_type ⇒ Object
readonly
Returns the value of attribute media_type.
-
.params ⇒ Object
readonly
Returns the value of attribute params.
-
.request ⇒ Object
readonly
Returns the value of attribute request.
-
.resource ⇒ Object
readonly
Returns the value of attribute resource.
Class Method Summary collapse
- .body ⇒ Object
- .call(env) ⇒ Object
- .json? ⇒ Boolean
- .render(body) ⇒ Object
- .response ⇒ Object
- .status ⇒ Object
- .xml? ⇒ Boolean
Class Attribute Details
.env ⇒ Object (readonly)
Returns the value of attribute env.
21 22 23 |
# File 'lib/hyperdrive/endpoint.rb', line 21 def env @env end |
.headers ⇒ Object
Returns the value of attribute headers.
22 23 24 |
# File 'lib/hyperdrive/endpoint.rb', line 22 def headers @headers end |
.media_type ⇒ Object (readonly)
Returns the value of attribute media_type.
21 22 23 |
# File 'lib/hyperdrive/endpoint.rb', line 21 def media_type @media_type end |
.params ⇒ Object (readonly)
Returns the value of attribute params.
21 22 23 |
# File 'lib/hyperdrive/endpoint.rb', line 21 def params @params end |
.request ⇒ Object (readonly)
Returns the value of attribute request.
21 22 23 |
# File 'lib/hyperdrive/endpoint.rb', line 21 def request @request end |
.resource ⇒ Object (readonly)
Returns the value of attribute resource.
21 22 23 |
# File 'lib/hyperdrive/endpoint.rb', line 21 def resource @resource end |
Class Method Details
.body ⇒ Object
55 56 57 58 59 |
# File 'lib/hyperdrive/endpoint.rb', line 55 def self.body body = instance_eval(&resource.request_handler(env['REQUEST_METHOD'])) body = '' if env['REQUEST_METHOD'] == 'DELETE' body end |
.call(env) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/hyperdrive/endpoint.rb', line 6 def self.call(env) @env = env @request = Rack::Request.new(@env) @media_type = env['hyperdrive.media_type'] @params = env['hyperdrive.params'] @resource = env['hyperdrive.resource'] @headers = Hyperdrive::Values.default_headers.dup @headers.merge!('Allow' => resource.allowed_methods, 'Content-Type' => @media_type) response.finish end |
.json? ⇒ Boolean
25 26 27 |
# File 'lib/hyperdrive/endpoint.rb', line 25 def self.json? media_type =~ /json$/ end |
.render(body) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hyperdrive/endpoint.rb', line 33 def self.render(body) case body when Array, Hash Oj.dump(body, mode: :compat) if json? when String body else body.to_s end end |
.response ⇒ Object
61 62 63 |
# File 'lib/hyperdrive/endpoint.rb', line 61 def self.response ::Rack::Response.new(body, status, headers) end |
.status ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/hyperdrive/endpoint.rb', line 44 def self.status case env['REQUEST_METHOD'] when 'POST' 201 when 'DELETE' 204 else 200 end end |
.xml? ⇒ Boolean
29 30 31 |
# File 'lib/hyperdrive/endpoint.rb', line 29 def self.xml? media_type =~ /xml$/ end |