2010-01-23 16:30:17 -05:00
|
|
|
require 'rails/engine'
|
|
|
|
|
2007-11-08 00:29:44 -05:00
|
|
|
module Rails
|
2010-01-23 11:51:48 -05:00
|
|
|
class Plugin < Engine
|
2010-01-23 12:41:53 -05:00
|
|
|
def self.inherited(base)
|
|
|
|
raise "You cannot inherit from Rails::Plugin"
|
|
|
|
end
|
2007-11-08 00:29:44 -05:00
|
|
|
|
2010-01-23 12:41:53 -05:00
|
|
|
def self.all(list, paths)
|
|
|
|
plugins = []
|
|
|
|
paths.each do |path|
|
|
|
|
Dir["#{path}/*"].each do |plugin_path|
|
|
|
|
plugin = new(plugin_path)
|
|
|
|
next unless list.include?(plugin.name) || list.include?(:all)
|
|
|
|
plugins << plugin
|
2010-01-23 11:51:48 -05:00
|
|
|
end
|
2010-01-23 12:41:53 -05:00
|
|
|
end
|
2008-11-26 08:41:20 -05:00
|
|
|
|
2010-01-23 12:41:53 -05:00
|
|
|
plugins.sort_by do |p|
|
|
|
|
[list.index(p.name) || list.index(:all), p.name.to_s]
|
2009-11-02 20:19:03 -05:00
|
|
|
end
|
2009-12-31 16:11:54 -05:00
|
|
|
end
|
2009-11-02 20:19:03 -05:00
|
|
|
|
2010-01-23 11:51:48 -05:00
|
|
|
attr_reader :name, :path
|
|
|
|
|
2010-01-24 03:47:55 -05:00
|
|
|
def load_tasks
|
|
|
|
super
|
|
|
|
extra_tasks = Dir["#{root}/{tasks,rails/tasks}/**/*.rake"]
|
|
|
|
|
|
|
|
unless extra_tasks.empty?
|
|
|
|
ActiveSupport::Deprecation.warn "Having rake tasks in PLUGIN_PATH/tasks or " <<
|
|
|
|
"PLUGIN_PATH/rails/tasks is deprecated. Use to PLUGIN_PATH/lib/tasks instead"
|
|
|
|
extra_tasks.sort.each { |ext| load(ext) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-23 11:51:48 -05:00
|
|
|
def initialize(root)
|
|
|
|
@name = File.basename(root).to_sym
|
|
|
|
config.root = root
|
2009-12-31 16:11:54 -05:00
|
|
|
end
|
2008-03-27 14:37:53 -04:00
|
|
|
|
2010-01-23 11:51:48 -05:00
|
|
|
def config
|
|
|
|
@config ||= Engine::Configuration.new
|
2009-12-31 16:11:54 -05:00
|
|
|
end
|
2008-03-27 14:37:53 -04:00
|
|
|
|
2010-01-27 01:08:50 -05:00
|
|
|
initializer :load_init_rb, :before => :load_application_initializers do |app|
|
2010-01-23 11:51:48 -05:00
|
|
|
file = Dir["#{root}/{rails/init,init}.rb"].first
|
|
|
|
config = app.config
|
|
|
|
eval(File.read(file), binding, file) if file && File.file?(file)
|
2008-03-27 14:37:53 -04:00
|
|
|
end
|
2010-01-24 03:00:18 -05:00
|
|
|
|
|
|
|
initializer :sanity_check_railties_collision do
|
|
|
|
if Engine.subclasses.map { |k| k.root.to_s }.include?(root.to_s)
|
2010-01-24 06:49:12 -05:00
|
|
|
raise "\"#{name}\" is a Railtie/Engine and cannot be installed as plugin"
|
2010-01-24 03:00:18 -05:00
|
|
|
end
|
|
|
|
end
|
2010-01-27 12:56:31 -05:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def reloadable?(app)
|
|
|
|
app.config.reload_plugins
|
|
|
|
end
|
2008-03-27 14:37:53 -04:00
|
|
|
end
|
2010-01-18 17:48:04 -05:00
|
|
|
end
|