mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Move key method to the base class
This commit is contained in:
parent
ecbb8bf6a6
commit
296970415a
@ -17,9 +17,20 @@ module ActiveModel
|
|||||||
attr_reader :root, :name, :embed_in_root
|
attr_reader :root, :name, :embed_in_root
|
||||||
alias :embed_in_root? :embed_in_root
|
alias :embed_in_root? :embed_in_root
|
||||||
|
|
||||||
|
def key
|
||||||
|
if key = options[:key]
|
||||||
|
key
|
||||||
|
elsif use_id_key?
|
||||||
|
id_key
|
||||||
|
else
|
||||||
|
@name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def embed_ids?
|
def embed_ids?
|
||||||
embed == :id || embed == :ids
|
embed == :id || embed == :ids
|
||||||
end
|
end
|
||||||
|
alias use_id_key? embed_ids?
|
||||||
|
|
||||||
def embed_objects?
|
def embed_objects?
|
||||||
embed == :object || embed == :objects
|
embed == :object || embed == :objects
|
||||||
@ -52,16 +63,6 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
class HasMany < Base #:nodoc:
|
class HasMany < Base #:nodoc:
|
||||||
def key
|
|
||||||
if key = options[:key]
|
|
||||||
key
|
|
||||||
elsif embed_ids?
|
|
||||||
id_key
|
|
||||||
else
|
|
||||||
@name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def root
|
def root
|
||||||
options[:root] || name
|
options[:root] || name
|
||||||
end
|
end
|
||||||
@ -90,16 +91,6 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
class HasOne < Base #:nodoc:
|
class HasOne < Base #:nodoc:
|
||||||
def key
|
|
||||||
if key = options[:key]
|
|
||||||
key
|
|
||||||
elsif embed_ids? && !polymorphic?
|
|
||||||
id_key
|
|
||||||
else
|
|
||||||
@name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def root
|
def root
|
||||||
if root = options[:root]
|
if root = options[:root]
|
||||||
root
|
root
|
||||||
@ -156,6 +147,10 @@ module ActiveModel
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def use_id_key?
|
||||||
|
embed_ids? && !polymorphic?
|
||||||
|
end
|
||||||
|
|
||||||
def polymorphic?
|
def polymorphic?
|
||||||
options[:polymorphic]
|
options[:polymorphic]
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user