2010-01-23 16:30:17 -05:00
|
|
|
require 'rails/initializable'
|
|
|
|
require 'rails/configuration'
|
|
|
|
|
2009-12-31 16:11:54 -05:00
|
|
|
module Rails
|
|
|
|
class Railtie
|
2010-01-23 16:30:17 -05:00
|
|
|
autoload :Configurable, "rails/railtie/configurable"
|
|
|
|
autoload :Configuration, "rails/railtie/configuration"
|
2010-01-23 12:41:53 -05:00
|
|
|
|
2009-12-31 16:11:54 -05:00
|
|
|
include Initializable
|
|
|
|
|
2010-01-21 17:14:20 -05:00
|
|
|
ABSTRACT_RAILTIES = %w(Rails::Plugin Rails::Engine Rails::Application)
|
2009-12-31 16:11:54 -05:00
|
|
|
|
2010-01-21 17:14:20 -05:00
|
|
|
class << self
|
2010-01-23 12:41:53 -05:00
|
|
|
def subclasses
|
|
|
|
@subclasses ||= []
|
2010-01-21 17:14:20 -05:00
|
|
|
end
|
2009-12-31 16:11:54 -05:00
|
|
|
|
2010-01-21 17:14:20 -05:00
|
|
|
def inherited(base)
|
2010-01-23 12:41:53 -05:00
|
|
|
unless abstract_railtie?(base)
|
2010-01-26 08:58:00 -05:00
|
|
|
base.send(:include, self::Configurable)
|
2010-01-23 12:41:53 -05:00
|
|
|
subclasses << base
|
|
|
|
end
|
2010-01-21 17:14:20 -05:00
|
|
|
end
|
2009-12-31 16:11:54 -05:00
|
|
|
|
2010-01-24 06:23:21 -05:00
|
|
|
def railtie_name(railtie_name = nil)
|
|
|
|
@railtie_name ||= name.demodulize.underscore
|
|
|
|
@railtie_name = railtie_name if railtie_name
|
|
|
|
@railtie_name
|
2010-01-21 17:14:20 -05:00
|
|
|
end
|
2009-12-31 16:11:54 -05:00
|
|
|
|
2010-01-24 06:23:21 -05:00
|
|
|
def railtie_names
|
|
|
|
subclasses.map { |p| p.railtie_name }
|
2010-01-21 17:14:20 -05:00
|
|
|
end
|
2010-01-12 07:27:24 -05:00
|
|
|
|
2010-01-21 17:14:20 -05:00
|
|
|
def subscriber(subscriber)
|
2010-01-24 06:23:21 -05:00
|
|
|
Rails::Subscriber.add(railtie_name, subscriber)
|
2010-01-21 17:14:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def rake_tasks(&blk)
|
|
|
|
@rake_tasks ||= []
|
|
|
|
@rake_tasks << blk if blk
|
|
|
|
@rake_tasks
|
|
|
|
end
|
2009-12-31 16:11:54 -05:00
|
|
|
|
2010-01-21 17:14:20 -05:00
|
|
|
def generators(&blk)
|
|
|
|
@generators ||= []
|
|
|
|
@generators << blk if blk
|
|
|
|
@generators
|
|
|
|
end
|
2010-01-23 12:41:53 -05:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def abstract_railtie?(base)
|
|
|
|
ABSTRACT_RAILTIES.include?(base.name)
|
|
|
|
end
|
2010-01-19 12:43:09 -05:00
|
|
|
end
|
|
|
|
|
2009-12-31 16:11:54 -05:00
|
|
|
def rake_tasks
|
|
|
|
self.class.rake_tasks
|
|
|
|
end
|
|
|
|
|
2010-01-19 12:43:09 -05:00
|
|
|
def generators
|
|
|
|
self.class.generators
|
|
|
|
end
|
|
|
|
|
2009-12-31 16:11:54 -05:00
|
|
|
def load_tasks
|
|
|
|
rake_tasks.each { |blk| blk.call }
|
|
|
|
end
|
2010-01-19 12:43:09 -05:00
|
|
|
|
|
|
|
def load_generators
|
|
|
|
generators.each { |blk| blk.call }
|
|
|
|
end
|
2009-12-31 16:11:54 -05:00
|
|
|
end
|
|
|
|
end
|