Class: JSONAPI::ResponseDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi/response_document.rb

Instance Method Summary collapse

Constructor Details

#initialize(operation_results, options = {}) ⇒ ResponseDocument


3
4
5
6
7
8
# File 'lib/jsonapi/response_document.rb', line 3

def initialize(operation_results, options = {})
  @operation_results = operation_results
  @options = options

  @key_formatter = @options.fetch(:key_formatter, JSONAPI.configuration.key_formatter)
end

Instance Method Details

#contentsObject


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/jsonapi/response_document.rb', line 10

def contents
  hash = results_to_hash

  meta = top_level_meta
  hash.merge!(meta: meta) unless meta.empty?

  links = top_level_links
  hash.merge!(links: links) unless links.empty?

  hash
end

#statusObject


22
23
24
25
26
27
28
# File 'lib/jsonapi/response_document.rb', line 22

def status
  if @operation_results.has_errors?
    @operation_results.all_errors[0].status
  else
    @operation_results.results[0].code
  end
end