mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Cleanup
This commit is contained in:
parent
d42634a1d2
commit
c32558248a
@ -71,7 +71,6 @@ module ActiveModel
|
|||||||
class Serializer
|
class Serializer
|
||||||
module Associations #:nodoc:
|
module Associations #:nodoc:
|
||||||
class Config #:nodoc:
|
class Config #:nodoc:
|
||||||
class_attribute :association_name
|
|
||||||
class_attribute :options
|
class_attribute :options
|
||||||
|
|
||||||
def self.refine(name, class_options)
|
def self.refine(name, class_options)
|
||||||
@ -86,21 +85,14 @@ module ActiveModel
|
|||||||
alias inspect to_s
|
alias inspect to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
self.association_name = name
|
|
||||||
self.options = class_options
|
self.options = class_options
|
||||||
|
|
||||||
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
||||||
def initialize(options={})
|
|
||||||
super(self.class.association_name, options)
|
|
||||||
end
|
|
||||||
RUBY
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.options = {}
|
self.options = {}
|
||||||
|
|
||||||
def initialize(name=nil, options={})
|
def initialize(name, options={})
|
||||||
@name = name || self.class.association_name
|
@name = name
|
||||||
@options = options
|
@options = options
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -287,7 +279,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
associations = _associations.inject({}) do |hash, (attr,association_class)|
|
associations = _associations.inject({}) do |hash, (attr,association_class)|
|
||||||
association = association_class.new
|
association = association_class.new(attr)
|
||||||
|
|
||||||
model_association = klass.reflect_on_association(association.name)
|
model_association = klass.reflect_on_association(association.name)
|
||||||
hash.merge association.key => { model_association.macro => model_association.name }
|
hash.merge association.key => { model_association.macro => model_association.name }
|
||||||
@ -370,14 +362,16 @@ module ActiveModel
|
|||||||
serializer = options[:serializer]
|
serializer = options[:serializer]
|
||||||
scope = options[:scope] || self.scope
|
scope = options[:scope] || self.scope
|
||||||
|
|
||||||
association_class = _associations[name]
|
association_class =
|
||||||
association = association_class.new(options) if association_class
|
if klass = _associations[name]
|
||||||
|
klass
|
||||||
|
elsif value.respond_to?(:to_ary)
|
||||||
|
Associations::HasMany
|
||||||
|
else
|
||||||
|
Associations::HasOne
|
||||||
|
end
|
||||||
|
|
||||||
association ||= if value.respond_to?(:to_ary)
|
association = association_class.new(name, options)
|
||||||
Associations::HasMany.new(name, options)
|
|
||||||
else
|
|
||||||
Associations::HasOne.new(name, options)
|
|
||||||
end
|
|
||||||
|
|
||||||
if embed == :ids
|
if embed == :ids
|
||||||
node[association.key] = association.serialize_ids(self, scope)
|
node[association.key] = association.serialize_ids(self, scope)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user