lib/rails/application.rb in railties-6.1.7.10 vs lib/rails/application.rb in railties-7.0.0.alpha1

- old
+ new

@@ -55,33 +55,10 @@ # One by one, each engine sets up its load paths, routes and runs its config/initializers/* files. # 8) Custom Railtie#initializers added by railties, engines and applications are executed # 9) Build the middleware stack and run to_prepare callbacks # 10) Run config.before_eager_load and eager_load! if eager_load is true # 11) Run config.after_initialize callbacks - # - # == Multiple Applications - # - # If you decide to define multiple applications, then the first application - # that is initialized will be set to +Rails.application+, unless you override - # it with a different application. - # - # To create a new application, you can instantiate a new instance of a class - # that has already been created: - # - # class Application < Rails::Application - # end - # - # first_application = Application.new - # second_application = Application.new(config: first_application.config) - # - # In the above example, the configuration from the first application was used - # to initialize the second application. You can also use the +initialize_copy+ - # on one of the applications to create a copy of the application which shares - # the configuration. - # - # If you decide to define Rake tasks, runners, or initializers in an - # application other than +Rails.application+, then you must run them manually. class Application < Engine autoload :Bootstrap, "rails/application/bootstrap" autoload :Configuration, "rails/application/configuration" autoload :DefaultMiddlewareStack, "rails/application/default_middleware_stack" autoload :Finisher, "rails/application/finisher" @@ -245,13 +222,15 @@ require "erb" all_configs = ActiveSupport::ConfigurationFile.parse(yaml).deep_symbolize_keys config, shared = all_configs[env.to_sym], all_configs[:shared] if shared - config = {} if config.nil? - if config.is_a?(Hash) + config = {} if config.nil? && shared.is_a?(Hash) + if config.is_a?(Hash) && shared.is_a?(Hash) config = shared.deep_merge(config) + elsif config.nil? + config = shared end end if config.is_a?(Hash) config = ActiveSupport::OrderedOptions.new.update(config) @@ -264,17 +243,17 @@ end # Stores some of the Rails initial environment parameters which # will be used by middlewares and engines to configure themselves. def env_config - @app_env_config ||= begin - super.merge( + @app_env_config ||= super.merge( "action_dispatch.parameter_filter" => config.filter_parameters, "action_dispatch.redirect_filter" => config.filter_redirect, "action_dispatch.secret_key_base" => secret_key_base, "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions, "action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local, + "action_dispatch.log_rescued_responses" => config.action_dispatch.log_rescued_responses, "action_dispatch.logger" => Rails.logger, "action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner, "action_dispatch.key_generator" => key_generator, "action_dispatch.http_auth_salt" => config.action_dispatch.http_auth_salt, "action_dispatch.signed_cookie_salt" => config.action_dispatch.signed_cookie_salt, @@ -293,11 +272,10 @@ "action_dispatch.content_security_policy_report_only" => config.content_security_policy_report_only, "action_dispatch.content_security_policy_nonce_generator" => config.content_security_policy_nonce_generator, "action_dispatch.content_security_policy_nonce_directives" => config.content_security_policy_nonce_directives, "action_dispatch.permissions_policy" => config.permissions_policy, ) - end end # If you try to define a set of Rake tasks on the instance, these will get # passed up to the Rake tasks defined on the application's class. def rake_tasks(&block) @@ -353,30 +331,30 @@ # # Notice this method takes into consideration the default root path. So if you # are changing config.root inside your application definition or having a custom # Rails application, you will need to add lib to $LOAD_PATH on your own in case # you need to load files in lib/ during the application configuration as well. - def self.add_lib_to_load_path!(root) #:nodoc: + def self.add_lib_to_load_path!(root) # :nodoc: path = File.join root, "lib" if File.exist?(path) && !$LOAD_PATH.include?(path) $LOAD_PATH.unshift(path) end end - def require_environment! #:nodoc: + def require_environment! # :nodoc: environment = paths["config/environment"].existent.first require environment if environment end - def routes_reloader #:nodoc: + def routes_reloader # :nodoc: @routes_reloader ||= RoutesReloader.new end # Returns an array of file paths appended with a hash of # directories-extensions suitable for ActiveSupport::FileUpdateChecker # API. - def watchable_args #:nodoc: + def watchable_args # :nodoc: files, dirs = config.watchable_files.dup, config.watchable_dirs.dup ActiveSupport::Dependencies.autoload_paths.each do |path| File.file?(path) ? files << path.to_s : dirs[path.to_s] = [:rb] end @@ -384,24 +362,24 @@ [files, dirs] end # Initialize the application passing the given group. By default, the # group is :default - def initialize!(group = :default) #:nodoc: + def initialize!(group = :default) # :nodoc: raise "Application has been already initialized." if @initialized run_initializers(group, self) @initialized = true self end - def initializers #:nodoc: + def initializers # :nodoc: Bootstrap.initializers_for(self) + railties_initializers(super) + Finisher.initializers_for(self) end - def config #:nodoc: + def config # :nodoc: @config ||= Application::Configuration.new(self.class.find_root(self.class.called_from)) end attr_writer :config @@ -485,15 +463,15 @@ env_key: env_key, raise_if_missing_key: config.require_master_key ) end - def to_app #:nodoc: + def to_app # :nodoc: self end - def helpers_paths #:nodoc: + def helpers_paths # :nodoc: config.helpers_paths end console do unless ::Kernel.private_method_defined?(:y) @@ -511,53 +489,49 @@ ordered_railties.flatten - [self] end # Eager loads the application code. def eager_load! - if Rails.autoloaders.zeitwerk_enabled? - Rails.autoloaders.each(&:eager_load) - else - super - end + Rails.autoloaders.each(&:eager_load) end protected alias :build_middleware_stack :app - def run_tasks_blocks(app) #:nodoc: + def run_tasks_blocks(app) # :nodoc: railties.each { |r| r.run_tasks_blocks(app) } super load "rails/tasks.rb" task :environment do ActiveSupport.on_load(:before_initialize) { config.eager_load = config.rake_eager_load } require_environment! end end - def run_generators_blocks(app) #:nodoc: + def run_generators_blocks(app) # :nodoc: railties.each { |r| r.run_generators_blocks(app) } super end - def run_runner_blocks(app) #:nodoc: + def run_runner_blocks(app) # :nodoc: railties.each { |r| r.run_runner_blocks(app) } super end - def run_console_blocks(app) #:nodoc: + def run_console_blocks(app) # :nodoc: railties.each { |r| r.run_console_blocks(app) } super end - def run_server_blocks(app) #:nodoc: + def run_server_blocks(app) # :nodoc: railties.each { |r| r.run_server_blocks(app) } super end # Returns the ordered railties for this application considering railties_order. - def ordered_railties #:nodoc: + def ordered_railties # :nodoc: @ordered_railties ||= begin order = config.railties_order.map do |railtie| if railtie == :main_app self elsif railtie.respond_to?(:instance) @@ -575,11 +549,11 @@ order[index] = all order end end - def railties_initializers(current) #:nodoc: + def railties_initializers(current) # :nodoc: initializers = [] ordered_railties.reverse.flatten.each do |r| if r == self initializers += current else @@ -587,10 +561,10 @@ end end initializers end - def default_middleware_stack #:nodoc: + def default_middleware_stack # :nodoc: default_stack = DefaultMiddlewareStack.new(self, config, paths) default_stack.build_stack end def validate_secret_key_base(secret_key_base)