module Rails
def self.gem_version
def self.gem_version Gem::Version.new VERSION::STRING end
def self.version
def self.version VERSION::STRING end
def application
def application @application ||= (app_class.instance if app_class) end
def backtrace_cleaner
def backtrace_cleaner @backtrace_cleaner ||= begin # Relies on Active Support, so we have to lazy load to postpone definition until AS has been loaded require 'rails/backtrace_cleaner' Rails::BacktraceCleaner.new end end
def configuration
def configuration application.config end
def env
Rails.env.development? # => true
Rails.env # => "development"
Returns the current Rails environment.
def env @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development") end
def env=(environment)
Sets the Rails environment.
def env=(environment) @_env = ActiveSupport::StringInquirer.new(environment) end
def groups(*groups)
# => [:default, :development, :assets] for Rails.env == "development"
# Returns
groups assets: [:development, :test]
* The optional envs given as argument and the hash with group dependencies;
* The environment variable RAILS_GROUPS;
* The Rails environment;
Returns all rails groups for loading based on:
def groups(*groups) hash = groups.extract_options! env = Rails.env groups.unshift(:default, env) groups.concat ENV["RAILS_GROUPS"].to_s.split(",") groups.concat hash.map { |k, v| k if v.map(&:to_s).include?(env) } groups.compact! groups.uniq! groups end
def public_path
Rails.public_path
rails project, otherwise it returns nil if there is no project:
Returns a Pathname object of the public folder of the current
def public_path application && Pathname.new(application.paths["public"].first) end
def root
Rails.root
otherwise it returns nil if there is no project:
Returns a Pathname object of the current rails project,
def root application && application.config.root end