@@ -109,6 +109,7 @@ def self.include_directive_from_options(options)
109109 end
110110 end
111111
112+ # @api private
112113 def self . serialization_adapter_instance
113114 @serialization_adapter_instance ||= ActiveModelSerializers ::Adapter ::Attributes
114115 end
@@ -138,9 +139,7 @@ def success?
138139 # associations, similar to how ActiveModel::Serializers::JSON is used
139140 # in ActiveRecord::Base.
140141 #
141- # TODO: Move to here the Attributes adapter logic for
142- # +serializable_hash_for_single_resource(options)+
143- # and include <tt>ActiveModel::Serializers::JSON</tt>.
142+ # TODO: Include <tt>ActiveModel::Serializers::JSON</tt>.
144143 # So that the below is true:
145144 # @param options [nil, Hash] The same valid options passed to `serializable_hash`
146145 # (:only, :except, :methods, and :include).
@@ -164,10 +163,13 @@ def success?
164163 # serializer.as_json(include: :posts)
165164 # # Second level and higher order associations work as well:
166165 # serializer.as_json(include: { posts: { include: { comments: { only: :body } }, only: :title } })
167- def serializable_hash ( adapter_opts = nil )
168- adapter_opts ||= { }
169- adapter_opts = { include : '*' } . merge! ( adapter_opts )
170- serialize ( adapter_opts )
166+ def serializable_hash ( adapter_options = nil , options = { } , adapter_instance = self . class . serialization_adapter_instance )
167+ adapter_options ||= { }
168+ options [ :include_directive ] ||= ActiveModel ::Serializer . include_directive_from_options ( adapter_options )
169+ cached_attributes = adapter_options [ :cached_attributes ] ||= { }
170+ resource = cached_attributes ( options [ :fields ] , cached_attributes , adapter_instance )
171+ relationships = resource_relationships ( adapter_options , options , adapter_instance )
172+ resource . merge ( relationships )
171173 end
172174 alias to_hash serializable_hash
173175 alias to_h serializable_hash
@@ -199,15 +201,6 @@ def read_attribute_for_serialization(attr)
199201 end
200202 end
201203
202- # @api private
203- def serialize ( adapter_options , options = { } , adapter_instance = self . class . serialization_adapter_instance )
204- options [ :include_directive ] ||= ActiveModel ::Serializer . include_directive_from_options ( adapter_options )
205- cached_attributes = adapter_options [ :cached_attributes ] ||= { }
206- resource = cached_attributes ( options [ :fields ] , cached_attributes , adapter_instance )
207- relationships = resource_relationships ( adapter_options , options , adapter_instance )
208- resource . merge ( relationships )
209- end
210-
211204 # @api private
212205 def resource_relationships ( adapter_options , options , adapter_instance )
213206 relationships = { }
@@ -227,7 +220,7 @@ def relationship_value_for(association, adapter_options, adapter_instance)
227220 association_object = association_serializer && association_serializer . object
228221 return unless association_object
229222
230- relationship_value = association_serializer . serialize ( adapter_options , { } , adapter_instance )
223+ relationship_value = association_serializer . serializable_hash ( adapter_options , { } , adapter_instance )
231224
232225 if association . options [ :polymorphic ] && relationship_value
233226 polymorphic_type = association_object . class . name . underscore
0 commit comments