mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 23:06:50 +00:00
Use blocks instead of eval to define methods
This commit is contained in:
parent
3f75c14267
commit
e8f2ecebfb
@ -318,7 +318,9 @@ module ActiveModel
|
|||||||
self._attributes = _attributes.merge(attr => options[:key] || attr.to_s.gsub(/\?$/, '').to_sym)
|
self._attributes = _attributes.merge(attr => options[:key] || attr.to_s.gsub(/\?$/, '').to_sym)
|
||||||
|
|
||||||
unless method_defined?(attr)
|
unless method_defined?(attr)
|
||||||
class_eval "def #{attr}() object.read_attribute_for_serialization(:#{attr}) end", __FILE__, __LINE__
|
define_method attr do
|
||||||
|
object.read_attribute_for_serialization(attr.to_sym)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -328,7 +330,9 @@ module ActiveModel
|
|||||||
|
|
||||||
attrs.each do |attr|
|
attrs.each do |attr|
|
||||||
unless method_defined?(attr)
|
unless method_defined?(attr)
|
||||||
class_eval "def #{attr}() object.#{attr} end", __FILE__, __LINE__
|
define_method attr do
|
||||||
|
object.send attr
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self._associations[attr] = klass.refine(attr, options)
|
self._associations[attr] = klass.refine(attr, options)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user