mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Merge pull request #1353 from bf4/disable_serializer_lookup
Allow users to globally opt out of automatic serializer lookup
This commit is contained in:
@@ -10,6 +10,12 @@ module ActionController
|
||||
# Deprecated
|
||||
ADAPTER_OPTION_KEYS = ActiveModel::SerializableResource::ADAPTER_OPTION_KEYS
|
||||
|
||||
module ClassMethods
|
||||
def serialization_scope(scope)
|
||||
self._serialization_scope = scope
|
||||
end
|
||||
end
|
||||
|
||||
included do
|
||||
class_attribute :_serialization_scope
|
||||
self._serialization_scope = :current_user
|
||||
@@ -55,11 +61,5 @@ module ActionController
|
||||
super(serializable_resource, options)
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def serialization_scope(scope)
|
||||
self._serialization_scope = scope
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -172,6 +172,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 }
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user