Skip to content
Browse files

fixes for Rails 1.1.

  • Loading branch information...
1 parent 3dd7f54 commit 552ef72b768ff597052d91cf3afba91371e30865 shugo committed May 24, 2006
Showing with 49 additions and 21 deletions.
  1. +49 −21 lib/apache/rails-dispatcher.rb
View
70 lib/apache/rails-dispatcher.rb
@@ -54,7 +54,7 @@
require "action_mailer"
require "action_web_service"
require "active_support/whiny_nil"
-require "rails_info"
+require "ruby_version_check"
Object.send(:remove_const, :RAILS_ENV)
@@ -134,7 +134,7 @@ def dispatch
@@current_environment.load_environment
conf_constants =
(@@current_environment.module.constants - old_constants).select { |c|
- /\A(RAILS_ROOT|RAILS_ENV|ADDITIONAL_LOAD_PATHS|RAILS_DEFAULT_LOGGER|[A-Z_]+_(CONF|PATH|DIR)|Controllers)\z/.match(c)
+ /\A(RAILS_ROOT|RAILS_ENV|ADDITIONAL_LOAD_PATHS|RAILS_DEFAULT_LOGGER|[A-Z_]+_(CONF|PATH|DIR))\z/.match(c)
}
begin
if /\A\/*\z/.match(r.options["rails_uri_root"])
@@ -183,8 +183,8 @@ def get_environment(rails_root)
def prepare_application
ActionController::Routing::Routes.reload if Dependencies.load?
- unless Controllers.const_defined?(:ApplicationController)
- Controllers.const_load!(:ApplicationController, "application")
+ unless @@current_environment.module.const_defined?(:ApplicationController)
+ require_dependency("application.rb")
end
end
@@ -266,12 +266,6 @@ def load_environment
environment_path = File.expand_path("config/environment.rb",
@rails_root)
load_file(environment_path)
- if @controllers
- remove_const(:Controllers)
- @module.const_set(:Controllers, @controllers)
- else
- @controllers = @module.const_get(:Controllers)
- end
end
def load_file(filename)
@@ -317,24 +311,60 @@ def setup_module
mod.send(:define_method, :load) do |filename|
env.load_file(filename)
end
-# mod.send(:define_method, :require) do |filename|
-# env.require_file(filename)
-# end
+ copy_constants(mod)
return mod
end
+
+ # copy constants for plugins
+ def copy_constants(mod)
+ mod.const_set(:Rails, Rails)
+ mod.const_set(:ActiveRecord, ActiveRecord)
+ mod.const_set(:ActionController, ActionController)
+ mod.const_set(:ActionView, ActionView)
+ mod.const_set(:ActionMailer, ActionMailer)
+ mod.const_set(:ActionWebService, ActionWebService)
+ end
end
end
end
module Dependencies
def require_or_load(file_name)
- file_name = "#{file_name}.rb" unless ! load? || file_name[-3..-1] == '.rb'
+ file_name = $1 if file_name =~ /^(.*)\.rb$/
+ return if loaded.include?(file_name)
+
+ # Record that we've seen this file *before* loading it to avoid an
+ # infinite loop with mutual dependencies.
+ loaded << file_name
+
env = Apache::RailsDispatcher.current_environment
if env
- load? ? env.load_file(file_name) : env.require_file(file_name)
+ load_func = env.method(:load_file)
+ require_func = env.method(:require_file)
+ else
+ load_func = method(:load)
+ require_func = method(:require)
+ end
+
+ if load?
+ begin
+ # Enable warnings iff this file has not been loaded before and
+ # warnings_on_first_load is set.
+ if !warnings_on_first_load or history.include?(file_name)
+ load_func.call("#{file_name}.rb")
+ else
+ enable_warnings { load_func.call("#{file_name}.rb") }
+ end
+ rescue
+ loaded.delete file_name
+ raise
+ end
else
- load? ? load(file_name) : require(file_name)
+ require_func.call(file_name)
end
+
+ # Record history *after* loading so first load gets warnings.
+ history << file_name
end
end
@@ -397,12 +427,10 @@ def const_missing(class_id)
if env.module.const_defined?(class_id)
return env.module.const_get(class_id)
end
- if class_id != :Controllers && Object.const_defined?(:Controllers) &&
- self != Controllers && Controllers.const_available?(class_id)
- return Controllers.const_get(class_id)
- end
begin
- require_dependency(class_id.to_s.demodulize.underscore)
+ file_name = class_id.to_s.demodulize.underscore
+ file_path = as_load_path.empty? ? file_name : "#{as_load_path}/#{file_name}"
+ require_dependency(file_path)
if env.module.const_defined?(class_id)
return env.module.const_get(class_id)
else

0 comments on commit 552ef72

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