diff options
author | Carl Lerche <carllerche@mac.com> | 2009-09-29 17:33:17 -0700 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2009-09-29 17:33:17 -0700 |
commit | c9d4529c9da7c8c8f1ba3c2ab55fb40154a25023 (patch) | |
tree | fd4e7f2189e0b26e413c15ff68f8df7e8da378ae | |
parent | d1a63b15e329a141e0e4cc3b01d6f348d1c25c0a (diff) | |
download | rails-c9d4529c9da7c8c8f1ba3c2ab55fb40154a25023.tar.gz rails-c9d4529c9da7c8c8f1ba3c2ab55fb40154a25023.tar.bz2 rails-c9d4529c9da7c8c8f1ba3c2ab55fb40154a25023.zip |
Change Rails::Application to a class that is inherited from.
This is still very experimental.
-rw-r--r-- | railties/lib/rails.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/application.rb | 16 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/config.ru | 7 | ||||
-rw-r--r-- | railties/lib/rails/initializer.rb | 25 | ||||
-rw-r--r-- | railties/test/application/load_test.rb | 6 |
5 files changed, 25 insertions, 30 deletions
diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 8c9bc799a4..43ece14a49 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -1,2 +1 @@ -require 'rails/application' require 'rails/initializer' diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index c70365e2f8..6139e20e95 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -1,10 +1,16 @@ module Rails class Application - attr_accessor :config - def self.load(environment_file) - environment = File.read(environment_file) - Object.class_eval(environment, environment_file) + def self.config + @config ||= Configuration.new + end + + def self.config=(config) + @config = config + end + + def config + self.class.config end def routes @@ -16,7 +22,7 @@ module Rails end def call(env) - @app ||= middleware.build(@routes) + @app ||= middleware.build(routes) @app.call(env) end end diff --git a/railties/lib/rails/generators/rails/app/templates/config.ru b/railties/lib/rails/generators/rails/app/templates/config.ru index 52a8a8e798..50ee033d44 100644 --- a/railties/lib/rails/generators/rails/app/templates/config.ru +++ b/railties/lib/rails/generators/rails/app/templates/config.ru @@ -1,8 +1,5 @@ -# Rack Dispatcher - -# Bootstrap rails -require ::File.dirname(__FILE__) + '/config/boot' # Require your environment file to bootstrap Rails +require ::File.dirname(__FILE__) + '/config/environment' # Dispatch the request -run Rails::Application.load(::File.dirname(__FILE__) + '/config/environment.rb') +run Rails.application.new diff --git a/railties/lib/rails/initializer.rb b/railties/lib/rails/initializer.rb index 382838f831..ddd0bb89a3 100644 --- a/railties/lib/rails/initializer.rb +++ b/railties/lib/rails/initializer.rb @@ -30,7 +30,7 @@ module Rails end def config - @@config + @@config || Configuration.new end alias configuration config @@ -96,15 +96,6 @@ module Rails else @initializers.each {|block| run_initializer(block) } end - - # HAX - # TODO: remove hax - unless initializer - app = Rails::Application.new - app.config = @config - - Rails.application = app - end end end @@ -113,10 +104,16 @@ module Rails end def self.run(initializer = nil, config = nil) - default.config = config if config - default.config ||= Configuration.new - yield default.config if block_given? - default.run(initializer) + # TODO: Clean this all up + if initializer + default.config = config + default.run(initializer) + else + Rails.application = Class.new(Application) + yield Rails.application.config if block_given? + default.config = Rails.application.config + default.run + end end end diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb index 079aa09460..5158abdbb4 100644 --- a/railties/test/application/load_test.rb +++ b/railties/test/application/load_test.rb @@ -40,11 +40,7 @@ module ApplicationTests test "Rails.application is available after config.ru has been racked up" do rackup - assert Rails.application.is_a?(Rails::Application) - end - - test "class_evaling config/environment.rb returns the application object" do - assert Rails::Application.load("#{app_path}/config/environment.rb").is_a?(Rails::Application) + assert Rails.application.new.is_a?(Rails::Application) end test "the config object is available on the application object" do |