From cc2d6a0b93251fce06bab15c52dbe0a5d5a8342c Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Mon, 31 Mar 2008 06:53:44 +0000 Subject: Allow files in plugins to be reloaded like the rest of the application. [rick] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9167 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/lib/initializer.rb | 16 ++++++++++++++++ railties/lib/rails/plugin/loader.rb | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 20e1f01926..40c2ad90cb 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -516,6 +516,22 @@ module Rails # a sub class would have access to fine grained modification of the loading behavior. See # the implementation of Rails::Plugin::Loader for more details. attr_accessor :plugin_loader + + # Enables or disables plugin reloading. You can get around this setting per plugin. + # If #reload_plugins? == false, add this to your plugin's init.rb to make it reloadable: + # + # Dependencies.load_once_paths.delete lib_path + # + # If #reload_plugins? == true, add this to your plugin's init.rb to only load it once: + # + # Dependencies.load_once_paths << lib_path + # + attr_accessor :reload_plugins + + # Returns true if plugin reloading is enabled. + def reload_plugins? + !!@reload_plugins + end # An array of gems that this rails application depends on. Rails will automatically load # these gems during installation, and allow you to install any missing gems with: diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index 438afa4d32..1e542dd038 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -46,7 +46,9 @@ module Rails plugin.load_paths.each do |path| $LOAD_PATH.insert(application_lib_index + 1, path) Dependencies.load_paths << path - Dependencies.load_once_paths << path + unless Rails.configuration.reload_plugins? + Dependencies.load_once_paths << path + end end end $LOAD_PATH.uniq! -- cgit v1.2.3