mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Rename associated_object to object
This commit is contained in:
parent
85bf3d2f3d
commit
f9e189e9d7
@ -25,7 +25,7 @@ module ActiveModel
|
|||||||
options[:name] || @name
|
options[:name] || @name
|
||||||
end
|
end
|
||||||
|
|
||||||
def associated_object
|
def object
|
||||||
options[:value]
|
options[:value]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def embeddable?
|
def embeddable?
|
||||||
!associated_object.nil?
|
!object.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def embed_key
|
def embed_key
|
||||||
@ -84,19 +84,19 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def serialize
|
def serialize
|
||||||
associated_object.map do |item|
|
object.map do |item|
|
||||||
find_serializable(item).serializable_hash
|
find_serializable(item).serializable_hash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def serializables
|
def serializables
|
||||||
associated_object.map do |item|
|
object.map do |item|
|
||||||
find_serializable(item)
|
find_serializable(item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def serialize_ids
|
def serialize_ids
|
||||||
associated_object.map do |item|
|
object.map do |item|
|
||||||
item.read_attribute_for_serialization(embed_key)
|
item.read_attribute_for_serialization(embed_key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -104,7 +104,7 @@ module ActiveModel
|
|||||||
|
|
||||||
class HasOne < Base #:nodoc:
|
class HasOne < Base #:nodoc:
|
||||||
def embeddable?
|
def embeddable?
|
||||||
if polymorphic? && associated_object.nil?
|
if polymorphic? && object.nil?
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
true
|
true
|
||||||
@ -119,7 +119,7 @@ module ActiveModel
|
|||||||
if root = options[:root]
|
if root = options[:root]
|
||||||
root
|
root
|
||||||
elsif polymorphic?
|
elsif polymorphic?
|
||||||
associated_object.class.to_s.pluralize.demodulize.underscore.to_sym
|
object.class.to_s.pluralize.demodulize.underscore.to_sym
|
||||||
else
|
else
|
||||||
@name.to_s.pluralize.to_sym
|
@name.to_s.pluralize.to_sym
|
||||||
end
|
end
|
||||||
@ -140,12 +140,10 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def polymorphic_key
|
def polymorphic_key
|
||||||
associated_object.class.to_s.demodulize.underscore.to_sym
|
object.class.to_s.demodulize.underscore.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
def serialize
|
def serialize
|
||||||
object = associated_object
|
|
||||||
|
|
||||||
if object
|
if object
|
||||||
if polymorphic?
|
if polymorphic?
|
||||||
{
|
{
|
||||||
@ -159,14 +157,11 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def serializables
|
def serializables
|
||||||
object = associated_object
|
|
||||||
value = object && find_serializable(object)
|
value = object && find_serializable(object)
|
||||||
value ? [value] : []
|
value ? [value] : []
|
||||||
end
|
end
|
||||||
|
|
||||||
def serialize_ids
|
def serialize_ids
|
||||||
object = associated_object
|
|
||||||
|
|
||||||
if object
|
if object
|
||||||
id = object.read_attribute_for_serialization(embed_key)
|
id = object.read_attribute_for_serialization(embed_key)
|
||||||
if polymorphic?
|
if polymorphic?
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user