Class: MiniApi::RelationResponder

Inherits:
Object
  • Object
show all
Includes:
Serialization
Defined in:
lib/mini_api/relation_responder.rb

Instance Method Summary collapse

Methods included from Serialization

#get_error_serializer, #serialiable_body

Constructor Details

#initialize(controller, resource, options = {}) ⇒ RelationResponder

Returns a new instance of RelationResponder.



11
12
13
14
15
# File 'lib/mini_api/relation_responder.rb', line 11

def initialize(controller, resource, options = {})
  @controller = controller
  @resource = resource
  @options = options
end

Instance Method Details

#respondObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mini_api/relation_responder.rb', line 17

def respond
  meta, collection = extract_meta_and_collection

  meta = CaseTransform.response_keys(meta)

  collection = transform_case(collection.as_json)

  @controller.render json: {
    success: @options[:success] || true,
    data: collection,
    meta: meta
  }, status: @options[:status]
end