lib/shamu/rails/json_api.rb in shamu-0.0.5 vs lib/shamu/rails/json_api.rb in shamu-0.0.7
- old
+ new
@@ -32,11 +32,11 @@
# @return [JsonApi::Response] the presented JSON response.
def json_resource( resource, presenter = nil, **context, &block )
response = build_json_response( context )
response.resource resource, presenter
yield response if block_given?
- response
+ response.to_json
end
# Builds a well-formed JSON API response for a collection of resources.
#
# @param [Enumerable<Object>] resources to present as a JSON array.
@@ -51,11 +51,11 @@
def json_collection( resources, presenter = nil, pagination: :auto, **context, &block )
response = build_json_response( context )
response.collection resources, presenter
json_paginate_resources response, resources, pagination
yield response if block_given?
- response
+ response.to_json
end
# Add page-based pagination links for the resources to the builder.
#
# @param [#current_page,#next_page,#previous_page] resources a collection that responds to `#current_page`
@@ -87,11 +87,11 @@
response.error error do |builder|
builder.http_status json_http_status_code_from_error( error )
yield builder if block_given?
end
- response
+ response.to_json
end
# Write all the validation errors from a record to the response.
#
# @param (see Shamu::JsonApi::Response#validation_errors)
@@ -100,10 +100,10 @@
# @return [JsonApi::Response] the presented JSON response.
def json_validation_errors( errors, **context, &block )
response = build_json_response( context )
response.validation_errors errors, &block
- response
+ response.to_json
end
JSON_CONTEXT_KEYWORDS = [ :fields, :namespaces, :presenters ].freeze
# @!visibility public
\ No newline at end of file