Module: ActionFigure::Formatters::Default

Includes:
ActionFigure::Formatter
Defined in:
lib/action_figure/formatters/default.rb

Overview

Implements Rails-style response helpers for use in action classes. Success responses use a { data: } envelope; errors live under an “errors” key on failure.

Constant Summary

Constants included from ActionFigure::Formatter

ActionFigure::Formatter::REQUIRED_METHODS

Instance Method Summary collapse

Methods included from ActionFigure::Formatter

#NoContent

Instance Method Details

#Accepted(resource: nil, meta: nil) ⇒ Object



22
23
24
25
26
# File 'lib/action_figure/formatters/default.rb', line 22

def Accepted(resource: nil, meta: nil)
  body = { data: resource }
  body[:meta] = meta if meta
  { json: body, status: :accepted }
end

#Conflict(errors:) ⇒ Object



40
41
42
# File 'lib/action_figure/formatters/default.rb', line 40

def Conflict(errors:)
  { json: { errors: errors }, status: :conflict }
end

#Created(resource:, meta: nil) ⇒ Object



16
17
18
19
20
# File 'lib/action_figure/formatters/default.rb', line 16

def Created(resource:, meta: nil)
  body = { data: resource }
  body[:meta] = meta if meta
  { json: body, status: :created }
end

#Forbidden(errors:) ⇒ Object



36
37
38
# File 'lib/action_figure/formatters/default.rb', line 36

def Forbidden(errors:)
  { json: { errors: errors }, status: :forbidden }
end

#NotFound(errors:) ⇒ Object



32
33
34
# File 'lib/action_figure/formatters/default.rb', line 32

def NotFound(errors:)
  { json: { errors: errors }, status: :not_found }
end

#Ok(resource:, meta: nil) ⇒ Object



10
11
12
13
14
# File 'lib/action_figure/formatters/default.rb', line 10

def Ok(resource:, meta: nil)
  body = { data: resource }
  body[:meta] = meta if meta
  { json: body, status: :ok }
end

#PaymentRequired(errors:) ⇒ Object



44
45
46
# File 'lib/action_figure/formatters/default.rb', line 44

def PaymentRequired(errors:)
  { json: { errors: errors }, status: :payment_required }
end

#UnprocessableContent(errors:) ⇒ Object



28
29
30
# File 'lib/action_figure/formatters/default.rb', line 28

def UnprocessableContent(errors:)
  { json: { errors: errors }, status: :unprocessable_content }
end