class Rails::Command::Base
Public Class Methods
# File railties/lib/rails/command/base.rb, line 77 def banner(*) "#{executable} #{arguments.map(&:usage).join(' ')} [options]".squish end
Use Rails' default banner.
# 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
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 95 def command_name @command_name ||= begin if command = name.to_s.split("::").last command.chomp!("Command") command.underscore end end end
Return command name without namespaces.
Rails::Command::TestCommand.command_name # => 'test'
# File railties/lib/rails/command/base.rb, line 117 def default_command_root path = File.expand_path(relative_command_path, __dir__) path if File.exist?(path) end
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 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
Tries to get the description from a USAGE file one folder above the command root.
# File railties/lib/rails/command/base.rb, line 21 def engine? defined?(ENGINE_ROOT) end
Returns true when the app is a Rails engine.
# File railties/lib/rails/command/base.rb, line 72 def executable "rails #{command_name}" end
# File railties/lib/rails/command/base.rb, line 48 def hide_command! Rails::Command.hidden_commands << self end
Convenience method to hide this command from the available ones when running rails command.
# 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
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.
# File railties/lib/rails/command/base.rb, line 68 def printing_commands namespaced_commands end
# 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
Path to lookup a USAGE description in a file.
Public Instance Methods
# File railties/lib/rails/command/base.rb, line 156 def help if command_name = self.class.command_name self.class.command_help(shell, command_name) else super end end
© 2004–2019 David Heinemeier Hansson
Licensed under the MIT License.