Sha256: 59d2cb9b9956b0fd8e17b4625dc40a1f9c8b922a48706fb7ca30a141a1c768cc

Contents?: true

Size: 1.62 KB

Versions: 42

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require "active_support"

module Rails
  module Command
    module EnvironmentArgument #:nodoc:
      extend ActiveSupport::Concern

      included do
        argument :environment, optional: true, banner: "environment"

        class_option :environment, aliases: "-e", type: :string,
          desc: "Specifies the environment to run this console under (test/development/production)."
      end

      private
        def extract_environment_option_from_argument
          if environment
            self.options = options.merge(environment: acceptable_environment(environment))

            ActiveSupport::Deprecation.warn "Passing the environment's name as a " \
                                            "regular argument is deprecated and "  \
                                            "will be removed in the next Rails "   \
                                            "version. Please, use the -e option "  \
                                            "instead."
          elsif options[:environment]
            self.options = options.merge(environment: acceptable_environment(options[:environment]))
          else
            self.options = options.merge(environment: Rails::Command.environment)
          end
        end

        def acceptable_environment(env = nil)
          if available_environments.include? env
            env
          else
            %w( production development test ).detect { |e| e =~ /^#{env}/ } || env
          end
        end

        def available_environments
          Dir["config/environments/*.rb"].map { |fname| File.basename(fname, ".*") }
        end
    end
  end
end

Version data entries

42 entries across 42 versions & 3 rubygems

Version Path
railties-5.2.8.1 lib/rails/command/environment_argument.rb
railties-5.2.8 lib/rails/command/environment_argument.rb
railties-5.2.7.1 lib/rails/command/environment_argument.rb
railties-5.2.7 lib/rails/command/environment_argument.rb
railties-5.2.6.3 lib/rails/command/environment_argument.rb
railties-5.2.6.2 lib/rails/command/environment_argument.rb
railties-5.2.6.1 lib/rails/command/environment_argument.rb
railties-5.2.6 lib/rails/command/environment_argument.rb
railties-5.2.4.6 lib/rails/command/environment_argument.rb
railties-5.2.5 lib/rails/command/environment_argument.rb
railties-5.2.4.5 lib/rails/command/environment_argument.rb
railties-5.2.4.4 lib/rails/command/environment_argument.rb
railties-5.2.4.3 lib/rails/command/environment_argument.rb
railties-5.2.4.2 lib/rails/command/environment_argument.rb
railties-5.2.4.1 lib/rails/command/environment_argument.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/railties-5.2.3/lib/rails/command/environment_argument.rb
railties-5.2.4 lib/rails/command/environment_argument.rb
railties-5.2.4.rc1 lib/rails/command/environment_argument.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/railties-5.2.3/lib/rails/command/environment_argument.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/railties-5.2.3/lib/rails/command/environment_argument.rb