rails--rails/railties/lib/rails/plugin.rb

46 lines
1.1 KiB
Ruby
Raw Normal View History

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"
end
2010-01-23 16:51:48 +00:00
def config
raise "Plugins does not provide configuration at the class level"
end
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
2010-01-23 16:51:48 +00:00
plugins.sort_by do |p|
[list.index(p.name) || list.index(:all), p.name.to_s]
end
end
end
2010-01-23 16:51:48 +00:00
attr_reader :name, :path
def initialize(root)
@name = File.basename(root).to_sym
config.root = root
end
2010-01-23 16:51:48 +00:00
def config
@config ||= Engine::Configuration.new
end
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)
end
end
end