lib/jsonapi/response_document.rb in jsonapi-resources-0.4.2 vs lib/jsonapi/response_document.rb in jsonapi-resources-0.4.3
- old
+ new
@@ -34,11 +34,12 @@
@options.fetch(:primary_resource_klass),
include_directives: @options[:include_directives],
fields: @options[:fields],
base_url: @options.fetch(:base_url, ''),
key_formatter: @key_formatter,
- route_formatter: @options.fetch(:route_formatter, JSONAPI.configuration.route_formatter)
+ route_formatter: @options.fetch(:route_formatter, JSONAPI.configuration.route_formatter),
+ scope_id: @options[:scope_id]
)
end
# Rolls up the top level meta data from the base_meta, the set of operations,
# and the result of each operation. The keys are then formatted.
@@ -48,11 +49,11 @@
meta.merge!(@operation_results.meta)
@operation_results.results.each do |result|
meta.merge!(result.meta)
- if JSONAPI.configuration.top_level_meta_include_record_count
+ if JSONAPI.configuration.top_level_meta_include_record_count && result.respond_to?(:record_count)
meta[JSONAPI.configuration.top_level_meta_record_count_key] = result.record_count
end
end
meta.deep_transform_keys { |key| @key_formatter.format(key) }
@@ -88,11 +89,11 @@
links.deep_transform_keys { |key| @key_formatter.format(key) }
end
def results_to_hash
if @operation_results.has_errors?
- {errors: @operation_results.all_errors}
+ { errors: @operation_results.all_errors }
else
if @operation_results.results.length == 1
result = @operation_results.results[0]
case result
@@ -121,6 +122,6 @@
serializer.serialize_to_hash(resources)
end
end
end
end
-end
\ No newline at end of file
+end