提交 9703d670 编写于 作者: W wangjohn

Removing the app constant and replacing it with Rails.application

syntax. This helps removing the class level abstraction of an
application.
上级 68937056
...@@ -124,7 +124,7 @@ module Rails ...@@ -124,7 +124,7 @@ module Rails
# #
# Now you can mount your engine in application's routes just like that: # Now you can mount your engine in application's routes just like that:
# #
# MyRailsApp::Application.routes.draw do # Rails.application.routes.draw do
# mount MyEngine::Engine => "/engine" # mount MyEngine::Engine => "/engine"
# end # end
# #
...@@ -154,7 +154,7 @@ module Rails ...@@ -154,7 +154,7 @@ module Rails
# Note that now there can be more than one router in your application, and it's better to avoid # Note that now there can be more than one router in your application, and it's better to avoid
# passing requests through many routers. Consider this situation: # passing requests through many routers. Consider this situation:
# #
# MyRailsApp::Application.routes.draw do # Rails.application.routes.draw do
# mount MyEngine::Engine => "/blog" # mount MyEngine::Engine => "/blog"
# get "/blog/omg" => "main#omg" # get "/blog/omg" => "main#omg"
# end # end
...@@ -164,7 +164,7 @@ module Rails ...@@ -164,7 +164,7 @@ module Rails
# and if there is no such route in +Engine+'s routes, it will be dispatched to <tt>main#omg</tt>. # and if there is no such route in +Engine+'s routes, it will be dispatched to <tt>main#omg</tt>.
# It's much better to swap that: # It's much better to swap that:
# #
# MyRailsApp::Application.routes.draw do # Rails.application.routes.draw do
# get "/blog/omg" => "main#omg" # get "/blog/omg" => "main#omg"
# mount MyEngine::Engine => "/blog" # mount MyEngine::Engine => "/blog"
# end # end
...@@ -251,7 +251,7 @@ module Rails ...@@ -251,7 +251,7 @@ module Rails
# created to allow you to do that. Consider such a scenario: # created to allow you to do that. Consider such a scenario:
# #
# # config/routes.rb # # config/routes.rb
# MyApplication::Application.routes.draw do # Rails.application.routes.draw do
# mount MyEngine::Engine => "/my_engine", as: "my_engine" # mount MyEngine::Engine => "/my_engine", as: "my_engine"
# get "/foo" => "foo#index" # get "/foo" => "foo#index"
# end # end
......
...@@ -86,7 +86,7 @@ def add_source(source, options={}) ...@@ -86,7 +86,7 @@ def add_source(source, options={})
# end # end
def environment(data=nil, options={}, &block) def environment(data=nil, options={}, &block)
sentinel = /class [a-z_:]+ < Rails::Application/i sentinel = /class [a-z_:]+ < Rails::Application/i
env_file_sentinel = /::Application\.configure do/ env_file_sentinel = /Rails\.application\.configure do/
data = block.call if !data && block_given? data = block.call if !data && block_given?
in_root do in_root do
......
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
require File.expand_path('../config/application', __FILE__) require File.expand_path('../config/application', __FILE__)
<%= app_const %>.load_tasks Rails.application.load_tasks
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
require File.expand_path('../application', __FILE__) require File.expand_path('../application', __FILE__)
# Initialize the rails application. # Initialize the rails application.
<%= app_const %>.initialize! Rails.application.initialize!
<%= app_const %>.configure do Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb. # Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on # In the development environment your application's code is reloaded on
......
<%= app_const %>.configure do Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb. # Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests. # Code is not reloaded between requests.
......
<%= app_const %>.configure do Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb. # Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's # The test environment is used exclusively to run your application's
......
...@@ -9,4 +9,4 @@ ...@@ -9,4 +9,4 @@
# Make sure your secret_key_base is kept private # Make sure your secret_key_base is kept private
# if you're sharing your code publicly. # if you're sharing your code publicly.
<%= app_const %>.config.secret_key_base = '<%= app_secret %>' Rails.application.config.secret_key_base = '<%= app_secret %>'
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
<%= app_const %>.config.session_store :cookie_store, key: <%= "'_#{app_name}_session'" %> Rails.application.config.session_store :cookie_store, key: <%= "'_#{app_name}_session'" %>
<%= app_const %>.routes.draw do Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority. # The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes". # See how all your routes lay out with "rake routes".
......
...@@ -179,7 +179,7 @@ def respond_to_missing?(*args) ...@@ -179,7 +179,7 @@ def respond_to_missing?(*args)
# Railtie::Configurable, but this module is no longer required for all # Railtie::Configurable, but this module is no longer required for all
# subclasses of Railtie so we provide the class method here. # subclasses of Railtie so we provide the class method here.
def configure(&block) def configure(&block)
class_eval(&block) instance.configure(&block)
end end
protected protected
...@@ -206,6 +206,10 @@ def initialize ...@@ -206,6 +206,10 @@ def initialize
end end
end end
def configure(&block)
instance_eval(&block)
end
def config def config
@config ||= Railtie::Configuration.new @config ||= Railtie::Configuration.new
end end
......
...@@ -103,7 +103,7 @@ def test_environment_should_include_data_in_environment_initializer_block_with_e ...@@ -103,7 +103,7 @@ def test_environment_should_include_data_in_environment_initializer_block_with_e
run_generator run_generator
autoload_paths = 'config.autoload_paths += %w["#{Rails.root}/app/extras"]' autoload_paths = 'config.autoload_paths += %w["#{Rails.root}/app/extras"]'
action :environment, autoload_paths, env: 'development' action :environment, autoload_paths, env: 'development'
assert_file "config/environments/development.rb", /Application\.configure do\n #{Regexp.escape(autoload_paths)}/ assert_file "config/environments/development.rb", /Rails\.application\.configure do\n #{Regexp.escape(autoload_paths)}/
end end
def test_environment_with_block_should_include_block_contents_in_environment_initializer_block def test_environment_with_block_should_include_block_contents_in_environment_initializer_block
......
...@@ -65,7 +65,7 @@ def test_invalid_application_name_raises_an_error ...@@ -65,7 +65,7 @@ def test_invalid_application_name_raises_an_error
def test_invalid_application_name_is_fixed def test_invalid_application_name_is_fixed
run_generator [File.join(destination_root, "things-43")] run_generator [File.join(destination_root, "things-43")]
assert_file "things-43/config/environment.rb", /Things43::Application\.initialize!/ assert_file "things-43/config/environment.rb", /Rails\.application\.initialize!/
assert_file "things-43/config/application.rb", /^module Things43$/ assert_file "things-43/config/application.rb", /^module Things43$/
end end
...@@ -111,7 +111,7 @@ def test_application_name_is_detected_if_it_exists_and_app_folder_renamed ...@@ -111,7 +111,7 @@ def test_application_name_is_detected_if_it_exists_and_app_folder_renamed
destination_root: app_moved_root, shell: @shell destination_root: app_moved_root, shell: @shell
generator.send(:app_const) generator.send(:app_const)
quietly { generator.send(:create_config_files) } quietly { generator.send(:create_config_files) }
assert_file "myapp_moved/config/environment.rb", /Myapp::Application\.initialize!/ assert_file "myapp_moved/config/environment.rb", /Rails\.application\.initialize!/
assert_file "myapp_moved/config/initializers/session_store.rb", /_myapp_session/ assert_file "myapp_moved/config/initializers/session_store.rb", /_myapp_session/
end end
...@@ -131,7 +131,7 @@ def test_rails_update_generates_correct_session_key ...@@ -131,7 +131,7 @@ def test_rails_update_generates_correct_session_key
def test_application_names_are_not_singularized def test_application_names_are_not_singularized
run_generator [File.join(destination_root, "hats")] run_generator [File.join(destination_root, "hats")]
assert_file "hats/config/environment.rb", /Hats::Application\.initialize!/ assert_file "hats/config/environment.rb", /Rails\.application\.initialize!/
end end
def test_gemfile_has_no_whitespace_errors def test_gemfile_has_no_whitespace_errors
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册