diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-04-29 11:19:14 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-04-29 11:19:14 -0700 |
commit | 8c3affeb76edf6cf887aa69e549f10895172f23b (patch) | |
tree | b14a238e23708d566a3a8cab1cab63682d3706c0 /railties/lib | |
parent | feb44b9213c91db22648ca0bb91bb6658c531df5 (diff) | |
parent | 81b7416afa10934022ad8b1b486419d5a4ed1349 (diff) | |
download | rails-8c3affeb76edf6cf887aa69e549f10895172f23b.tar.gz rails-8c3affeb76edf6cf887aa69e549f10895172f23b.tar.bz2 rails-8c3affeb76edf6cf887aa69e549f10895172f23b.zip |
Merge pull request #9791 from wangjohn/remove_configurable
Removing Railtie::Configurable and replacing it with class methods
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/engine.rb | 8 | ||||
-rw-r--r-- | railties/lib/rails/railtie.rb | 36 |
2 files changed, 38 insertions, 6 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 86f62dfb40..94edcd352a 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -634,6 +634,10 @@ module Rails end end + def routes? #:nodoc: + @routes + end + protected def run_tasks_blocks(*) #:nodoc: @@ -641,10 +645,6 @@ module Rails paths["lib/tasks"].existent.sort.each { |ext| load(ext) } end - def routes? #:nodoc: - @routes - end - def has_migrations? #:nodoc: paths["db/migrate"].existent.any? end diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 9437e9c406..2b6ad1ff2d 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -112,7 +112,6 @@ module Rails # Be sure to look at the documentation of those specific classes for more information. # class Railtie - autoload :Configurable, "rails/railtie/configurable" autoload :Configuration, "rails/railtie/configuration" include Initializable @@ -121,6 +120,7 @@ module Rails class << self private :new + delegate :config, to: :instance def subclasses @subclasses ||= [] @@ -128,7 +128,6 @@ module Rails def inherited(base) unless base.abstract_railtie? - base.send(:include, Railtie::Configurable) subclasses << base end end @@ -166,14 +165,47 @@ module Rails @railtie_name ||= generate_railtie_name(self.name) end + # Since Rails::Railtie cannot be instantiated, any methods that call + # +instance+ are intended to be called only on subclasses of a Railtie. + def instance + @instance ||= new + end + + def respond_to_missing?(*args) + instance.respond_to?(*args) || super + end + + # Allows you to configure the railtie. This is the same method seen in + # Railtie::Configurable, but this module is no longer required for all + # subclasses of Railtie so we provide the class method here. + def configure(&block) + class_eval(&block) + end + protected def generate_railtie_name(class_or_module) ActiveSupport::Inflector.underscore(class_or_module).tr("/", "_") end + + # If the class method does not have a method, then send the method call + # to the Railtie instance. + def method_missing(name, *args, &block) + if instance.respond_to?(name) + instance.public_send(name, *args, &block) + else + super + end + end end delegate :railtie_name, to: :class + def initialize + if self.class.abstract_railtie? + raise "#{self.class.name} is abstract, you cannot instantiate it directly." + end + end + def config @config ||= Railtie::Configuration.new end |