2017-08-14 17:08:09 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-21 13:08:33 +00:00
|
|
|
require "rails/ruby_version_check"
|
2010-06-11 18:02:47 +00:00
|
|
|
|
2016-08-06 17:15:47 +00:00
|
|
|
require "pathname"
|
2009-12-31 20:28:48 +00:00
|
|
|
|
2016-08-06 17:15:47 +00:00
|
|
|
require "active_support"
|
|
|
|
require "active_support/core_ext/kernel/reporting"
|
|
|
|
require "active_support/core_ext/module/delegation"
|
|
|
|
require "active_support/core_ext/array/extract_options"
|
2016-12-19 01:45:14 +00:00
|
|
|
require "active_support/core_ext/object/blank"
|
2009-12-31 20:28:48 +00:00
|
|
|
|
2017-10-21 13:08:33 +00:00
|
|
|
require "rails/application"
|
|
|
|
require "rails/version"
|
2009-12-31 20:28:48 +00:00
|
|
|
|
2016-08-06 17:15:47 +00:00
|
|
|
require "active_support/railtie"
|
|
|
|
require "action_dispatch/railtie"
|
2010-01-17 11:41:55 +00:00
|
|
|
|
2015-01-04 18:37:05 +00:00
|
|
|
# UTF-8 is the default internal and external encoding.
|
2011-12-20 16:58:45 +00:00
|
|
|
silence_warnings do
|
|
|
|
Encoding.default_external = Encoding::UTF_8
|
|
|
|
Encoding.default_internal = Encoding::UTF_8
|
2009-12-31 20:28:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
module Rails
|
2013-06-11 20:37:38 +00:00
|
|
|
extend ActiveSupport::Autoload
|
2020-12-04 12:52:10 +00:00
|
|
|
extend ActiveSupport::Benchmarkable
|
2013-06-11 20:37:38 +00:00
|
|
|
|
|
|
|
autoload :Info
|
|
|
|
autoload :InfoController
|
2013-12-16 05:52:58 +00:00
|
|
|
autoload :MailersController
|
2013-06-11 20:37:38 +00:00
|
|
|
autoload :WelcomeController
|
2010-03-20 19:03:43 +00:00
|
|
|
|
2009-12-31 20:28:48 +00:00
|
|
|
class << self
|
2014-08-07 01:27:16 +00:00
|
|
|
@application = @app_class = nil
|
|
|
|
|
|
|
|
attr_writer :application
|
|
|
|
attr_accessor :app_class, :cache, :logger
|
|
|
|
def application
|
|
|
|
@application ||= (app_class.instance if app_class)
|
|
|
|
end
|
2009-12-31 20:28:48 +00:00
|
|
|
|
2013-06-11 20:37:38 +00:00
|
|
|
delegate :initialize!, :initialized?, to: :application
|
|
|
|
|
2009-12-31 20:28:48 +00:00
|
|
|
# The Configuration instance used to configure the Rails environment
|
|
|
|
def configuration
|
2010-01-12 11:52:09 +00:00
|
|
|
application.config
|
2009-12-31 20:28:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def backtrace_cleaner
|
2012-04-06 04:59:57 +00:00
|
|
|
@backtrace_cleaner ||= begin
|
2016-09-24 18:39:16 +00:00
|
|
|
# Relies on Active Support, so we have to lazy load to postpone definition until Active Support has been loaded
|
2017-10-21 13:08:33 +00:00
|
|
|
require "rails/backtrace_cleaner"
|
2009-12-31 20:28:48 +00:00
|
|
|
Rails::BacktraceCleaner.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-12 06:51:36 +00:00
|
|
|
# Returns a Pathname object of the current Rails project,
|
2016-10-26 21:13:15 +00:00
|
|
|
# otherwise it returns +nil+ if there is no project:
|
2015-05-07 16:54:26 +00:00
|
|
|
#
|
|
|
|
# Rails.root
|
|
|
|
# # => #<Pathname:/Users/someuser/some/path/project>
|
2009-12-31 20:28:48 +00:00
|
|
|
def root
|
|
|
|
application && application.config.root
|
|
|
|
end
|
|
|
|
|
2014-12-20 18:09:45 +00:00
|
|
|
# Returns the current Rails environment.
|
|
|
|
#
|
|
|
|
# Rails.env # => "development"
|
|
|
|
# Rails.env.development? # => true
|
|
|
|
# Rails.env.production? # => false
|
2009-12-31 20:28:48 +00:00
|
|
|
def env
|
2019-11-26 22:56:14 +00:00
|
|
|
@_env ||= ActiveSupport::EnvironmentInquirer.new(ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || "development")
|
2009-12-31 20:28:48 +00:00
|
|
|
end
|
|
|
|
|
2014-12-20 18:09:45 +00:00
|
|
|
# Sets the Rails environment.
|
|
|
|
#
|
|
|
|
# Rails.env = "staging" # => "staging"
|
2010-04-08 05:52:35 +00:00
|
|
|
def env=(environment)
|
2019-11-26 22:56:14 +00:00
|
|
|
@_env = ActiveSupport::EnvironmentInquirer.new(environment)
|
2010-04-08 05:52:35 +00:00
|
|
|
end
|
|
|
|
|
2021-11-10 14:21:27 +00:00
|
|
|
def error
|
|
|
|
application && application.executor.error_reporter
|
|
|
|
end
|
|
|
|
|
2016-07-12 06:51:36 +00:00
|
|
|
# Returns all Rails groups for loading based on:
|
2011-06-21 11:02:47 +00:00
|
|
|
#
|
|
|
|
# * The Rails environment;
|
|
|
|
# * The environment variable RAILS_GROUPS;
|
2011-07-10 11:35:06 +00:00
|
|
|
# * The optional envs given as argument and the hash with group dependencies;
|
2011-06-21 11:02:47 +00:00
|
|
|
#
|
2019-09-05 10:00:20 +00:00
|
|
|
# Rails.groups assets: [:development, :test]
|
|
|
|
# # => [:default, "development", :assets] for Rails.env == "development"
|
|
|
|
# # => [:default, "production"] for Rails.env == "production"
|
2011-07-10 11:35:06 +00:00
|
|
|
def groups(*groups)
|
|
|
|
hash = groups.extract_options!
|
2011-06-21 11:02:47 +00:00
|
|
|
env = Rails.env
|
2011-07-10 11:35:06 +00:00
|
|
|
groups.unshift(:default, env)
|
2011-06-21 11:02:47 +00:00
|
|
|
groups.concat ENV["RAILS_GROUPS"].to_s.split(",")
|
2013-06-11 20:37:38 +00:00
|
|
|
groups.concat hash.map { |k, v| k if v.map(&:to_s).include?(env) }
|
2011-06-21 11:02:47 +00:00
|
|
|
groups.compact!
|
2011-07-10 11:35:06 +00:00
|
|
|
groups.uniq!
|
2011-06-21 11:02:47 +00:00
|
|
|
groups
|
|
|
|
end
|
|
|
|
|
2015-05-07 16:54:26 +00:00
|
|
|
# Returns a Pathname object of the public folder of the current
|
2016-10-26 21:13:15 +00:00
|
|
|
# Rails project, otherwise it returns +nil+ if there is no project:
|
2015-05-07 16:54:26 +00:00
|
|
|
#
|
|
|
|
# Rails.public_path
|
|
|
|
# # => #<Pathname:/Users/someuser/some/path/project/public>
|
2009-12-31 20:28:48 +00:00
|
|
|
def public_path
|
2012-10-03 00:44:02 +00:00
|
|
|
application && Pathname.new(application.paths["public"].first)
|
2009-12-31 20:28:48 +00:00
|
|
|
end
|
2019-02-11 20:44:25 +00:00
|
|
|
|
|
|
|
def autoloaders
|
2022-01-05 11:59:49 +00:00
|
|
|
application.autoloaders
|
2019-02-11 20:44:25 +00:00
|
|
|
end
|
2009-12-23 01:03:23 +00:00
|
|
|
end
|
2009-12-31 20:28:48 +00:00
|
|
|
end
|