Commit b992ab23 by Prem Sichanugrist

Fix problem that Module#const_get might try to lookup the constant in the…

Fix problem that Module#const_get might try to lookup the constant in the ancestor class, and fixing the strange error from Rails 2.3.x dependency management

Closes #478
parent 54093c67
......@@ -136,9 +136,28 @@ module Paperclip
end
def class_for(class_name)
# Ruby 1.9 introduces an inherit argument for Module#const_get and
# #const_defined? and changes their default behavior.
# https://github.com/rails/rails/blob/v3.0.9/activesupport/lib/active_support/inflector/methods.rb#L89
if Module.method(:const_get).arity == 1
class_name.split('::').inject(Object) do |klass, partial_class_name|
klass.const_get(partial_class_name)
end
else
class_name.split('::').inject(Object) do |klass, partial_class_name|
klass.const_get(partial_class_name, false)
end
end
rescue ArgumentError => e
# Sadly, we need to capture ArguementError here because Rails 2.3.x
# Active Support dependency's management will try to the constant inherited
# from Object, and fail misably with "Object is not missing constant X" error
# https://github.com/rails/rails/blob/v2.3.12/activesupport/lib/active_support/dependencies.rb#L124
if e.message =~ /is not missing constant/
raise NameError, "uninitialized constant #{class_name}"
else
raise e
end
end
end
......
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