From 74165eb6acaca98d4da13409c4e5b5ecc9d260f7 Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Tue, 8 Aug 2006 21:21:04 +0000 Subject: New dependencies implementation git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4728 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/CHANGELOG | 7 +++++++ railties/lib/initializer.rb | 41 +++++++++++++++++++++++++++++++++++++++++ railties/lib/webrick_server.rb | 1 + 3 files changed, 49 insertions(+) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 50daa2f009..413639a61d 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,9 +1,16 @@ *SVN* +<<<<<<< .mine +* Add "require 'dispatcher'" to webrick server in the continuing quest to squash webrick weirdness. [Nicholas Seckar] + +* Add autoload_paths support to Initializer. [Nicholas Seckar] + +======= * Fix Dispatcher.reset_application! so that AR subclasses are removed and Observers re-initialized *after* Reloadable classes are removed. Closes #5743. [Rick Olson] * Clarify usage of script/plugin source. Closes #5344. [james.adam@gmail.com] +>>>>>>> .r4727 * Add Dispatcher.to_prepare and config.to_prepare to provide a pre-request hook. [Nicholas Seckar] * Tweak the Rails load order so observers are loaded after plugins, and reloaded in development mode. Closed #5279. [Rick Olson] diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 8abc3231db..ef83c2c259 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -80,6 +80,7 @@ module Rails set_connection_adapters require_frameworks + set_autoload_paths load_environment initialize_database @@ -125,6 +126,13 @@ module Rails $LOAD_PATH.uniq! end + # Set the paths from which Rails will automatically load source files. + def set_autoload_paths + Dependencies.autoload_paths = configuration.autoload_paths.uniq + # Freeze the array so future modifications will fail rather than do nothing mysteriously + configuration.autoload_paths.freeze + end + # Sets the +RAILS_CONNECTION_ADAPTERS+ constant based on the value of # Configuration#connection_adapters. This constant is used to determine # which database adapters should be loaded (by default, all adapters are @@ -412,6 +420,11 @@ module Rails # all +app+, +lib+, +vendor+ and mock paths are included in this list. attr_accessor :load_paths + # An array of paths from which Rails will automatically load classes and + # modules from. By default, all +app+, +lib+, +vendor+ and mock paths are + # included in this list. + attr_accessor :autoload_paths + # The log level to use for the default Rails logger. In production mode, # this defaults to :info. In development mode, it defaults to # :debug. @@ -443,6 +456,7 @@ module Rails def initialize self.frameworks = default_frameworks self.load_paths = default_load_paths + self.autoload_paths = default_autoload_paths self.log_path = default_log_path self.log_level = default_log_level self.view_path = default_view_path @@ -546,6 +560,33 @@ module Rails actionwebservice/lib ).map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) } end + + def default_autoload_paths + paths = [] + + # Add the app's controller directory + paths.concat(Dir["#{root_path}/app/controllers/"]) + + # Then model subdirectories. + # TODO: Don't include .rb models as load paths + paths.concat(Dir["#{root_path}/app/models/[_a-z]*"]) + paths.concat(Dir["#{root_path}/components/[_a-z]*"]) + + # Followed by the standard includes. + paths.concat %w( + app + app/models + app/controllers + app/helpers + app/services + app/apis + components + config + lib + ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) } + + paths.concat Dir["#{root_path}/vendor/plugins/*/lib/"] + end def default_log_path File.join(root_path, 'log', "#{environment}.log") diff --git a/railties/lib/webrick_server.rb b/railties/lib/webrick_server.rb index 8f4ddb11a3..984638c8cc 100644 --- a/railties/lib/webrick_server.rb +++ b/railties/lib/webrick_server.rb @@ -3,6 +3,7 @@ require 'webrick' require 'cgi' require 'stringio' +require 'dispatcher' include WEBrick -- cgit v1.2.3