mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Make more class attributes inheritable
This commit is contained in:
parent
236fb6d7fb
commit
0f50847c7d
@ -27,12 +27,12 @@ module ActiveModel
|
|||||||
)
|
)
|
||||||
/x
|
/x
|
||||||
|
|
||||||
class << self
|
|
||||||
attr_accessor :_attributes
|
|
||||||
attr_accessor :_attributes_keys
|
|
||||||
end
|
|
||||||
|
|
||||||
with_options instance_writer: false, instance_reader: false do |serializer|
|
with_options instance_writer: false, instance_reader: false do |serializer|
|
||||||
|
class_attribute :_type, instance_reader: true
|
||||||
|
class_attribute :_attributes
|
||||||
|
self._attributes ||= []
|
||||||
|
class_attribute :_attributes_keys
|
||||||
|
self._attributes_keys ||= {}
|
||||||
serializer.class_attribute :_cache
|
serializer.class_attribute :_cache
|
||||||
serializer.class_attribute :_fragmented
|
serializer.class_attribute :_fragmented
|
||||||
serializer.class_attribute :_cache_key
|
serializer.class_attribute :_cache_key
|
||||||
@ -43,8 +43,8 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.inherited(base)
|
def self.inherited(base)
|
||||||
base._attributes = _attributes.try(:dup) || []
|
base._attributes = _attributes.dup
|
||||||
base._attributes_keys = _attributes_keys.try(:dup) || {}
|
base._attributes_keys = _attributes_keys.dup
|
||||||
base._cache_digest = digest_caller_file(caller.first)
|
base._cache_digest = digest_caller_file(caller.first)
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
@ -125,7 +125,6 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :object, :root, :scope
|
attr_accessor :object, :root, :scope
|
||||||
class_attribute :_type, instance_writer: false
|
|
||||||
|
|
||||||
def initialize(object, options = {})
|
def initialize(object, options = {})
|
||||||
self.object = object
|
self.object = object
|
||||||
@ -149,10 +148,10 @@ module ActiveModel
|
|||||||
attributes = self.class._attributes.dup
|
attributes = self.class._attributes.dup
|
||||||
|
|
||||||
attributes.each_with_object({}) do |name, hash|
|
attributes.each_with_object({}) do |name, hash|
|
||||||
unless self.class._fragmented
|
if self.class._fragmented
|
||||||
hash[name] = send(name)
|
|
||||||
else
|
|
||||||
hash[name] = self.class._fragmented.public_send(name)
|
hash[name] = self.class._fragmented.public_send(name)
|
||||||
|
else
|
||||||
|
hash[name] = send(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user