active_model_serializers/lib/action_controller/serialization.rb
Gary Gordon d5bae0c2f0 Include 'linked' member for json-api collections
The options passed to the render are partitioned into adapter options
and serializer options. 'include' and 'root' are sent to the adapter,
not sure what options would go directly to serializer, but leaving this
in until I understand that better.
2014-11-03 17:13:55 -05:00

29 lines
860 B
Ruby

require 'active_support/core_ext/class/attribute'
module ActionController
module Serialization
extend ActiveSupport::Concern
include ActionController::Renderers
ADAPTER_OPTION_KEYS = [:include, :root]
[:_render_option_json, :_render_with_renderer_json].each do |renderer_method|
define_method renderer_method do |resource, options|
serializer = ActiveModel::Serializer.serializer_for(resource)
if serializer
adapter_opts, serializer_opts =
options.partition { |k, _| ADAPTER_OPTION_KEYS.include? k }
# omg hax
object = serializer.new(resource, Hash[serializer_opts])
adapter = ActiveModel::Serializer.adapter.new(object, Hash[adapter_opts])
super(adapter, options)
else
super(resource, options)
end
end
end
end
end