Sha256: 6e8568e9a2058d5fcc07dc31c4d55ddda8c01ff64dd4604fd67b4df4c7cc9363

Contents?: true

Size: 1.37 KB

Versions: 15

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

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

module Jets
  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: Jets::Command.environment)
          if options[:environment]
            self.options = options.merge(environment: acceptable_environment(options[:environment]))
          else
            self.options = options.merge(environment: default_environment)
          end
          # JETS_ENV needs to be set before config/application is required.
          ENV["JETS_ENV"] = options[:environment]
        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

15 entries across 15 versions & 1 rubygems

Version Path
jets-5.0.13 lib/jets/command/environment_argument.rb
jets-5.0.12 lib/jets/command/environment_argument.rb
jets-5.0.11 lib/jets/command/environment_argument.rb
jets-5.0.10 lib/jets/command/environment_argument.rb
jets-5.0.9 lib/jets/command/environment_argument.rb
jets-5.0.8 lib/jets/command/environment_argument.rb
jets-5.0.7 lib/jets/command/environment_argument.rb
jets-5.0.6 lib/jets/command/environment_argument.rb
jets-5.0.5 lib/jets/command/environment_argument.rb
jets-5.0.4 lib/jets/command/environment_argument.rb
jets-5.0.3 lib/jets/command/environment_argument.rb
jets-5.0.2 lib/jets/command/environment_argument.rb
jets-5.0.1 lib/jets/command/environment_argument.rb
jets-5.0.0 lib/jets/command/environment_argument.rb
jets-5.0.0.beta1 lib/jets/command/environment_argument.rb