mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Merge pull request #1129 from bf4/remove_serializable_resource_serialize
Remove SerializableResource.serialize in favor of `.new`
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user