mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Merge pull request #1129 from bf4/remove_serializable_resource_serialize
Remove SerializableResource.serialize in favor of `.new`
This commit is contained in:
commit
610775a95f
@ -22,10 +22,10 @@ module ActionController
|
|||||||
def get_serializer(resource, options = {})
|
def get_serializer(resource, options = {})
|
||||||
if !use_adapter?
|
if !use_adapter?
|
||||||
warn 'ActionController::Serialization#use_adapter? has been removed. '\
|
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
|
options[:adapter] = false
|
||||||
end
|
end
|
||||||
ActiveModel::SerializableResource.serialize(resource, options) do |serializable_resource|
|
serializable_resource = ActiveModel::SerializableResource.new(resource, options)
|
||||||
if serializable_resource.serializer?
|
if serializable_resource.serializer?
|
||||||
serializable_resource.serialization_scope ||= serialization_scope
|
serializable_resource.serialization_scope ||= serialization_scope
|
||||||
serializable_resource.serialization_scope_name = _serialization_scope
|
serializable_resource.serialization_scope_name = _serialization_scope
|
||||||
@ -38,7 +38,6 @@ module ActionController
|
|||||||
resource
|
resource
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Deprecated
|
# Deprecated
|
||||||
def use_adapter?
|
def use_adapter?
|
||||||
|
|||||||
@ -3,6 +3,8 @@ module ActiveModel
|
|||||||
class SerializableResource
|
class SerializableResource
|
||||||
ADAPTER_OPTION_KEYS = Set.new([:include, :fields, :adapter])
|
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 = {})
|
def initialize(resource, options = {})
|
||||||
@resource = resource
|
@resource = resource
|
||||||
@adapter_opts, @serializer_opts =
|
@adapter_opts, @serializer_opts =
|
||||||
@ -11,20 +13,6 @@ module ActiveModel
|
|||||||
|
|
||||||
delegate :serializable_hash, :as_json, :to_json, to: :adapter
|
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)
|
def serialization_scope=(scope)
|
||||||
serializer_opts[:scope] = scope
|
serializer_opts[:scope] = scope
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user