Add config.serializer_lookup_enabled that defaults true

This commit is contained in:
Benjamin Fleischer
2015-11-30 00:12:21 -06:00
parent 47a14b6581
commit 28394340d8
7 changed files with 54 additions and 10 deletions

View File

@@ -208,6 +208,7 @@ module ActiveModel
# 2. try again with superclass, if present
# 3. nil
def self.get_serializer_for(klass)
return nil unless config.serializer_lookup_enabled
serializers_cache.fetch_or_store(klass) do
# NOTE(beauby): When we drop 1.9.3 support we can lazify the map for perfs.
serializer_class = serializer_lookup_chain_for(klass).map(&:safe_constantize).find { |x| x && x < ActiveModel::Serializer }

View File

@@ -9,6 +9,7 @@ module ActiveModel
included do |base|
config = base.config
config.collection_serializer = ActiveModel::Serializer::CollectionSerializer
config.serializer_lookup_enabled = true
def config.array_serializer=(collection_serializer)
self.collection_serializer = collection_serializer
@@ -20,7 +21,6 @@ module ActiveModel
config.adapter = :attributes
config.jsonapi_resource_type = :plural
config.automatic_lookup = true
end
end
end