class Quails::Command::Base

Public Class Methods

banner(*) click to toggle source

Use Quails' default banner.

base_name() click to toggle source

Sets the base_name taking into account the current class namespace.

Quails::Command::TestCommand.base_name # => 'quails'
# File railties/lib/rails/command/base.rb, line 84
def base_name
  @base_name ||= begin
    if base = name.to_s.split("::").first
      base.underscore
    end
  end
end
command_name() click to toggle source

Return command name without namespaces.

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

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

For a Quails::Command::TestCommand placed in quails/command/test_command.rb would return quails/test.

# File railties/lib/rails/command/base.rb, line 117
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 = {}) click to toggle 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 27
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?() click to toggle source

Returns true when the app is a Quails engine.

# File railties/lib/rails/command/base.rb, line 21
def engine?
  defined?(ENGINE_ROOT)
end
executable() click to toggle source
# File railties/lib/rails/command/base.rb, line 72
def executable
  "bin/quails #{command_name}"
end
hide_command!() click to toggle source

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

# File railties/lib/rails/command/base.rb, line 48
def hide_command!
  Quails::Command.hidden_commands << self
end
namespace(name = nil) click to toggle 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 38
def namespace(name = nil)
  if name
    super
  else
    @namespace ||= super.chomp("_command").sub(/:command:/, ":")
  end
end
printing_commands() click to toggle source
# File railties/lib/rails/command/base.rb, line 68
def printing_commands
  namespaced_commands
end
usage_path() click to toggle source

Path to lookup a USAGE description in a file.

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

Private Class Methods

command_root_namespace() click to toggle source
# File railties/lib/rails/command/base.rb, line 137
def command_root_namespace
  (namespace.split(":") - %w( quails )).first
end
create_command(meth) click to toggle source

Allow the command method to be called perform.

Calls superclass method
# File railties/lib/rails/command/base.rb, line 124
def create_command(meth)
  if meth == "perform"
    alias_method command_name, meth
  else
    # Prevent exception about command without usage.
    # Some commands define their documentation differently.
    @usage ||= ""
    @desc  ||= ""

    super
  end
end
namespaced_commands() click to toggle source
# File railties/lib/rails/command/base.rb, line 141
def namespaced_commands
  commands.keys.map do |key|
    key == command_root_namespace ? key : "#{command_root_namespace}:#{key}"
  end
end

Public Instance Methods

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