Skip to content
This repository
Browse code

Fixed that auto reloading would some times not work or would reload t…

…he models twice #475 [Tobias Luetke]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@408 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 6c1fe632a3c2d4e71ce8f9e877f57180990c1532 1 parent c755b29
David Heinemeier Hansson authored January 15, 2005
2  railties/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Fixed that auto reloading would some times not work or would reload the models twice #475 [Tobias Luetke]
  4
+
3 5
 * Added rewrite rules to deal with caching to public/.htaccess
4 6
 
5 7
 * Added the option to specify a controller name to "generate scaffold" and made the default controller name the plural form of the model.
110  railties/lib/dispatcher.rb
@@ -24,60 +24,70 @@
24 24
 require 'breakpoint'
25 25
 
26 26
 class Dispatcher
27  
-  def self.dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS)
28  
-    Breakpoint.activate_drb("druby://localhost:#{BREAKPOINT_SERVER_PORT}", nil, !defined?(FastCGI)) if defined?(BREAKPOINT_SERVER_PORT)
29  
-
30  
-    begin
31  
-      request  = ActionController::CgiRequest.new(cgi, session_options)
32  
-      response = ActionController::CgiResponse.new(cgi)
33  
-      
34  
-      controller_name, module_name = controller_name(request.parameters), module_name(request.parameters)
  27
+  
  28
+  class <<self
  29
+    
  30
+    def dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS)
  31
+     Breakpoint.activate_drb("druby://localhost:#{BREAKPOINT_SERVER_PORT}", nil, !defined?(FastCGI)) if defined?(BREAKPOINT_SERVER_PORT)
35 32
 
36  
-      require_dependency("application")
37  
-      require_dependency(controller_path(controller_name, module_name))
  33
+      begin
  34
+        request  = ActionController::CgiRequest.new(cgi, session_options)
  35
+        response = ActionController::CgiResponse.new(cgi)
  36
+    
  37
+        controller_name, module_name = controller_name(request.parameters), module_name(request.parameters)
38 38
 
39  
-      controller_class(controller_name).process(request, response).out
40  
-    rescue Object => exception
41  
-      ActionController::Base.process_with_exception(request, response, exception).out
42  
-    ensure
43  
-      if Dependencies.mechanism == :load
44  
-        ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses
45  
-        Dependencies.reload rescue nil # Ignore out of order reloading errors for Controllers
46  
-        remove_class_hierarchy(controller_class(controller_name), ActionController::Base)
  39
+        require_dependency("application")
  40
+        require_dependency(controller_path(controller_name, module_name))
  41
+        
  42
+        reload_application rescue nil # Ignore out of order reloading errors for Controllers
  43
+        
  44
+        controller_class(controller_name).process(request, response).out
  45
+      rescue Object => exception
  46
+        ActionController::Base.process_with_exception(request, response, exception).out
  47
+      ensure      
  48
+        remove_class_hierarchy(controller_class(controller_name), ActionController::Base) if Dependencies.mechanism == :load
  49
+        Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT)
47 50
       end
48  
-      
49  
-      Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT)
50 51
     end
51  
-  end
52  
-  
53  
-  def self.controller_path(controller_name, module_name = nil)
54  
-    if module_name
55  
-      "#{module_name}/#{Inflector.underscore(controller_name)}_controller"
56  
-    else
57  
-      "#{Inflector.underscore(controller_name)}_controller"
58  
-    end
59  
-  end
60  
-  
61  
-  def self.controller_class(controller_name)
62  
-    Object.const_get(controller_class_name(controller_name))
63  
-  end
64  
-  
65  
-  def self.controller_class_name(controller_name)
66  
-    "#{Inflector.camelize(controller_name)}Controller"
67  
-  end
68  
-  
69  
-  def self.controller_name(parameters)
70  
-    parameters["controller"].gsub(/[^_a-zA-Z0-9]/, "").untaint
71  
-  end
72  
-  
73  
-  def self.module_name(parameters)
74  
-    parameters["module"].gsub(/[^_a-zA-Z0-9]/, "").untaint if parameters["module"]
75  
-  end
  52
+    
  53
+    private
  54
+    
  55
+      def reload_application
  56
+        if Dependencies.mechanism == :load
  57
+          ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses
  58
+          Dependencies.reload 
  59
+        end    
  60
+      end
76 61
 
77  
-  def self.remove_class_hierarchy(klass, until_superclass)
78  
-    while klass
79  
-      Object.send(:remove_const, "#{klass}".intern)
80  
-      klass = (klass.superclass unless until_superclass == klass.superclass)
81  
-    end
  62
+      def controller_path(controller_name, module_name = nil)
  63
+        if module_name
  64
+          "#{module_name}/#{Inflector.underscore(controller_name)}_controller"
  65
+        else
  66
+          "#{Inflector.underscore(controller_name)}_controller"
  67
+        end
  68
+      end
  69
+
  70
+      def controller_class(controller_name)
  71
+        Object.const_get(controller_class_name(controller_name))
  72
+      end
  73
+
  74
+      def controller_class_name(controller_name)
  75
+        "#{Inflector.camelize(controller_name)}Controller"
  76
+      end
  77
+
  78
+      def controller_name(parameters)
  79
+        parameters["controller"].gsub(/[^_a-zA-Z0-9]/, "").untaint
  80
+      end
  81
+
  82
+      def module_name(parameters)
  83
+        parameters["module"].gsub(/[^_a-zA-Z0-9]/, "").untaint if parameters["module"]
  84
+      end
  85
+
  86
+      def remove_class_hierarchy(klass, until_superclass)
  87
+        while klass
  88
+          Object.send(:remove_const, "#{klass}".intern)
  89
+          klass = (klass.superclass unless until_superclass == klass.superclass)
  90
+        end
  91
+      end
82 92
   end
83 93
 end

0 notes on commit 6c1fe63

Please sign in to comment.
Something went wrong with that request. Please try again.