aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorwangjohn <wangjohn@mit.edu>2013-03-18 22:12:35 -0400
committerwangjohn <wangjohn@mit.edu>2013-04-29 13:06:29 -0400
commit81b7416afa10934022ad8b1b486419d5a4ed1349 (patch)
treeb14a238e23708d566a3a8cab1cab63682d3706c0 /railties/lib
parentfeb44b9213c91db22648ca0bb91bb6658c531df5 (diff)
downloadrails-81b7416afa10934022ad8b1b486419d5a4ed1349.tar.gz
rails-81b7416afa10934022ad8b1b486419d5a4ed1349.tar.bz2
rails-81b7416afa10934022ad8b1b486419d5a4ed1349.zip
Removing Railtie::Configurable from the base Railtie object and making
Railtie itself abstract. This stops the weird behavior of forcing subclasses of Railtie to include the Configurable module.
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/engine.rb8
-rw-r--r--railties/lib/rails/railtie.rb36
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