未验证 提交 9e5c6c4c 编写于 作者: A Aaron Patterson 提交者: GitHub

Merge pull request #37808 from headius/optimize_string_inquirer

Use optimized subclass of StringInquirer for Rails.env
# frozen_string_literal: true
require "active_support/string_inquirer"
require "active_support/environment_inquirer"
class String
# Wraps the current string in the <tt>ActiveSupport::StringInquirer</tt> class,
......
# frozen_string_literal: true
module ActiveSupport
# This is a special case of StringInquirer that defines the three default
# environments at construction time based on the environment string.
class EnvironmentInquirer < StringInquirer
DEFAULT_ENVIRONMENTS = ["development", "test", "production"]
def initialize(env)
super(env)
DEFAULT_ENVIRONMENTS.each do |default_env|
singleton_class.define_method(:"#{env}?", (env == default_env).method(:itself))
end
end
end
end
......@@ -70,14 +70,14 @@ def root
# Rails.env.development? # => true
# Rails.env.production? # => false
def env
@_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || "development")
@_env ||= ActiveSupport::EnvironmentInquirer.new(ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || "development")
end
# Sets the Rails environment.
#
# Rails.env = "staging" # => "staging"
def env=(environment)
@_env = ActiveSupport::StringInquirer.new(environment)
@_env = ActiveSupport::EnvironmentInquirer.new(environment)
end
# Returns all Rails groups for loading based on:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册