Module: JSONAPI::Utils::Response::Formatters

Included in:
JSONAPI::Utils::Response
Defined in:
lib/jsonapi/utils/response/formatters.rb

Instance Method Summary collapse

Instance Method Details

#jsonapi_format(records, options = {}) ⇒ Object Also known as: jsonapi_serialize



5
6
7
8
9
10
11
12
# File 'lib/jsonapi/utils/response/formatters.rb', line 5

def jsonapi_format(records, options = {})
  if records.is_a?(Hash)
    hash    = records.with_indifferent_access
    records = hash_to_active_record(hash[:data], options[:model])
  end
  fix_request_options(params, records)
  build_response_document(records, options).contents
end

#jsonapi_format_errors(data) ⇒ Object



16
17
18
19
20
# File 'lib/jsonapi/utils/response/formatters.rb', line 16

def jsonapi_format_errors(data)
  data = JSONAPI::Utils::Exceptions::ActiveRecord.new(data, @request.resource_klass, context) if active_record_obj?(data)
  errors = data.respond_to?(:errors) ? data.errors : data
  JSONAPI::Utils::Support::Error.sanitize(errors).uniq
end