Skip to content

Commit

Permalink
Use Adapter.const_get instead of safe_constantize
Browse files Browse the repository at this point in the history
  • Loading branch information
bf4 committed Sep 9, 2015
1 parent 819137e commit 6e886c0
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/active_model/serializer/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ def lookup(adapter)
register(adapter_name, adapter_class)
adapter_class
}
rescue ArgumentError => e
failure_message =
"Unknown adapter: #{adapter.inspect}. Valid adapters are: #{adapters}"
raise UnknownAdapterError, failure_message, e.backtrace
rescue NameError => e
rescue NameError, ArgumentError => e
failure_message =
"NameError: #{e.message}. Unknown adapter: #{adapter.inspect}. Valid adapters are: #{adapters}"
raise UnknownAdapterError, failure_message, e.backtrace
Expand All @@ -73,7 +69,7 @@ def lookup(adapter)
# @api private
def find_by_name(adapter_name)
adapter_name = adapter_name.to_s.classify.tr('API', 'Api')
"ActiveModel::Serializer::Adapter::#{adapter_name}".safe_constantize or # rubocop:disable Style/AndOr
ActiveModel::Serializer::Adapter.const_get(adapter_name.to_sym) or # rubocop:disable Style/AndOr
fail UnknownAdapterError
end
private :find_by_name
Expand Down

0 comments on commit 6e886c0

Please sign in to comment.