mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Merge pull request #679 from Ahalogy/serializer-options
Serializer options
This commit is contained in:
@@ -38,9 +38,9 @@ module ActiveModel
|
||||
serializer_class.new(item, scope: scope, key_format: key_format, only: @only, except: @except, polymorphic: @polymorphic, namespace: @namespace)
|
||||
end
|
||||
|
||||
def serializable_object
|
||||
def serializable_object(options={})
|
||||
@object.map do |item|
|
||||
serializer_for(item).serializable_object_with_notification
|
||||
serializer_for(item).serializable_object_with_notification(options)
|
||||
end
|
||||
end
|
||||
alias_method :serializable_array, :serializable_object
|
||||
|
||||
@@ -9,18 +9,18 @@ module ActiveModel
|
||||
def as_json(options={})
|
||||
instrument('!serialize') do
|
||||
if root = options.fetch(:root, json_key)
|
||||
hash = { root => serializable_object }
|
||||
hash = { root => serializable_object(options) }
|
||||
hash.merge!(serializable_data)
|
||||
hash
|
||||
else
|
||||
serializable_object
|
||||
serializable_object(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def serializable_object_with_notification
|
||||
def serializable_object_with_notification(options={})
|
||||
instrument('!serialize') do
|
||||
serializable_object
|
||||
serializable_object(options)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -273,7 +273,13 @@ end
|
||||
end]
|
||||
end
|
||||
|
||||
attr_writer :serialization_options
|
||||
def serialization_options
|
||||
@serialization_options || {}
|
||||
end
|
||||
|
||||
def serializable_object(options={})
|
||||
self.serialization_options = options
|
||||
return @wrap_in_array ? [] : nil if @object.nil?
|
||||
hash = attributes
|
||||
hash.merge! associations
|
||||
|
||||
Reference in New Issue
Block a user