mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Merge pull request #215 from mulder/feature/reloading
Serializer Reloading via ActiveSupport::DescendantsTracker
This commit is contained in:
commit
1c28577280
@ -1,4 +1,6 @@
|
||||
require "active_support/core_ext/class/attribute"
|
||||
require 'active_support/dependencies'
|
||||
require 'active_support/descendants_tracker'
|
||||
|
||||
module ActiveModel
|
||||
# Active Model Array Serializer
|
||||
@ -11,6 +13,8 @@ module ActiveModel
|
||||
# ActiveModel::ArraySerializer.root = false
|
||||
#
|
||||
class ArraySerializer
|
||||
extend ActiveSupport::DescendantsTracker
|
||||
|
||||
attr_reader :object, :options
|
||||
|
||||
class_attribute :root
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
require "active_support/core_ext/class/attribute"
|
||||
require "active_support/core_ext/module/anonymous"
|
||||
require 'active_support/dependencies'
|
||||
require 'active_support/descendants_tracker'
|
||||
|
||||
module ActiveModel
|
||||
# Active Model Serializer
|
||||
@ -36,6 +38,8 @@ module ActiveModel
|
||||
# end
|
||||
#
|
||||
class Serializer
|
||||
extend ActiveSupport::DescendantsTracker
|
||||
|
||||
INCLUDE_METHODS = {}
|
||||
INSTRUMENT = { :serialize => :"serialize.serializer", :associations => :"associations.serializer" }
|
||||
|
||||
|
||||
@ -33,14 +33,12 @@ module ActiveModel::SerializerSupport
|
||||
module ClassMethods #:nodoc:
|
||||
if "".respond_to?(:safe_constantize)
|
||||
def active_model_serializer
|
||||
@active_model_serializer ||= "#{self.name}Serializer".safe_constantize
|
||||
"#{self.name}Serializer".safe_constantize
|
||||
end
|
||||
else
|
||||
def active_model_serializer
|
||||
return @active_model_serializer if defined?(@active_model_serializer)
|
||||
|
||||
begin
|
||||
@active_model_serializer = "#{self.name}Serializer".constantize
|
||||
"#{self.name}Serializer".constantize
|
||||
rescue NameError => e
|
||||
raise unless e.message =~ /uninitialized constant/
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user