diff --git a/lib/active_model/serializer/adapter.rb b/lib/active_model/serializer/adapter.rb index b463a9e2a..ef4bac7cc 100644 --- a/lib/active_model/serializer/adapter.rb +++ b/lib/active_model/serializer/adapter.rb @@ -30,9 +30,6 @@ def get(adapter) # 2. return if registered adapter_map.fetch(adapter_name) { # 3. try to find adapter class from environment - # We want to avoid the adapter.to_s.classify since it depends on the - # Inflector. For this reason, we cannot use get_const nor - # safe_constantize. adapter_class = find_by_name(adapter_name) if adapter_class register(adapter_name, adapter_class) @@ -44,11 +41,13 @@ def get(adapter) } end + # We want to avoid the adapter.to_s.classify since it depends on the + # Inflector, and may incorrectly inflect api to API, rather than Api. def find_by_name(adapter_name) adapter_const = self.constants.find {|adapter_klass| adapter_klass.to_s.downcase.underscore === adapter_name } - adapter_const && self.const_get(adapter_const.to_sym) + adapter_const && "ActiveModel::Serializer::Adapter::#{adapter_const}".safe_constantize end private :find_by_name