diff options
author | José Valim <jose.valim@gmail.com> | 2011-09-23 16:46:33 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-09-23 16:46:33 +0200 |
commit | e8987c30d0dc3ae5903a6d3a6e293641759b6fc4 (patch) | |
tree | 5830b6162bdd90980ce6f2ddf9170aec01960eb2 | |
parent | b2f34d1e3591df0f19f01ba30160661175c9a6b6 (diff) | |
download | rails-e8987c30d0dc3ae5903a6d3a6e293641759b6fc4.tar.gz rails-e8987c30d0dc3ae5903a6d3a6e293641759b6fc4.tar.bz2 rails-e8987c30d0dc3ae5903a6d3a6e293641759b6fc4.zip |
Use safe_constantize where possible.
-rw-r--r-- | actionpack/lib/action_controller/metal/params_wrapper.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/action_view/test_case.rb | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/reachable.rb | 4 |
3 files changed, 5 insertions, 12 deletions
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 6acbb23907..e0d8e1c992 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -141,19 +141,16 @@ module ActionController # try to find Foo::Bar::User, Foo::User and finally User. def _default_wrap_model #:nodoc: return nil if self.anonymous? - model_name = self.name.sub(/Controller$/, '').singularize begin - model_klass = model_name.constantize - rescue NameError, ArgumentError => e - if e.message =~ /is not missing constant|uninitialized constant #{model_name}/ + if model_klass = model_name.safe_constantize + model_klass + else namespaces = model_name.split("::") namespaces.delete_at(-2) break if namespaces.last == model_name model_name = namespaces.join("::") - else - raise end end until model_klass diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 2cc85a9f69..c4d51d7946 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -54,10 +54,8 @@ module ActionView end def determine_default_helper_class(name) - mod = name.sub(/Test$/, '').constantize + mod = name.sub(/Test$/, '').safe_constantize mod.is_a?(Class) ? nil : mod - rescue NameError - nil end def helper_method(*methods) diff --git a/activesupport/lib/active_support/core_ext/module/reachable.rb b/activesupport/lib/active_support/core_ext/module/reachable.rb index 443d2c3d53..5d3d0e9851 100644 --- a/activesupport/lib/active_support/core_ext/module/reachable.rb +++ b/activesupport/lib/active_support/core_ext/module/reachable.rb @@ -3,8 +3,6 @@ require 'active_support/core_ext/string/inflections' class Module def reachable? #:nodoc: - !anonymous? && name.constantize.equal?(self) - rescue NameError - false + !anonymous? && name.safe_constantize.equal?(self) end end |