mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +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
|
||||
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?
|
||||
embed == :id || embed == :ids
|
||||
end
|
||||
alias use_id_key? embed_ids?
|
||||
|
||||
def embed_objects?
|
||||
embed == :object || embed == :objects
|
||||
@ -52,16 +63,6 @@ module ActiveModel
|
||||
end
|
||||
|
||||
class HasMany < Base #:nodoc:
|
||||
def key
|
||||
if key = options[:key]
|
||||
key
|
||||
elsif embed_ids?
|
||||
id_key
|
||||
else
|
||||
@name
|
||||
end
|
||||
end
|
||||
|
||||
def root
|
||||
options[:root] || name
|
||||
end
|
||||
@ -90,16 +91,6 @@ module ActiveModel
|
||||
end
|
||||
|
||||
class HasOne < Base #:nodoc:
|
||||
def key
|
||||
if key = options[:key]
|
||||
key
|
||||
elsif embed_ids? && !polymorphic?
|
||||
id_key
|
||||
else
|
||||
@name
|
||||
end
|
||||
end
|
||||
|
||||
def root
|
||||
if root = options[:root]
|
||||
root
|
||||
@ -156,6 +147,10 @@ module ActiveModel
|
||||
|
||||
private
|
||||
|
||||
def use_id_key?
|
||||
embed_ids? && !polymorphic?
|
||||
end
|
||||
|
||||
def polymorphic?
|
||||
options[:polymorphic]
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user