Commit 76bac64a by Prem Sichanugrist

`Module#const_get` was unreliable on returning the right constant. We should…

`Module#const_get` was unreliable on returning the right constant. We should check if the constant has been defined first before trying to call `Module#const_get`
parent b992ab23
...@@ -141,11 +141,11 @@ module Paperclip ...@@ -141,11 +141,11 @@ module Paperclip
# https://github.com/rails/rails/blob/v3.0.9/activesupport/lib/active_support/inflector/methods.rb#L89 # https://github.com/rails/rails/blob/v3.0.9/activesupport/lib/active_support/inflector/methods.rb#L89
if Module.method(:const_get).arity == 1 if Module.method(:const_get).arity == 1
class_name.split('::').inject(Object) do |klass, partial_class_name| class_name.split('::').inject(Object) do |klass, partial_class_name|
klass.const_get(partial_class_name) klass.const_defined?(partial_class_name) ? klass.const_get(partial_class_name) : klass.const_missing(partial_class_name)
end end
else else
class_name.split('::').inject(Object) do |klass, partial_class_name| class_name.split('::').inject(Object) do |klass, partial_class_name|
klass.const_get(partial_class_name, false) klass.const_defined?(partial_class_name) ? klass.const_get(partial_class_name, false) : klass.const_missing(partial_class_name)
end end
end end
rescue ArgumentError => e rescue ArgumentError => e
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment