2007-11-08 05:29:44 +00:00
|
|
|
module Rails
|
2010-01-23 16:51:48 +00:00
|
|
|
class Plugin < Engine
|
|
|
|
class << self
|
|
|
|
def inherited(base)
|
|
|
|
raise "You should not inherit from Rails::Plugin"
|
2009-12-31 21:11:54 +00:00
|
|
|
end
|
2009-12-16 06:07:12 +00:00
|
|
|
|
2010-01-23 16:51:48 +00:00
|
|
|
def config
|
|
|
|
raise "Plugins does not provide configuration at the class level"
|
2009-12-31 21:11:54 +00:00
|
|
|
end
|
2007-11-08 05:29:44 +00:00
|
|
|
|
2010-01-23 16:51:48 +00:00
|
|
|
def 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
|
|
|
|
end
|
|
|
|
end
|
2008-11-26 13:41:20 +00:00
|
|
|
|
2010-01-23 16:51:48 +00:00
|
|
|
plugins.sort_by do |p|
|
|
|
|
[list.index(p.name) || list.index(:all), p.name.to_s]
|
2008-06-08 18:04:04 +00:00
|
|
|
end
|
2009-11-03 01:19:03 +00:00
|
|
|
end
|
2009-12-31 21:11:54 +00:00
|
|
|
end
|
2009-11-03 01:19:03 +00:00
|
|
|
|
2010-01-23 16:51:48 +00:00
|
|
|
attr_reader :name, :path
|
|
|
|
|
|
|
|
def initialize(root)
|
|
|
|
@name = File.basename(root).to_sym
|
|
|
|
config.root = root
|
2009-12-31 21:11:54 +00:00
|
|
|
end
|
2008-03-27 18:37:53 +00:00
|
|
|
|
2010-01-23 16:51:48 +00:00
|
|
|
def config
|
|
|
|
@config ||= Engine::Configuration.new
|
2009-12-31 21:11:54 +00:00
|
|
|
end
|
2008-03-27 18:37:53 +00:00
|
|
|
|
2010-01-23 16:51:48 +00:00
|
|
|
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?(file)
|
2008-03-27 18:37:53 +00:00
|
|
|
end
|
|
|
|
end
|
2010-01-18 22:48:04 +00:00
|
|
|
end
|