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
2 changed files with 12 additions and 25 deletions

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