mirror of
https://github.com/github/rails.git
synced 2026-01-30 00:38:00 -05:00
Dependencies can autoload directories of nested classes.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4769 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
*SVN*
|
||||
|
||||
* Dependencies can autoload directories of nested classes. [Jeremy Kemper]
|
||||
Example:
|
||||
invoice.rb class Invoice
|
||||
invoice/lineitem.rb class Invoice::Lineitem
|
||||
|
||||
* Add Deprecation.silence so that Reloadable does not scold itself. [Nicholas Seckar]
|
||||
|
||||
* Add debugging logging to Dependencies. Currently can be enabled with Dependencies.log_activity = true; adding to Initializer and documenting is forthcoming. [Nicholas Seckar]
|
||||
|
||||
@@ -282,7 +282,11 @@ class Class
|
||||
super
|
||||
else
|
||||
begin
|
||||
parent.send :const_missing, class_id
|
||||
begin
|
||||
Dependencies.load_missing_constant self, class_id
|
||||
rescue NameError
|
||||
parent.send :const_missing, class_id
|
||||
end
|
||||
rescue NameError => e
|
||||
# Make sure that the name we are missing is the one that caused the error
|
||||
parent_qualified_name = Dependencies.qualified_name_for parent, class_id
|
||||
|
||||
2
activesupport/test/autoloading_fixtures/class_folder.rb
Normal file
2
activesupport/test/autoloading_fixtures/class_folder.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class ClassFolder
|
||||
end
|
||||
@@ -0,0 +1,2 @@
|
||||
class ClassFolder::InlineClass
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
class ClassFolder
|
||||
class NestedClass
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,2 @@
|
||||
class ModuleFolder::InlineClass
|
||||
end
|
||||
@@ -1,2 +1,4 @@
|
||||
class ModuleFolder::NestedClass
|
||||
end
|
||||
module ModuleFolder
|
||||
class NestedClass
|
||||
end
|
||||
end
|
||||
|
||||
@@ -125,20 +125,48 @@ class DependenciesTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_directories_should_manifest_as_modules
|
||||
def test_directories_manifest_as_modules_unless_const_defined
|
||||
with_loading 'autoloading_fixtures' do
|
||||
assert_kind_of Module, ModuleFolder
|
||||
Object.send :remove_const, :ModuleFolder
|
||||
end
|
||||
end
|
||||
|
||||
def test_nested_class_access
|
||||
def test_module_with_nested_class
|
||||
with_loading 'autoloading_fixtures' do
|
||||
assert_kind_of Class, ModuleFolder::NestedClass
|
||||
Object.send :remove_const, :ModuleFolder
|
||||
end
|
||||
end
|
||||
|
||||
def test_module_with_nested_inline_class
|
||||
with_loading 'autoloading_fixtures' do
|
||||
assert_kind_of Class, ModuleFolder::InlineClass
|
||||
Object.send :remove_const, :ModuleFolder
|
||||
end
|
||||
end
|
||||
|
||||
def test_directories_may_manifest_as_nested_classes
|
||||
with_loading 'autoloading_fixtures' do
|
||||
assert_kind_of Class, ClassFolder
|
||||
Object.send :remove_const, :ClassFolder
|
||||
end
|
||||
end
|
||||
|
||||
def test_class_with_nested_class
|
||||
with_loading 'autoloading_fixtures' do
|
||||
assert_kind_of Class, ClassFolder::NestedClass
|
||||
Object.send :remove_const, :ClassFolder
|
||||
end
|
||||
end
|
||||
|
||||
def test_class_with_nested_inline_class
|
||||
with_loading 'autoloading_fixtures' do
|
||||
assert_kind_of Class, ClassFolder::InlineClass
|
||||
Object.send :remove_const, :ClassFolder
|
||||
end
|
||||
end
|
||||
|
||||
def test_nested_class_can_access_sibling
|
||||
with_loading 'autoloading_fixtures' do
|
||||
sibling = ModuleFolder::NestedClass.class_eval "NestedSibling"
|
||||
|
||||
Reference in New Issue
Block a user