Permalink
Browse files

Merge pull request #9791 from wangjohn/remove_configurable

Removing Railtie::Configurable and replacing it with class methods
  • Loading branch information...
2 parents feb44b9 + 81b7416 commit 8c3affeb76edf6cf887aa69e549f10895172f23b @rafaelfranca rafaelfranca committed Apr 29, 2013
View
@@ -1,3 +1,7 @@
-* No changes.
+* Rails::Railtie no longer forces the Rails::Configurable module on everything
+ that subclassess it. Instead, the methods from Rails::Configurable have been
+ moved to class methods in Railtie and the Railtie has been made abstract.
+
+ *John Wang*
Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/railties/CHANGELOG.md) for previous changes.
@@ -634,17 +634,17 @@ def load_seed
end
end
+ def routes? #:nodoc:
+ @routes
+ end
+
protected
def run_tasks_blocks(*) #:nodoc:
super
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
@@ -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,14 +120,14 @@ class Railtie
class << self
private :new
+ delegate :config, to: :instance
def subclasses
@subclasses ||= []
end
def inherited(base)
unless base.abstract_railtie?
- base.send(:include, Railtie::Configurable)
subclasses << base
end
end
@@ -166,14 +165,47 @@ def railtie_name(name = nil)
@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
@@ -416,11 +416,6 @@ def call(env)
boot_rails
end
- test "Rails::Engine itself does not respond to config" do
- boot_rails
- assert !Rails::Engine.respond_to?(:config)
- end
-
test "initializers are executed after application configuration initializers" do
@plugin.write "lib/bukkits.rb", <<-RUBY
module Bukkits
@@ -19,8 +19,8 @@ def app
@app ||= Rails.application
end
- test "Rails::Railtie itself does not respond to config" do
- assert !Rails::Railtie.respond_to?(:config)
+ test "cannot instantiate a Railtie object" do
+ assert_raise(RuntimeError) { Rails::Railtie.new }
end
test "Railtie provides railtie_name" do
@@ -39,13 +39,6 @@ class Foo < Rails::Railtie
assert_equal "bar", Foo.railtie_name
end
- test "cannot inherit from a railtie" do
- class Foo < Rails::Railtie ; end
- assert_raise RuntimeError do
- class Bar < Foo; end
- end
- end
-
test "config is available to railtie" do
class Foo < Rails::Railtie ; end
assert_nil Foo.config.action_controller.foo

0 comments on commit 8c3affe

Please sign in to comment.