Repository: rails/rails
File: railties/lib/rails/application.rb (Ruby)

Code before:

    def railties_initializers(current) # :nodoc:
      initializers = Initializable::Collection.new
      ordered_railties.reverse.flatten.each do |r|
        if r == self
          initializers += current
        else
          initializers += r.initializers
        end
      end
      initializers
    end

    def default_middleware_stack # :nodoc:
      default_stack = DefaultMiddlewareStack.new(self, config, paths)
      default_stack.build_stack
    end

    def ensure_generator_templates_added
      configured_paths = config.generators.templates
      configured_paths.unshift(*(paths["lib/templates"].existent - configured_paths))
    end

    private
      def missing_environment_file
        raise <<~TEXT
          Rails environment has been set to #{Rails.env} but
          config\/environments\/#{Rails.env}.rb does not exist"
        TEXT
      end

      def build_request(env)
        req = super
        env["ORIGINAL_FULLPATH"] = req.fullpath
        env["ORIGINAL_SCRIPT_NAME"] = req.script_name
        req
      end

      def build_middleware
        config.app_middleware + super
      end

      def coerce_same_site_protection(protection)
        protection.respond_to?(:call) ? protection : proc { protection }
      end

      def filter_parameters
        if config.precompile_filter_parameters
          config.filter_parameters.replace(
            ActiveSupport::ParameterFilter.precompile_filters(config.filter_parameters)
          )

Review comment (suggestion):
Should users have a config to turn off this? I don't know, but I'm guessing maybe someone could have a case in which they are running Rails on some weird environment name and everything is ok for them. We could check for config and switch from `raise` to `warn`.

Code after:

    def railties_initializers(current) # :nodoc:
      initializers = Initializable::Collection.new
      ordered_railties.reverse.flatten.each do |r|
        if r == self
          initializers += current
        else
          initializers += r.initializers
        end
      end
      initializers
    end

    def default_middleware_stack # :nodoc:
      default_stack = DefaultMiddlewareStack.new(self, config, paths)
      default_stack.build_stack
    end

    def ensure_generator_templates_added
      configured_paths = config.generators.templates
      configured_paths.unshift(*(paths["lib/templates"].existent - configured_paths))
    end

    private
      def missing_environment_file
        raise "Rails environment has been set to #{Rails.env} but config/environments/#{Rails.env}.rb does not exist."
      end

      def any_environment_files?
        paths["config/environments"]
          .paths
          .flat_map { |path| [path, *path.glob("*.rb")] }
          .select(&:file?)
          .any?
      end

      def build_request(env)
        req = super
        env["ORIGINAL_FULLPATH"] = req.fullpath
        env["ORIGINAL_SCRIPT_NAME"] = req.script_name
        req
      end

      def build_middleware
        config.app_middleware + super
      end

      def coerce_same_site_protection(protection)
        protection.respond_to?(:call) ? protection : proc { protection }
      end