Sha256: 9ee5ac706521a1692caf70af1a0d51f00e4c5b83f499419ee6d1d079f9806200

Contents?: true

Size: 1.25 KB

Versions: 40

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

require "active_support"
require "active_support/core_ext/class/attribute"

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

      included do
        no_commands do
          class_attribute :environment_desc, default: "Specifies the environment to run this #{self.command_name} under (test/development/production)."
        end
        class_option :environment, aliases: "-e", type: :string, desc: environment_desc
      end

      private
        def extract_environment_option_from_argument(default_environment: Rails::Command.environment)
          if options[:environment]
            self.options = options.merge(environment: acceptable_environment(options[:environment]))
          else
            self.options = options.merge(environment: default_environment)
          end
        end

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

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

Version data entries

40 entries across 37 versions & 5 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/railties-7.0.8.6/lib/rails/command/environment_argument.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/railties-7.0.8.7/lib/rails/command/environment_argument.rb
railties-7.0.8.7 lib/rails/command/environment_argument.rb
railties-7.0.8.6 lib/rails/command/environment_argument.rb
railties-7.0.8.5 lib/rails/command/environment_argument.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/railties-7.0.8.4/lib/rails/command/environment_argument.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/railties-7.0.5.1/lib/rails/command/environment_argument.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/railties-7.0.5.1/lib/rails/command/environment_argument.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/railties-7.0.5.1/lib/rails/command/environment_argument.rb
railties-7.0.8.4 lib/rails/command/environment_argument.rb
railties-7.0.8.1 lib/rails/command/environment_argument.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/railties-7.0.3.1/lib/rails/command/environment_argument.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/railties-7.0.2.3/lib/rails/command/environment_argument.rb
railties-7.0.8 lib/rails/command/environment_argument.rb
railties-7.0.7.2 lib/rails/command/environment_argument.rb
railties-7.0.7.1 lib/rails/command/environment_argument.rb
railties-7.0.7 lib/rails/command/environment_argument.rb
railties-7.0.6 lib/rails/command/environment_argument.rb
railties-7.0.5.1 lib/rails/command/environment_argument.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/railties-7.0.2.3/lib/rails/command/environment_argument.rb