Class: SharkOnLambda::JsonapiRenderer
- Inherits:
-
Object
- Object
- SharkOnLambda::JsonapiRenderer
- Defined in:
- lib/shark_on_lambda/jsonapi_renderer.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(object, renderer: nil) ⇒ JsonapiRenderer
constructor
A new instance of JsonapiRenderer.
- #render(options = {}) ⇒ Object
Constructor Details
#initialize(object, renderer: nil) ⇒ JsonapiRenderer
Returns a new instance of JsonapiRenderer.
7 8 9 10 11 12 |
# File 'lib/shark_on_lambda/jsonapi_renderer.rb', line 7 def initialize(object, renderer: nil) @object = object @renderer = renderer || JSONAPI::Serializable::Renderer.new @status = 200 end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/shark_on_lambda/jsonapi_renderer.rb', line 5 def object @object end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/shark_on_lambda/jsonapi_renderer.rb', line 5 def status @status end |
Instance Method Details
#render(options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/shark_on_lambda/jsonapi_renderer.rb', line 14 def render( = {}) @status = [:status] if [:status] object_to_render = transform_active_model_errors(object) unless renderable?(object_to_render, ) return handle_unrenderable_objects(object_to_render, ) end if error?(object_to_render) render_errors(object_to_render, ) else render_success(object_to_render, ) end end |