Sha256: 0ef5237ce17f974682172831e4d7ba3922cb5246c861f1bf6336f0ed8b46b41e

Contents?: true

Size: 1.09 KB

Versions: 44

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

44 entries across 44 versions & 8 rubygems

Version Path
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
activesupport-7.2.0.rc1 lib/active_support/environment_inquirer.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3.4/lib/active_support/environment_inquirer.rb
activesupport-7.2.0.beta3 lib/active_support/environment_inquirer.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/environment_inquirer.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/environment_inquirer.rb
activesupport-7.2.0.beta2 lib/active_support/environment_inquirer.rb
activesupport-7.1.3.4 lib/active_support/environment_inquirer.rb
activesupport-7.2.0.beta1 lib/active_support/environment_inquirer.rb
activesupport-7.1.3.2 lib/active_support/environment_inquirer.rb
activesupport-7.1.3.1 lib/active_support/environment_inquirer.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3/lib/active_support/environment_inquirer.rb
activesupport-7.1.3 lib/active_support/environment_inquirer.rb
activesupport-7.1.2 lib/active_support/environment_inquirer.rb
activesupport-7.1.1 lib/active_support/environment_inquirer.rb