Class: Lepus::Web::RespondWith
- Inherits:
-
Object
- Object
- Lepus::Web::RespondWith
- Defined in:
- lib/lepus/web/respond_with.rb
Constant Summary collapse
- TEMPLATES =
{ not_found: { status: 404, body: {error: "not_found"} }, health: { status: 200, body: {status: "ok"} }, ok: { status: 200 } }.freeze
Class Method Summary collapse
Class Method Details
.json(template: nil, body: nil, status: nil, headers: {}) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/lepus/web/respond_with.rb', line 20 def self.json(template: nil, body: nil, status: nil, headers: {}) headers["content-type"] = "application/json" body ||= TEMPLATES.dig(template, :body) status ||= TEMPLATES.dig(template, :status) || 200 [status, headers, [MultiJson.dump(body)]] end |