mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Removing the app constant and replacing it with Rails.application
syntax. This helps removing the class level abstraction of an application.
This commit is contained in:
parent
689370568f
commit
9703d67048
13 changed files with 22 additions and 18 deletions
|
@ -124,7 +124,7 @@ module Rails
|
|||
#
|
||||
# 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"
|
||||
# end
|
||||
#
|
||||
|
@ -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
|
||||
# passing requests through many routers. Consider this situation:
|
||||
#
|
||||
# MyRailsApp::Application.routes.draw do
|
||||
# Rails.application.routes.draw do
|
||||
# mount MyEngine::Engine => "/blog"
|
||||
# get "/blog/omg" => "main#omg"
|
||||
# end
|
||||
|
@ -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>.
|
||||
# It's much better to swap that:
|
||||
#
|
||||
# MyRailsApp::Application.routes.draw do
|
||||
# Rails.application.routes.draw do
|
||||
# get "/blog/omg" => "main#omg"
|
||||
# mount MyEngine::Engine => "/blog"
|
||||
# end
|
||||
|
@ -251,7 +251,7 @@ module Rails
|
|||
# created to allow you to do that. Consider such a scenario:
|
||||
#
|
||||
# # config/routes.rb
|
||||
# MyApplication::Application.routes.draw do
|
||||
# Rails.application.routes.draw do
|
||||
# mount MyEngine::Engine => "/my_engine", as: "my_engine"
|
||||
# get "/foo" => "foo#index"
|
||||
# end
|
||||
|
|
|
@ -86,7 +86,7 @@ module Rails
|
|||
# end
|
||||
def environment(data=nil, options={}, &block)
|
||||
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?
|
||||
|
||||
in_root do
|
||||
|
|
|
@ -3,4 +3,4 @@
|
|||
|
||||
require File.expand_path('../config/application', __FILE__)
|
||||
|
||||
<%= app_const %>.load_tasks
|
||||
Rails.application.load_tasks
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
require File.expand_path('../application', __FILE__)
|
||||
|
||||
# Initialize the rails application.
|
||||
<%= app_const %>.initialize!
|
||||
Rails.application.initialize!
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<%= app_const %>.configure do
|
||||
Rails.application.configure do
|
||||
# Settings specified here will take precedence over those in config/application.rb.
|
||||
|
||||
# In the development environment your application's code is reloaded on
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<%= app_const %>.configure do
|
||||
Rails.application.configure do
|
||||
# Settings specified here will take precedence over those in config/application.rb.
|
||||
|
||||
# Code is not reloaded between requests.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<%= app_const %>.configure do
|
||||
Rails.application.configure do
|
||||
# Settings specified here will take precedence over those in config/application.rb.
|
||||
|
||||
# The test environment is used exclusively to run your application's
|
||||
|
|
|
@ -9,4 +9,4 @@
|
|||
|
||||
# Make sure your secret_key_base is kept private
|
||||
# if you're sharing your code publicly.
|
||||
<%= app_const %>.config.secret_key_base = '<%= app_secret %>'
|
||||
Rails.application.config.secret_key_base = '<%= app_secret %>'
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
# 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'" %>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<%= app_const %>.routes.draw do
|
||||
Rails.application.routes.draw do
|
||||
# The priority is based upon order of creation: first created -> highest priority.
|
||||
# See how all your routes lay out with "rake routes".
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ module Rails
|
|||
# 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)
|
||||
instance.configure(&block)
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -206,6 +206,10 @@ module Rails
|
|||
end
|
||||
end
|
||||
|
||||
def configure(&block)
|
||||
instance_eval(&block)
|
||||
end
|
||||
|
||||
def config
|
||||
@config ||= Railtie::Configuration.new
|
||||
end
|
||||
|
|
|
@ -103,7 +103,7 @@ class ActionsTest < Rails::Generators::TestCase
|
|||
run_generator
|
||||
autoload_paths = 'config.autoload_paths += %w["#{Rails.root}/app/extras"]'
|
||||
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
|
||||
|
||||
def test_environment_with_block_should_include_block_contents_in_environment_initializer_block
|
||||
|
|
|
@ -65,7 +65,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
|
||||
def test_invalid_application_name_is_fixed
|
||||
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$/
|
||||
end
|
||||
|
||||
|
@ -111,7 +111,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
destination_root: app_moved_root, shell: @shell
|
||||
generator.send(:app_const)
|
||||
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/
|
||||
end
|
||||
|
||||
|
@ -131,7 +131,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
|
||||
def test_application_names_are_not_singularized
|
||||
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
|
||||
|
||||
def test_gemfile_has_no_whitespace_errors
|
||||
|
|
Loading…
Reference in a new issue