123456789_123456789_123456789_123456789_123456789_

Class: Rails::Command::Base

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Rails::Command::ApplicationCommand, Rails::Command::ConsoleCommand, Rails::Command::CredentialsCommand, Rails::Command::DbconsoleCommand, Rails::Command::DestroyCommand, Rails::Command::DevCommand, Rails::Command::EncryptedCommand, Rails::Command::GenerateCommand, Rails::Command::HelpCommand, Rails::Command::InitializersCommand, Rails::Command::NewCommand, Rails::Command::NotesCommand, Rails::Command::PluginCommand, Rails::Command::RakeCommand, Rails::Command::RoutesCommand, Rails::Command::RunnerCommand, Rails::Command::SecretsCommand, Rails::Command::ServerCommand, Rails::Command::TestCommand, Rails::Command::VersionCommand, Rails::Command::Db::System::ChangeCommand
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Thor
Instance Chain:
self, Actions, Thor
Inherits: Thor
Defined in: railties/lib/rails/command/base.rb

Class Attribute Summary

Class Method Summary

Instance Method Summary

Actions - Included

#load_generators

See additional method definition at line 38.

#load_tasks

See additional method definition at line 33.

#require_application!, #require_application_and_environment!, #require_environment!,
#set_application_directory!

Change to the application’s path if there is no config.ru file in current directory.

Class Attribute Details

.engine?Boolean (readonly)

Returns true when the app is a ::Rails engine.

[ GitHub ]

  
# File 'railties/lib/rails/command/base.rb', line 25

def engine?
  defined?(ENGINE_ROOT)
end

Class Method Details

.base_name

Sets the base_name taking into account the current class namespace.

Rails::Command::TestCommand.base_name # => 'rails'
[ GitHub ]

  
# File 'railties/lib/rails/command/base.rb', line 88

def base_name
  @base_name ||= begin
    if base = name.to_s.split("::").first
      base.underscore
    end
  end
end

.command_name

Return command name without namespaces.

Rails::Command::TestCommand.command_name # => 'test'
[ GitHub ]

  
# File 'railties/lib/rails/command/base.rb', line 99

def command_name
  @command_name ||= begin
    if command = name.to_s.split("::").last
      command.chomp!("Command")
      command.underscore
    end
  end
end

.default_command_root

Default file root to place extra files a command might need, placed one folder above the command file.

For a TestCommand placed in rails/command/test_command.rb would return rails/test.

[ GitHub ]

  
# File 'railties/lib/rails/command/base.rb', line 121

def default_command_root
  path = File.expand_path(relative_command_path, __dir__)
  path if File.exist?(path)
end

.desc(usage = nil, description = nil, options = {})

Tries to get the description from a USAGE file one folder above the command root.

[ GitHub ]

  
# File 'railties/lib/rails/command/base.rb', line 31

def desc(usage = nil, description = nil, options = {})
  if usage
    super
  else
    @desc ||= ERB.new(File.read(usage_path)).result(binding) if usage_path
  end
end

.executable

[ GitHub ]

  
# File 'railties/lib/rails/command/base.rb', line 76

def executable
  "rails #{command_name}"
end

.hide_command!

Convenience method to hide this command from the available ones when running rails command.

[ GitHub ]

  
# File 'railties/lib/rails/command/base.rb', line 52

def hide_command!
  Rails::Command.hidden_commands << self
end

.namespace(name = nil)

Convenience method to get the namespace from the class name. It’s the same as Thor default except that the ::Rails::Command at the end of the class is removed.

[ GitHub ]

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

def namespace(name = nil)
  if name
    super
  else
    @namespace ||= super.chomp("_command").sub(/:command:/, ":")
  end
end

.printing_commands

[ GitHub ]

  
# File 'railties/lib/rails/command/base.rb', line 72

def printing_commands
  namespaced_commands
end

.usage_path

Path to lookup a USAGE description in a file.

[ GitHub ]

  
# File 'railties/lib/rails/command/base.rb', line 109

def usage_path
  if default_command_root
    path = File.join(default_command_root, "USAGE")
    path if File.exist?(path)
  end
end

Instance Method Details

#help

[ GitHub ]

  
# File 'railties/lib/rails/command/base.rb', line 160

def help
  if command_name = self.class.command_name
    self.class.command_help(shell, command_name)
  else
    super
  end
end