[go: up one dir, main page]

Skip to content

Commit

Permalink
Deprecate MissingSourceFile in favor of LoadError.
Browse files Browse the repository at this point in the history
`MissingSourceFile` was just an alias to `LoadError` and was not
being raised inside the framework.
  • Loading branch information
rafaelfranca committed Jan 2, 2015
1 parent 48deeab commit 734d97d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions activesupport/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
* Deprecate `MissingSourceFile` in favor of `LoadError`.

`MissingSourceFile` was just an alias to `LoadError` and was not being
raised inside the framework.

*Rafael Mendonça França*

* Add support for error dispatcher classes in `ActiveSupport::Rescuable`.
Now it acts closer to Ruby's rescue.

Expand Down
4 changes: 3 additions & 1 deletion activesupport/lib/active_support/core_ext/load_error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'active_support/deprecation/proxy_wrappers'

class LoadError
REGEXPS = [
/^no such file to load -- (.+)$/i,
Expand Down Expand Up @@ -25,4 +27,4 @@ def is_missing?(location)
end
end

MissingSourceFile = LoadError
MissingSourceFile = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('MissingSourceFile', 'LoadError')
9 changes: 9 additions & 0 deletions activesupport/test/core_ext/load_error_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
require 'abstract_unit'
require 'active_support/core_ext/load_error'


class TestMissingSourceFile < ActiveSupport::TestCase
def test_it_is_deprecated
assert_deprecated do
MissingSourceFile.new
end
end
end

class TestLoadError < ActiveSupport::TestCase
def test_with_require
assert_raise(LoadError) { require 'no_this_file_don\'t_exist' }
Expand Down
6 changes: 3 additions & 3 deletions guides/source/active_support_core_extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3873,7 +3873,7 @@ def default_helper_module!
module_name = name.sub(/Controller$/, '')
module_path = module_name.underscore
helper module_path
rescue MissingSourceFile => e
rescue LoadError => e
raise e unless e.is_missing? "helpers/#{module_path}_helper"
rescue NameError => e
raise e unless e.missing_name? "#{module_name}Helper"
Expand All @@ -3885,7 +3885,7 @@ NOTE: Defined in `active_support/core_ext/name_error.rb`.
Extensions to `LoadError`
-------------------------

Active Support adds `is_missing?` to `LoadError`, and also assigns that class to the constant `MissingSourceFile` for backwards compatibility.
Active Support adds `is_missing?` to `LoadError`.

Given a path name `is_missing?` tests whether the exception was raised due to that particular file (except perhaps for the ".rb" extension).

Expand All @@ -3896,7 +3896,7 @@ def default_helper_module!
module_name = name.sub(/Controller$/, '')
module_path = module_name.underscore
helper module_path
rescue MissingSourceFile => e
rescue LoadError => e
raise e unless e.is_missing? "helpers/#{module_path}_helper"
rescue NameError => e
raise e unless e.missing_name? "#{module_name}Helper"
Expand Down

0 comments on commit 734d97d

Please sign in to comment.