public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
New approach to reloading that uses remove_const on ARs and AOs as well as 
ACs

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@507 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
dhh (author)
Tue Jan 25 10:00:15 -0800 2005
commit  ee662e9768f3682389daaa54d38c3e46cdcd4408
tree    e98164fe1659358726b4ff30a6fab9ecc3abab8e
parent  c37e8d365b9470a593668476fc9be0af6da2e812
...
18
19
20
21
22
 
 
23
24
25
26
...
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
47
48
49
...
57
58
59
60
 
61
62
63
...
18
19
20
 
 
21
22
23
24
25
26
...
32
33
34
 
 
 
 
 
 
 
 
 
 
35
 
36
37
38
39
...
47
48
49
 
50
51
52
53
0
@@ -18,8 +18,8 @@
0
       loaded << file_name
0
       begin
0
         require_or_load(file_name)
0
- rescue LoadError
0
- raise unless swallow_load_errors
0
+ rescue Object => e
0
+ raise ScriptError, "#{e.message}" unless e.is_a?(LoadError) && swallow_load_errors
0
       end
0
     end
0
   end
0
0
@@ -32,18 +32,8 @@
0
     self.loaded = [ ]
0
   end
0
   
0
- def reload
0
- loaded.each do |file_name|
0
- begin
0
- silence_warnings { load("#{file_name}.rb") }
0
- rescue LoadError
0
- # We don't care if the file was removed now
0
- end
0
- end
0
- end
0
-
0
   def require_or_load(file_name)
0
- mechanism == :load ? silence_warnings { load("#{file_name}.rb") } : require(file_name)
0
+ load? ? load("#{file_name}.rb") : require(file_name)
0
   end
0
 end
0
 
0
@@ -57,7 +47,7 @@
0
     # require_association when using single-table inheritance.
0
     def const_missing(class_id)
0
       begin
0
- require_dependency(Inflector.underscore(Inflector.demodulize(class_id.to_s)))
0
+ require_or_load(class_id.to_s.demodulize.underscore)
0
         if Object.const_defined?(class_id) then return Object.const_get(class_id) else raise LoadError end
0
       rescue LoadError
0
         raise NameError, "uninitialized constant #{class_id}"
...
34
35
36
37
38
39
40
41
42
43
...
43
44
45
46
 
47
48
49
50
51
52
53
54
55
56
 
 
 
 
 
57
58
59
60
61
62
63
64
65
66
...
84
85
86
87
88
89
90
91
92
93
94
95
96
...
34
35
36
 
 
37
38
39
40
41
...
41
42
43
 
44
45
46
47
48
49
 
 
 
 
 
50
51
52
53
54
55
 
 
 
 
 
 
56
57
58
...
76
77
78
 
 
 
 
 
 
 
79
80
81
0
@@ -34,8 +34,6 @@
0
     
0
         controller_name, module_name = controller_name(request.parameters), module_name(request.parameters)
0
 
0
- reload_models
0
-
0
         require_or_load("application")
0
         require_or_load(controller_path(controller_name, module_name))
0
 
0
0
0
@@ -43,24 +41,18 @@
0
       rescue Object => exception
0
         ActionController::Base.process_with_exception(request, response, exception).out
0
       ensure
0
- remove_controllers(controller_name)
0
+ reset_application if Dependencies.load?
0
         Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT)
0
       end
0
     end
0
     
0
     private
0
- def reload_models
0
- if Dependencies.load?
0
- ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses
0
- Dependencies.reload
0
- end
0
+ def reset_application
0
+ Dependencies.clear
0
+ ActiveRecord::Base.remove_subclasses
0
+ ActiveRecord::Observer.remove_subclasses
0
+ ActionController::Base.remove_subclasses
0
       end
0
-
0
- def remove_controllers(controller_name)
0
- if Dependencies.load? && defined?(ApplicationController)
0
- remove_class_hierarchy(controller_class(controller_name), ActionController::Base)
0
- end
0
- end
0
     
0
       def controller_path(controller_name, module_name = nil)
0
         if module_name
0
@@ -84,13 +76,6 @@
0
 
0
       def module_name(parameters)
0
         parameters["module"].downcase.gsub(/[^_a-zA-Z0-9]/, "").untaint if parameters["module"]
0
- end
0
-
0
- def remove_class_hierarchy(klass, until_superclass)
0
- while klass
0
- Object.send(:remove_const, "#{klass}".intern)
0
- klass = (klass.superclass unless until_superclass == klass.superclass)
0
- end
0
       end
0
   end
0
 end

Comments

    No one has commented yet.