mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Eager load modules on boot
Using ActiveModelSerializers with a threaded web server eg. Puma uninitialized constant errors are thrown. Leaving this article for reference: http://blog.plataformatec.com.br/2012/08/eager-loading-for-greater-good/.
This commit is contained in:
parent
fce8be0dc0
commit
2a8b9f4105
@ -18,6 +18,7 @@ module ActiveModel
|
||||
# @see #serializable_hash for more details on these valid keys.
|
||||
SERIALIZABLE_HASH_VALID_KEYS = [:only, :except, :methods, :include, :root].freeze
|
||||
extend ActiveSupport::Autoload
|
||||
eager_autoload do
|
||||
autoload :Adapter
|
||||
autoload :Null
|
||||
autoload :Attribute
|
||||
@ -28,6 +29,7 @@ module ActiveModel
|
||||
autoload :BelongsToReflection
|
||||
autoload :HasOneReflection
|
||||
autoload :HasManyReflection
|
||||
end
|
||||
include ActiveSupport::Configurable
|
||||
include Caching
|
||||
|
||||
|
||||
@ -5,16 +5,19 @@ require 'active_support/core_ext/string/inflections'
|
||||
require 'active_support/json'
|
||||
module ActiveModelSerializers
|
||||
extend ActiveSupport::Autoload
|
||||
eager_autoload do
|
||||
autoload :Model
|
||||
autoload :Callbacks
|
||||
autoload :Deserialization
|
||||
autoload :SerializableResource
|
||||
autoload :SerializationContext
|
||||
autoload :Logging
|
||||
autoload :Test
|
||||
autoload :Adapter
|
||||
autoload :JsonPointer
|
||||
autoload :Deprecate
|
||||
autoload :LookupChain
|
||||
autoload :Deserialization
|
||||
end
|
||||
|
||||
class << self; attr_accessor :logger; end
|
||||
self.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))
|
||||
@ -46,6 +49,11 @@ module ActiveModelSerializers
|
||||
$VERBOSE = original_verbose
|
||||
end
|
||||
|
||||
def self.eager_load!
|
||||
super
|
||||
ActiveModel::Serializer.eager_load!
|
||||
end
|
||||
|
||||
require 'active_model/serializer/version'
|
||||
require 'active_model/serializer'
|
||||
require 'active_model/serializable_resource'
|
||||
|
||||
@ -22,14 +22,16 @@ module ActiveModelSerializers
|
||||
module Adapter
|
||||
class JsonApi < Base
|
||||
extend ActiveSupport::Autoload
|
||||
eager_autoload do
|
||||
autoload :Jsonapi
|
||||
autoload :ResourceIdentifier
|
||||
autoload :Relationship
|
||||
autoload :Link
|
||||
autoload :PaginationLinks
|
||||
autoload :Meta
|
||||
autoload :Error
|
||||
autoload :Deserialization
|
||||
autoload :Relationship
|
||||
end
|
||||
|
||||
def self.default_key_transform
|
||||
:dash
|
||||
|
||||
@ -5,6 +5,8 @@ require 'action_controller/serialization'
|
||||
|
||||
module ActiveModelSerializers
|
||||
class Railtie < Rails::Railtie
|
||||
config.eager_load_namespaces << ActiveModelSerializers
|
||||
|
||||
config.to_prepare do
|
||||
ActiveModel::Serializer.serializers_cache.clear
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user