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