From 788fce2550ed587d86d239d8fcd488f919d15b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 18:41:53 +0100 Subject: Create configurable modules and ensure that they are added only on direct children. --- railties/lib/rails/railtie.rb | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'railties/lib/rails/railtie.rb') diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 84f7a86946..208b017348 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -1,19 +1,21 @@ module Rails class Railtie + autoload :Configurable, "rails/railtie/configurable" + include Initializable ABSTRACT_RAILTIES = %w(Rails::Plugin Rails::Engine Rails::Application) class << self - attr_reader :subclasses - - def abstract_railtie?(base) - ABSTRACT_RAILTIES.include?(base.name) + def subclasses + @subclasses ||= [] end def inherited(base) - @subclasses ||= [] - @subclasses << base unless abstract_railtie?(base) + unless abstract_railtie?(base) + base.send(:include, self::Configurable) if add_configurable?(base) + subclasses << base + end end # TODO This should be called railtie_name and engine_name @@ -25,7 +27,7 @@ module Rails # TODO Deprecate me def plugins - @subclasses + subclasses end # TODO Deprecate me @@ -33,10 +35,6 @@ module Rails plugins.map { |p| p.plugin_name } end - def config - Configuration.default - end - def subscriber(subscriber) Rails::Subscriber.add(plugin_name, subscriber) end @@ -52,6 +50,20 @@ module Rails @generators << blk if blk @generators end + + protected + + def abstract_railtie?(base) + ABSTRACT_RAILTIES.include?(base.name) + end + + # Just add configurable behavior if a Configurable module is defined + # and the class is a direct child from self. This is required to avoid + # application or plugins getting class configuration method from Railties + # and/or Engines. + def add_configurable?(base) + defined?(self::Configurable) && base.ancestors[1] == self + end end def rake_tasks -- cgit v1.2.3