Class: SharkOnLambda::JsonapiRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/shark_on_lambda/jsonapi_renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#objectObject (readonly)

Returns the value of attribute object.



5
6
7
# File 'lib/shark_on_lambda/jsonapi_renderer.rb', line 5

def object
  @object
end

#statusObject (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(options = {})
  @status = options[:status] if options[:status]
  object_to_render = transform_active_model_errors(object)

  unless renderable?(object_to_render, options)
    return handle_unrenderable_objects(object_to_render, options)
  end

  if error?(object_to_render)
    render_errors(object_to_render, options)
  else
    render_success(object_to_render, options)
  end
end