aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/plugin.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/plugin.rb')
-rw-r--r--railties/lib/rails/plugin.rb60
1 files changed, 17 insertions, 43 deletions
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb
index c3b81bcd3e..394e634903 100644
--- a/railties/lib/rails/plugin.rb
+++ b/railties/lib/rails/plugin.rb
@@ -1,5 +1,13 @@
+require 'rails/engine'
+
module Rails
- class Plugin < Railtie
+ class Plugin < Engine
+ def self.inherited(base)
+ raise "You cannot inherit from Rails::Plugin"
+ end
+
+ # TODO Right now, if a plugin has an Engine or a Railtie inside it,
+ # the initializers for this plugin will be executed twice.
def self.all(list, paths)
plugins = []
paths.each do |path|
@@ -17,53 +25,19 @@ module Rails
attr_reader :name, :path
- def initialize(path)
- @name = File.basename(path).to_sym
- @path = path
- end
-
- def load_paths
- Dir["#{path}/{lib}", "#{path}/app/{models,controllers,helpers}"]
+ def initialize(root)
+ @name = File.basename(root).to_sym
+ config.root = root
end
- def load_tasks
- Dir["#{path}/{tasks,lib/tasks,rails/tasks}/**/*.rake"].sort.each { |ext| load ext }
+ def config
+ @config ||= Engine::Configuration.new
end
- initializer :add_to_load_path, :after => :set_autoload_paths do |app|
- load_paths.each do |path|
- $LOAD_PATH << path
- require "active_support/dependencies"
-
- ActiveSupport::Dependencies.load_paths << path
-
- unless app.config.reload_plugins
- ActiveSupport::Dependencies.load_once_paths << path
- end
- end
- end
-
- initializer :load_init_rb, :before => :load_application_initializers do |app|
- file = "#{@path}/init.rb"
+ initializer :load_init_rb do |app|
+ file = Dir["#{root}/{rails/init,init}.rb"].first
config = app.config
- eval File.read(file), binding, file if File.file?(file)
- end
-
- initializer :add_view_paths, :after => :initialize_framework_views do
- plugin_views = "#{path}/app/views"
- if File.directory?(plugin_views)
- ActionController::Base.view_paths.concat([plugin_views]) if defined? ActionController
- ActionMailer::Base.view_paths.concat([plugin_views]) if defined? ActionMailer
- end
- end
-
- # TODO Isn't it supposed to be :after => "action_controller.initialize_routing" ?
- initializer :add_routing_file, :after => :initialize_routing do |app|
- routing_file = "#{path}/config/routes.rb"
- if File.exist?(routing_file)
- app.route_configuration_files << routing_file
- app.reload_routes!
- end
+ eval(File.read(file), binding, file) if file && File.file?(file)
end
end
end