Module: ActionFigure::Formatters::Wrapped
Overview
Implements uniform envelope response helpers for use in action classes. Every response uses the same { data:, errors:, status: } shape.
Constant Summary
ActionFigure::Formatter::REQUIRED_METHODS
Instance Method Summary
collapse
#NoContent
Instance Method Details
#Accepted(resource: nil, meta: nil) ⇒ Object
22
23
24
25
26
|
# File 'lib/action_figure/formatters/wrapped.rb', line 22
def Accepted(resource: nil, meta: nil)
body = { data: resource, errors: nil, status: "success" }
body[:meta] = meta if meta
{ json: body, status: :accepted }
end
|
#Conflict(errors:) ⇒ Object
40
41
42
|
# File 'lib/action_figure/formatters/wrapped.rb', line 40
def Conflict(errors:)
{ json: { data: nil, errors: errors, status: "error" }, status: :conflict }
end
|
#Created(resource:, meta: nil) ⇒ Object
16
17
18
19
20
|
# File 'lib/action_figure/formatters/wrapped.rb', line 16
def Created(resource:, meta: nil)
body = { data: resource, errors: nil, status: "success" }
body[:meta] = meta if meta
{ json: body, status: :created }
end
|
#Forbidden(errors:) ⇒ Object
36
37
38
|
# File 'lib/action_figure/formatters/wrapped.rb', line 36
def Forbidden(errors:)
{ json: { data: nil, errors: errors, status: "error" }, status: :forbidden }
end
|
#NotFound(errors:) ⇒ Object
32
33
34
|
# File 'lib/action_figure/formatters/wrapped.rb', line 32
def NotFound(errors:)
{ json: { data: nil, errors: errors, status: "error" }, status: :not_found }
end
|
#Ok(resource:, meta: nil) ⇒ Object
10
11
12
13
14
|
# File 'lib/action_figure/formatters/wrapped.rb', line 10
def Ok(resource:, meta: nil)
body = { data: resource, errors: nil, status: "success" }
body[:meta] = meta if meta
{ json: body, status: :ok }
end
|
#PaymentRequired(errors:) ⇒ Object
44
45
46
|
# File 'lib/action_figure/formatters/wrapped.rb', line 44
def PaymentRequired(errors:)
{ json: { data: nil, errors: errors, status: "error" }, status: :payment_required }
end
|
#UnprocessableContent(errors:) ⇒ Object
28
29
30
|
# File 'lib/action_figure/formatters/wrapped.rb', line 28
def UnprocessableContent(errors:)
{ json: { data: nil, errors: errors, status: "error" }, status: :unprocessable_content }
end
|