mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Move DefaultSerializer from array_serializer.rb to serializer.rb
This commit is contained in:
parent
8f6218c587
commit
c4fcf96eb4
@ -1,15 +1,6 @@
|
||||
require "active_support/core_ext/class/attribute"
|
||||
|
||||
module ActiveModel
|
||||
class DefaultSerializer
|
||||
attr_reader :object
|
||||
def initialize(object)
|
||||
@object = object
|
||||
end
|
||||
def serializable_hash
|
||||
@object.as_json
|
||||
end
|
||||
end
|
||||
# Active Model Array Serializer
|
||||
#
|
||||
# It serializes an Array, checking if each element that implements
|
||||
|
||||
@ -387,4 +387,20 @@ module ActiveModel
|
||||
ActiveSupport::Notifications.instrument(event_name, payload, &block)
|
||||
end
|
||||
end
|
||||
|
||||
# DefaultSerializer
|
||||
#
|
||||
# Provides a constant interface for all items, particularly
|
||||
# for ArraySerializer.
|
||||
class DefaultSerializer
|
||||
attr_reader :object, :options
|
||||
|
||||
def initialize(object, options={})
|
||||
@object, @options = object, options
|
||||
end
|
||||
|
||||
def serializable_hash
|
||||
@object.as_json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -68,7 +68,7 @@ class MyUserSerializer < ActiveModel::Serializer
|
||||
end
|
||||
end
|
||||
|
||||
class CommentSerializer < ActiveModel::Serializer
|
||||
class CommentSerializer
|
||||
def initialize(comment, options={})
|
||||
@object = comment
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user