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 ]


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

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 34

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

#environment=(environment) (rw, private)

[ GitHub ]

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

def environment=(environment)
  @environment = environment
end

#environment_specified?Boolean (readonly, private)

[ GitHub ]

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

def environment_specified?
  @environment_specified
end

Instance Method Details

#available_environments (private)

[ GitHub ]

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

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 51

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 16

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 29

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