Skip to content

Commit 30a2012

Browse files
committed
Add hook for default jsonapi object.
1 parent 9bc6bfb commit 30a2012

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

lib/jsonapi/rails/action_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def deserializable_resource(key, options = {}, &block)
4040
end
4141
end
4242

43+
def jsonapi_object
44+
nil
45+
end
46+
4347
def jsonapi_expose
4448
{
4549
url_helpers: ::Rails.application.routes.url_helpers

lib/jsonapi/rails/railtie.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ class Railtie < ::Rails::Railtie
3030
::ActionController::Renderers.add(:jsonapi) do |resources, options|
3131
self.content_type ||= Mime[:jsonapi]
3232

33+
options = options.dup
3334
# Renderer proc is evaluated in the controller context.
3435
if (pagination_links = jsonapi_pagination(resources))
3536
(options[:links] ||= {}).merge!(pagination_links)
3637
end
37-
options[:expose] = jsonapi_expose.merge!(options[:expose] || {})
38+
options[:expose] = jsonapi_expose.merge!(options[:expose] || {})
39+
options[:jsonapi] = options[:jsonapi_object] || jsonapi_object
3840

3941
RENDERERS[:jsonapi].render(resources, options).to_json
4042
end

lib/jsonapi/rails/renderer.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ def initialize(renderer = JSONAPI::Serializable::SuccessRenderer.new)
1010
end
1111

1212
def render(resources, options)
13-
opts = options.dup
14-
opts[:jsonapi] = opts.delete(:jsonapi_object)
15-
1613
@renderer.render(resources, opts)
1714
end
1815
end

0 commit comments

Comments
 (0)