mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Revert "Merge pull request #422 from marclove/reduce-serializer-code-complexity"
This reverts commit449849516b, reversing changes made toe103569c22. Conflicts: lib/active_model/serializer.rb
This commit is contained in:
parent
303ac21428
commit
1eb09476ef
@ -69,7 +69,12 @@ end
|
|||||||
|
|
||||||
def attributes(*attrs)
|
def attributes(*attrs)
|
||||||
@_attributes.concat attrs
|
@_attributes.concat attrs
|
||||||
attrs.each{|attr| define_attribute_accessor(attr)}
|
|
||||||
|
attrs.each do |attr|
|
||||||
|
define_method attr do
|
||||||
|
object.read_attribute_for_serialization attr
|
||||||
|
end unless method_defined?(attr)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_one(*attrs)
|
def has_one(*attrs)
|
||||||
@ -86,27 +91,13 @@ end
|
|||||||
options = attrs.extract_options!
|
options = attrs.extract_options!
|
||||||
|
|
||||||
attrs.each do |attr|
|
attrs.each do |attr|
|
||||||
define_association_accessor(attr)
|
define_method attr do
|
||||||
|
object.send attr
|
||||||
|
end unless method_defined?(attr)
|
||||||
|
|
||||||
@_associations[attr] = klass.new(attr, options)
|
@_associations[attr] = klass.new(attr, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def define_accessor_unless_defined(attr, &block)
|
|
||||||
return if method_defined?(attr)
|
|
||||||
define_method(attr, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
def define_attribute_accessor(attr)
|
|
||||||
define_accessor_unless_defined(attr) do
|
|
||||||
object.read_attribute_for_serialization(attr)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def define_association_accessor(attr)
|
|
||||||
define_accessor_unless_defined(attr) do
|
|
||||||
object.__send__(attr)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(object, options={})
|
def initialize(object, options={})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user