module Rails::Command::EnvironmentArgument
def available_environments
def available_environments @available_environments ||= Dir["config/environments/*.rb"].map { |filename| File.basename(filename, ".*") } end
def environment
def environment @environment ||= options[:environment] end
def environment=(environment)
def environment=(environment) @environment = environment end
def environment_specified?
def environment_specified? @environment_specified end
def expand_environment_name(name)
def expand_environment_name(name) %w[production development test].find { |full_name| full_name.start_with?(name) } || name end
def initialize(...)
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
def require_application!
def require_application! ENV["RAILS_ENV"] = environment super end