aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/application
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/application')
-rw-r--r--railties/lib/rails/application/bootstrap.rb10
-rw-r--r--railties/lib/rails/application/configuration.rb50
-rw-r--r--railties/lib/rails/application/default_middleware_stack.rb6
-rw-r--r--railties/lib/rails/application/finisher.rb27
4 files changed, 58 insertions, 35 deletions
diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb
index f615f22b26..11da271501 100644
--- a/railties/lib/rails/application/bootstrap.rb
+++ b/railties/lib/rails/application/bootstrap.rb
@@ -1,7 +1,7 @@
-require 'fileutils'
-require 'active_support/notifications'
-require 'active_support/dependencies'
-require 'active_support/descendants_tracker'
+require "fileutils"
+require "active_support/notifications"
+require "active_support/dependencies"
+require "active_support/descendants_tracker"
module Rails
class Application
@@ -36,7 +36,7 @@ INFO
FileUtils.mkdir_p File.dirname path
end
- f = File.open path, 'a'
+ f = File.open path, "a"
f.binmode
f.sync = config.autoflush_log # if true make sure every write flushes
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index f415a20833..810750ed35 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -1,10 +1,10 @@
-require 'active_support/core_ext/kernel/reporting'
-require 'active_support/file_update_checker'
-require 'rails/engine/configuration'
-require 'rails/source_annotation_extractor'
+require "active_support/core_ext/kernel/reporting"
+require "active_support/file_update_checker"
+require "rails/engine/configuration"
+require "rails/source_annotation_extractor"
-require 'active_support/deprecation'
-require 'active_support/core_ext/string/strip' # for strip_heredoc
+require "active_support/deprecation"
+require "active_support/core_ext/string/strip" # for strip_heredoc
module Rails
class Application
@@ -16,7 +16,7 @@ module Rails
:railties_order, :relative_url_root, :secret_key_base, :secret_token,
:ssl_options, :public_file_server,
:session_options, :time_zone, :reload_classes_only_on_change,
- :beginning_of_week, :filter_redirect, :x
+ :beginning_of_week, :filter_redirect, :x, :enable_dependency_loading
attr_writer :log_level
attr_reader :encoding, :api_only, :static_cache_control
@@ -34,8 +34,7 @@ module Rails
@public_file_server.index_name = "index"
@force_ssl = false
@ssl_options = {}
- @session_store = :cookie_store
- @session_options = {}
+ @session_store = nil
@time_zone = "UTC"
@beginning_of_week = :monday
@log_level = nil
@@ -54,6 +53,7 @@ module Rails
@api_only = false
@debug_exception_response_format = nil
@x = Custom.new
+ @enable_dependency_loading = false
end
def static_cache_control=(value)
@@ -134,7 +134,7 @@ module Rails
require "yaml"
require "erb"
YAML.load(ERB.new(yaml.read).result) || {}
- elsif ENV['DATABASE_URL']
+ elsif ENV["DATABASE_URL"]
# Value from ENV['DATABASE_URL'] is set to default database connection
# by Active Record.
{}
@@ -164,29 +164,37 @@ module Rails
self.generators.colorize_logging = val
end
- def session_store(*args)
- if args.empty?
- case @session_store
- when :disabled
- nil
- when :active_record_store
+ def session_store(new_session_store = nil, **options)
+ if new_session_store
+ if new_session_store == :active_record_store
begin
ActionDispatch::Session::ActiveRecordStore
rescue NameError
raise "`ActiveRecord::SessionStore` is extracted out of Rails into a gem. " \
"Please add `activerecord-session_store` to your Gemfile to use it."
end
+ end
+
+ @session_store = new_session_store
+ @session_options = options || {}
+ else
+ case @session_store
+ when :disabled
+ nil
+ when :active_record_store
+ ActionDispatch::Session::ActiveRecordStore
when Symbol
ActionDispatch::Session.const_get(@session_store.to_s.camelize)
else
@session_store
end
- else
- @session_store = args.shift
- @session_options = args.shift || {}
end
end
+ def session_store? #:nodoc:
+ @session_store
+ end
+
def annotations
SourceAnnotationExtractor::Annotation
end
@@ -205,6 +213,10 @@ module Rails
}
end
end
+
+ def respond_to_missing?(symbol, *)
+ true
+ end
end
end
end
diff --git a/railties/lib/rails/application/default_middleware_stack.rb b/railties/lib/rails/application/default_middleware_stack.rb
index 381e548730..14c0a8cbe4 100644
--- a/railties/lib/rails/application/default_middleware_stack.rb
+++ b/railties/lib/rails/application/default_middleware_stack.rb
@@ -19,7 +19,7 @@ module Rails
if config.public_file_server.enabled
headers = config.public_file_server.headers || {}
- headers['Cache-Control'.freeze] = config.static_cache_control if config.static_cache_control
+ headers["Cache-Control".freeze] = config.static_cache_control if config.static_cache_control
middleware.use ::ActionDispatch::Static, paths["public"].first, index: config.public_file_server.index_name, headers: headers
end
@@ -76,9 +76,9 @@ module Rails
return unless rack_cache
begin
- require 'rack/cache'
+ require "rack/cache"
rescue LoadError => error
- error.message << ' Be sure to add rack-cache to your Gemfile'
+ error.message << " Be sure to add rack-cache to your Gemfile"
raise
end
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb
index 0aed6c1351..a855e8fab0 100644
--- a/railties/lib/rails/application/finisher.rb
+++ b/railties/lib/rails/application/finisher.rb
@@ -21,15 +21,26 @@ module Rails
initializer :add_builtin_route do |app|
if Rails.env.development?
+ app.routes.prepend do
+ get "/rails/info/properties" => "rails/info#properties", internal: true
+ get "/rails/info/routes" => "rails/info#routes", internal: true
+ get "/rails/info" => "rails/info#index", internal: true
+ end
+
app.routes.append do
- get '/rails/info/properties' => "rails/info#properties", internal: true
- get '/rails/info/routes' => "rails/info#routes", internal: true
- get '/rails/info' => "rails/info#index", internal: true
- get '/' => "rails/welcome#index", internal: true
+ get "/" => "rails/welcome#index", internal: true
end
end
end
+ # Setup default session store if not already set in config/application.rb
+ initializer :setup_default_session_store, before: :build_middleware_stack do |app|
+ unless app.config.session_store?
+ app_name = app.class.name ? app.railtie_name.chomp("_application") : ""
+ app.config.session_store :cookie_store, key: "_#{app_name}_session"
+ end
+ end
+
initializer :build_middleware_stack do
build_middleware_stack
end
@@ -95,7 +106,7 @@ module Rails
elsif config.allow_concurrency == :unsafe
# Do nothing, even if we know this is dangerous. This is the
- # historical behaviour for true.
+ # historical behavior for true.
else
# Default concurrency setting: enabled, but safe
@@ -114,7 +125,7 @@ module Rails
initializer :set_routes_reloader_hook do |app|
reloader = routes_reloader
reloader.execute_if_updated
- self.reloaders << reloader
+ reloaders << reloader
app.reloader.to_run do
# We configure #execute rather than #execute_if_updated because if
# autoloaded constants are cleared we need to reload routes also in
@@ -150,7 +161,7 @@ module Rails
if config.reload_classes_only_on_change
reloader = config.file_watcher.new(*watchable_args, &callback)
- self.reloaders << reloader
+ reloaders << reloader
# Prepend this callback to have autoloaded constants cleared before
# any other possible reloading, in case they need to autoload fresh
@@ -173,7 +184,7 @@ module Rails
# Disable dependency loading during request cycle
initializer :disable_dependency_loading do
- if config.eager_load && config.cache_classes
+ if config.eager_load && config.cache_classes && !config.enable_dependency_loading
ActiveSupport::Dependencies.unhook!
end
end