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