Sha256: 0ef5237ce17f974682172831e4d7ba3922cb5246c861f1bf6336f0ed8b46b41e

Contents?: true

Size: 1.09 KB

Versions: 38

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require "active_support/string_inquirer"
require "active_support/core_ext/object/inclusion"

module ActiveSupport
  class EnvironmentInquirer < StringInquirer # :nodoc:
    # Optimization for the three default environments, so this inquirer doesn't need to rely on
    # the slower delegation through method_missing that StringInquirer would normally entail.
    DEFAULT_ENVIRONMENTS = %w[ development test production ]

    # Environments that'll respond true for #local?
    LOCAL_ENVIRONMENTS = %w[ development test ]

    def initialize(env)
      raise(ArgumentError, "'local' is a reserved environment name") if env == "local"

      super(env)

      DEFAULT_ENVIRONMENTS.each do |default|
        instance_variable_set :"@#{default}", env == default
      end

      @local = in? LOCAL_ENVIRONMENTS
    end

    DEFAULT_ENVIRONMENTS.each do |env|
      class_eval <<~RUBY, __FILE__, __LINE__ + 1
        def #{env}?
          @#{env}
        end
      RUBY
    end

    # Returns true if we're in the development or test environment.
    def local?
      @local
    end
  end
end

Version data entries

38 entries across 38 versions & 6 rubygems

Version Path
activesupport-8.0.0 lib/active_support/environment_inquirer.rb
activesupport-7.2.2 lib/active_support/environment_inquirer.rb
activesupport-7.1.5 lib/active_support/environment_inquirer.rb
activesupport-8.0.0.rc2 lib/active_support/environment_inquirer.rb
activesupport-7.2.1.2 lib/active_support/environment_inquirer.rb
activesupport-7.1.4.2 lib/active_support/environment_inquirer.rb
activesupport-8.0.0.rc1 lib/active_support/environment_inquirer.rb
activesupport-7.2.1.1 lib/active_support/environment_inquirer.rb
activesupport-7.1.4.1 lib/active_support/environment_inquirer.rb
activesupport-8.0.0.beta1 lib/active_support/environment_inquirer.rb
omg-activesupport-8.0.0.alpha9 lib/active_support/environment_inquirer.rb
omg-activesupport-8.0.0.alpha8 lib/active_support/environment_inquirer.rb
omg-activesupport-8.0.0.alpha7 lib/active_support/environment_inquirer.rb
omg-activesupport-8.0.0.alpha4 lib/active_support/environment_inquirer.rb
omg-activesupport-8.0.0.alpha3 lib/active_support/environment_inquirer.rb
omg-activesupport-8.0.0.alpha2 lib/active_support/environment_inquirer.rb
omg-activesupport-8.0.0.alpha1 lib/active_support/environment_inquirer.rb
activesupport-7.1.4 lib/active_support/environment_inquirer.rb
activesupport-7.2.1 lib/active_support/environment_inquirer.rb
activesupport-7.2.0 lib/active_support/environment_inquirer.rb