Skip to content

Commit

Permalink
Hopefully fix CI errors where constant not found
Browse files Browse the repository at this point in the history
  • Loading branch information
bf4 committed Jul 17, 2015
1 parent bb5b39c commit 7f83aa1
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/active_model/serializer/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 7f83aa1

Please sign in to comment.