aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2012-09-06 13:31:28 +0200
committerXavier Noria <fxn@hashref.com>2012-09-06 13:39:23 +0200
commit3ee191fd95584dc984ee76486a932a54419156d2 (patch)
tree08107cf46e459c94fbe1b3dfa00974d326ef9aba
parent3c27dcc639a9380ff86c76ed6ed089a072d64df0 (diff)
downloadrails-3ee191fd95584dc984ee76486a932a54419156d2.tar.gz
rails-3ee191fd95584dc984ee76486a932a54419156d2.tar.bz2
rails-3ee191fd95584dc984ee76486a932a54419156d2.zip
no more const_missing combinatorics
Basically, const_missing had a loop to try parent namespaces if the constant lookup failed, but at the same time delegated to load_missing_constant which in turn also walks up parent namespaces calling const_missing by hand. In the case of missing constants this results in repeated work in some funky nested way.
-rw-r--r--activesupport/lib/active_support/dependencies.rb43
1 files changed, 2 insertions, 41 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index d6bc95a522..ab96538fdf 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -169,47 +169,8 @@ module ActiveSupport #:nodoc:
end
def const_missing(const_name)
- klass_name = name.presence || "Object"
-
- # Since Ruby does not pass the nesting at the point the unknown
- # constant triggered the callback we cannot fully emulate constant
- # name lookup and need to make a trade-off: we are going to assume
- # that the nesting in the body of Foo::Bar is [Foo::Bar, Foo] even
- # though it might not be. Counterexamples are
- #
- # class Foo::Bar
- # Module.nesting # => [Foo::Bar]
- # end
- #
- # or
- #
- # module M::N
- # module S::T
- # Module.nesting # => [S::T, M::N]
- # end
- # end
- #
- # for example.
- nesting = []
- klass_name.to_s.scan(/::|$/) { nesting.unshift $` }
-
- # If there are multiple levels of nesting to search under, the top
- # level is the one we want to report as the lookup fail.
- error = nil
-
- nesting.each do |namespace|
- begin
- return Dependencies.load_missing_constant Inflector.constantize(namespace), const_name
- rescue NoMethodError then raise
- rescue NameError => e
- error ||= e
- end
- end
-
- # Raise the first error for this set. If this const_missing came from an
- # earlier const_missing, this will result in the real error bubbling
- # all the way up
- raise error
+ namespace = name.presence || "Object"
+ Dependencies.load_missing_constant(Inflector.constantize(namespace), const_name)
end
def unloadable(const_desc = self)