class Rails::Command::Base
Public Class Methods
Source
# File lib/rails/command/base.rb, line 104 def base_name @base_name ||= if base = name.to_s.split("::").first base.underscore end end
Sets the base_name taking into account the current class namespace.
Rails::Command::TestCommand.base_name # => 'rails'
Source
# File lib/rails/command/base.rb, line 113 def command_name @command_name ||= if command = name.to_s.split("::").last command.chomp!("Command") command.underscore end end
Return command name without namespaces.
Rails::Command::TestCommand.command_name # => 'test'
Source
# File lib/rails/command/base.rb, line 137 def default_command_root @default_command_root = resolve_path(".") unless defined?(@default_command_root) @default_command_root 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.
Source
# File lib/rails/command/base.rb, line 32 def desc(usage = nil, description = nil, options = {}) if usage super else class_usage end end
Tries to get the description from a USAGE file one folder above the command root.
Calls superclass method
Source
# File lib/rails/command/base.rb, line 26 def engine? defined?(ENGINE_ROOT) end
Returns true when the app is a Rails engine.
Source
# File lib/rails/command/base.rb, line 80 def executable(command_name = self.command_name) "#{bin} #{namespaced_name(command_name)}" end
Source
# File lib/rails/command/base.rb, line 53 def hide_command! Rails::Command.hidden_commands << self end
Convenience method to hide this command from the available ones when running rails command.
Source
# File lib/rails/command/base.rb, line 43 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.
Calls superclass method
Source
# File lib/rails/command/base.rb, line 74 def printing_commands commands.filter_map do |name, command| [namespaced_name(name), command.description] unless command.hidden? end end
Source
# File lib/rails/command/base.rb, line 127 def usage_path @usage_path = resolve_path("USAGE") unless defined?(@usage_path) @usage_path end
Path to lookup a USAGE description in a file.