Merge pull request #1129 from bf4/remove_serializable_resource_serialize

Remove SerializableResource.serialize in favor of `.new`
This commit is contained in:
L. Preston Sego III 2015-09-15 17:32:44 -04:00
commit 610775a95f
2 changed files with 12 additions and 25 deletions

View File

@ -22,10 +22,10 @@ module ActionController
def get_serializer(resource, options = {})
if !use_adapter?
warn 'ActionController::Serialization#use_adapter? has been removed. '\
"Please pass 'adapter: false' or see ActiveSupport::SerializableResource#serialize"
"Please pass 'adapter: false' or see ActiveSupport::SerializableResource.new"
options[:adapter] = false
end
ActiveModel::SerializableResource.serialize(resource, options) do |serializable_resource|
serializable_resource = ActiveModel::SerializableResource.new(resource, options)
if serializable_resource.serializer?
serializable_resource.serialization_scope ||= serialization_scope
serializable_resource.serialization_scope_name = _serialization_scope
@ -38,7 +38,6 @@ module ActionController
resource
end
end
end
# Deprecated
def use_adapter?

View File

@ -3,6 +3,8 @@ module ActiveModel
class SerializableResource
ADAPTER_OPTION_KEYS = Set.new([:include, :fields, :adapter])
# Primary interface to composing a resource with a serializer and adapter.
# @return the serializable_resource, ready for #as_json/#to_json/#serializable_hash.
def initialize(resource, options = {})
@resource = resource
@adapter_opts, @serializer_opts =
@ -11,20 +13,6 @@ module ActiveModel
delegate :serializable_hash, :as_json, :to_json, to: :adapter
# Primary interface to building a serializer (with adapter)
# If no block is given,
# returns the serializable_resource, ready for #as_json/#to_json/#serializable_hash.
# Otherwise, yields the serializable_resource and
# returns the contents of the block
def self.serialize(resource, options = {})
serializable_resource = SerializableResource.new(resource, options)
if block_given?
yield serializable_resource
else
serializable_resource
end
end
def serialization_scope=(scope)
serializer_opts[:scope] = scope
end