W3cubDocs

/Ruby on Rails 5.1

class Rails::Command::Base

Parent:
Thor
Included modules:
Rails::Command::Actions

Public Class Methods

banner(*) Show source

Use Rails' default banner.

base_name() Show source

Sets the ::base_name taking into account the current class namespace.

Rails::Command::TestCommand.base_name # => 'rails'
# File railties/lib/rails/command/base.rb, line 82
def base_name
  @base_name ||= begin
    if base = name.to_s.split("::").first
      base.underscore
    end
  end
end
command_name() Show source

Return command name without namespaces.

Rails::Command::TestCommand.command_name # => 'test'
# File railties/lib/rails/command/base.rb, line 93
def command_name
  @command_name ||= begin
    if command = name.to_s.split("::").last
      command.chomp!("Command")
      command.underscore
    end
  end
end
default_command_root() Show source

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

For a `Rails::Command::TestCommand` placed in `rails/command/test_command.rb` would return `rails/test`.

# File railties/lib/rails/command/base.rb, line 115
def default_command_root
  path = File.expand_path(File.join("../commands", command_root_namespace), __dir__)
  path if File.exist?(path)
end
desc(usage = nil, description = nil, options = {}) Show source

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

Calls superclass method
# File railties/lib/rails/command/base.rb, line 25
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
engine?() Show source

Returns true when the app is a Rails engine.

# File railties/lib/rails/command/base.rb, line 19
def engine?
  defined?(ENGINE_ROOT)
end
executable() Show source
# File railties/lib/rails/command/base.rb, line 70
def executable
  "bin/rails #{command_name}"
end
hide_command!() Show source

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

# File railties/lib/rails/command/base.rb, line 46
def hide_command!
  Rails::Command.hidden_commands << self
end
namespace(name = nil) Show source

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

Calls superclass method
# File railties/lib/rails/command/base.rb, line 36
def namespace(name = nil)
  if name
    super
  else
    @namespace ||= super.chomp("_command").sub(/:command:/, ":")
  end
end
printing_commands() Show source
# File railties/lib/rails/command/base.rb, line 66
def printing_commands
  namespaced_commands
end
usage_path() Show source

Path to lookup a USAGE description in a file.

# File railties/lib/rails/command/base.rb, line 103
def usage_path
  if default_command_root
    path = File.join(default_command_root, "USAGE")
    path if File.exist?(path)
  end
end

Public Instance Methods

help() Show source
Calls superclass method
# File railties/lib/rails/command/base.rb, line 146
def help
  if command_name = self.class.command_name
    self.class.command_help(shell, command_name)
  else
    super
  end
end

© 2004–2017 David Heinemeier Hansson
Licensed under the MIT License.