diff options
author | Gonçalo Silva <goncalossilva@gmail.com> | 2011-03-24 17:21:17 +0000 |
---|---|---|
committer | Gonçalo Silva <goncalossilva@gmail.com> | 2011-03-24 17:21:17 +0000 |
commit | 9887f238871bb2dd73de6ce8855615bcc5d8d079 (patch) | |
tree | 74fa9ff9524a51701cfa23f708b3f777c65b7fe5 /railties/lib/rails/plugin.rb | |
parent | aff821508a16245ebc03510ba29c70379718dfb7 (diff) | |
parent | 5214e73850916de3c9127d35a4ecee0424d364a3 (diff) | |
download | rails-9887f238871bb2dd73de6ce8855615bcc5d8d079.tar.gz rails-9887f238871bb2dd73de6ce8855615bcc5d8d079.tar.bz2 rails-9887f238871bb2dd73de6ce8855615bcc5d8d079.zip |
Merge branch 'master' of https://github.com/rails/rails
Diffstat (limited to 'railties/lib/rails/plugin.rb')
-rw-r--r-- | railties/lib/rails/plugin.rb | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index be229cc9a2..ceddd25eaa 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -16,8 +16,12 @@ module Rails # Besides this conceptual difference, the only difference between Rails::Engine and # Rails::Plugin is that plugins automatically load the file "init.rb" at the plugin # root during the boot process. - # + # class Plugin < Engine + def self.global_plugins + @global_plugins ||= [] + end + def self.inherited(base) raise "You cannot inherit from Rails::Plugin" end @@ -28,6 +32,11 @@ module Rails Dir["#{path}/*"].each do |plugin_path| plugin = new(plugin_path) next unless list.include?(plugin.name) || list.include?(:all) + if global_plugins.include?(plugin.name) + warn "WARNING: plugin #{plugin.name} from #{path} was not loaded. Plugin with the same name has been already loaded." + next + end + global_plugins << plugin.name plugins << plugin end end @@ -39,17 +48,8 @@ module Rails attr_reader :name, :path - def load_tasks - super - load_deprecated_tasks - end - - def load_deprecated_tasks - tasks = Dir["#{root}/{tasks,rails/tasks}/**/*.rake"].sort - if tasks.any? - ActiveSupport::Deprecation.warn "Rake tasks in #{tasks.to_sentence} are deprecated. Use lib/tasks instead" - tasks.each { |ext| load(ext) } - end + def railtie_name + name.to_s end def initialize(root) @@ -62,29 +62,28 @@ module Rails end initializer :handle_lib_autoload, :before => :set_load_path do |app| - paths = if app.config.reload_plugins + autoload = if app.config.reload_plugins config.autoload_paths else config.autoload_once_paths end - paths.concat config.paths.lib.to_a + autoload.concat paths["lib"].existent end initializer :load_init_rb, :before => :load_config_initializers do |app| - files = %w(rails/init.rb init.rb).map { |path| File.expand_path path, root } - if initrb = files.find { |path| File.file? path } - if initrb == files.first - ActiveSupport::Deprecation.warn "Use toplevel init.rb; rails/init.rb is deprecated: #{initrb}" - end + init_rb = File.expand_path("init.rb", root) + if File.file?(init_rb) config = app.config - eval(File.read(initrb), binding, initrb) + # TODO: think about evaling initrb in context of Engine (currently it's + # always evaled in context of Rails::Application) + eval(File.read(init_rb), binding, init_rb) end end initializer :sanity_check_railties_collision do if Engine.subclasses.map { |k| k.root.to_s }.include?(root.to_s) - raise "\"#{name}\" is a Railtie/Engine and cannot be installed as plugin" + raise "\"#{name}\" is a Railtie/Engine and cannot be installed as a plugin" end end end |