mirror of https://github.com/rails/rails
lazily instantiate application subclasses
this means we can meaningfully override methods in the subclass
This commit is contained in:
parent
2090615d39
commit
d25fe31c40
|
@ -29,7 +29,13 @@ module Rails
|
|||
autoload :WelcomeController
|
||||
|
||||
class << self
|
||||
attr_accessor :application, :cache, :logger
|
||||
@application = @app_class = nil
|
||||
|
||||
attr_writer :application
|
||||
attr_accessor :app_class, :cache, :logger
|
||||
def application
|
||||
@application ||= (app_class.instance if app_class)
|
||||
end
|
||||
|
||||
delegate :initialize!, :initialized?, to: :application
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ module Rails
|
|||
class << self
|
||||
def inherited(base)
|
||||
super
|
||||
base.instance
|
||||
Rails.app_class = base
|
||||
end
|
||||
|
||||
# Makes the +new+ method public.
|
||||
|
@ -117,8 +117,6 @@ module Rails
|
|||
@railties = nil
|
||||
@message_verifiers = {}
|
||||
|
||||
Rails.application ||= self
|
||||
|
||||
add_lib_to_load_path!
|
||||
ActiveSupport.run_load_hooks(:before_configuration, self)
|
||||
|
||||
|
|
|
@ -11,4 +11,14 @@ class EngineTest < ActiveSupport::TestCase
|
|||
|
||||
assert !engine.routes?
|
||||
end
|
||||
|
||||
def test_application_can_be_subclassed
|
||||
klass = Class.new(Rails::Application) do
|
||||
attr_reader :hello
|
||||
def initialize
|
||||
@hello = "world"
|
||||
end
|
||||
end
|
||||
assert_equal "world", klass.instance.hello
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue