123456789_123456789_123456789_123456789_123456789_

Module: Rails::Command::EnvironmentArgument

Do not use. This module is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Defined in: railties/lib/rails/command/environment_argument.rb

Class Method Summary

::ActiveSupport::Concern - Extended

class_methods

Define class methods from given block.

included

Evaluate given block in context of base class, so that you can write class macros here.

prepended

Evaluate given block in context of base class, so that you can write class macros here.

append_features, prepend_features

Instance Attribute Summary

Instance Method Summary

DSL Calls

included

[ GitHub ]


10
11
12
13
# File 'railties/lib/rails/command/environment_argument.rb', line 10

included do
  class_option :environment, aliases: "-e", type: :string,
    desc: "The environment to run `#{self.command_name}` in (e.g. test / development / production)."
end

Instance Attribute Details

#environment (rw, private)

[ GitHub ]

  
# File 'railties/lib/rails/command/environment_argument.rb', line 33

def environment
  @environment ||= options[:environment]
end

#environment=(environment) (rw, private)

[ GitHub ]

  
# File 'railties/lib/rails/command/environment_argument.rb', line 37

def environment=(environment)
  @environment = environment
end

#environment_specified?Boolean (readonly, private)

[ GitHub ]

  
# File 'railties/lib/rails/command/environment_argument.rb', line 41

def environment_specified?
  @environment_specified
end

Instance Method Details

#available_environments (private)

[ GitHub ]

  
# File 'railties/lib/rails/command/environment_argument.rb', line 45

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

#expand_environment_name(name) (private)

[ GitHub ]

  
# File 'railties/lib/rails/command/environment_argument.rb', line 50

def expand_environment_name(name)
  %w[production development test].find { |full_name| full_name.start_with?(name) } || name
end

#initialize

[ GitHub ]

  
# File 'railties/lib/rails/command/environment_argument.rb', line 15

def initialize(...)
  super

  @environment_specified = options[:environment].present?

  if !@environment_specified
    self.options = options.merge(environment: Rails::Command.environment)
  elsif !available_environments.include?(options[:environment])
    self.options = options.merge(environment: expand_environment_name(options[:environment]))
  end
end

#require_application! (private)

[ GitHub ]

  
# File 'railties/lib/rails/command/environment_argument.rb', line 28

def require_application!
  ENV["RAILS_ENV"] = environment
  super
end