Class: Rails::Command::Base
- Inherits:
-
Thor
- Object
- Thor
- Rails::Command::Base
- Includes:
- Actions
- Defined in:
- lib/rails/command/base.rb
Direct Known Subclasses
ApplicationCommand, ConsoleCommand, DbconsoleCommand, DestroyCommand, GenerateCommand, HelpCommand, NewCommand, PluginCommand, RakeCommand, RunnerCommand, SecretsCommand, ServerCommand, TestCommand, VersionCommand
Defined Under Namespace
Classes: Error
Class Method Summary collapse
-
.banner ⇒ Object
Use Rails’ default banner.
-
.base_name ⇒ Object
Sets the base_name taking into account the current class namespace.
-
.command_name ⇒ Object
Return command name without namespaces.
-
.default_command_root ⇒ Object
Default file root to place extra files a command might need, placed one folder above the command file.
-
.desc(usage = nil, description = nil, options = {}) ⇒ Object
Tries to get the description from a USAGE file one folder above the command root.
-
.engine? ⇒ Boolean
Returns true when the app is a Rails engine.
- .executable ⇒ Object
-
.hide_command! ⇒ Object
Convenience method to hide this command from the available ones when running rails command.
-
.inherited(base) ⇒ Object
:nodoc:.
-
.namespace(name = nil) ⇒ Object
Convenience method to get the namespace from the class name.
-
.perform(command, args, config) ⇒ Object
:nodoc:.
- .printing_commands ⇒ Object
-
.usage_path ⇒ Object
Path to lookup a USAGE description in a file.
Instance Method Summary collapse
Methods included from Actions
#load_generators, #load_tasks, #require_application_and_environment!, #set_application_directory!
Class Method Details
.banner ⇒ Object
Use Rails’ default banner.
75 76 77 |
# File 'lib/rails/command/base.rb', line 75 def (*) "#{executable} #{arguments.map(&:usage).join(' ')} [options]".squish! end |
.base_name ⇒ Object
Sets the base_name taking into account the current class namespace.
Rails::Command::TestCommand.base_name # => 'rails'
82 83 84 85 86 87 88 |
# File '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 ⇒ Object
Return command name without namespaces.
Rails::Command::TestCommand.command_name # => 'test'
93 94 95 96 97 98 99 100 |
# File '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 ⇒ Object
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`.
115 116 117 118 |
# File 'lib/rails/command/base.rb', line 115 def default_command_root path = File.(File.join("../commands", command_root_namespace), __dir__) path if File.exist?(path) end |
.desc(usage = nil, description = nil, options = {}) ⇒ Object
Tries to get the description from a USAGE file one folder above the command root.
25 26 27 28 29 30 31 |
# File 'lib/rails/command/base.rb', line 25 def desc(usage = nil, description = nil, = {}) if usage super else @desc ||= ERB.new(File.read(usage_path)).result(binding) if usage_path end end |
.engine? ⇒ Boolean
Returns true when the app is a Rails engine.
19 20 21 |
# File 'lib/rails/command/base.rb', line 19 def engine? defined?(ENGINE_ROOT) end |
.executable ⇒ Object
70 71 72 |
# File 'lib/rails/command/base.rb', line 70 def executable "bin/rails #{command_name}" end |
.hide_command! ⇒ Object
Convenience method to hide this command from the available ones when running rails command.
46 47 48 |
# File 'lib/rails/command/base.rb', line 46 def hide_command! Rails::Command.hidden_commands << self end |
.inherited(base) ⇒ Object
:nodoc:
50 51 52 53 54 55 56 |
# File 'lib/rails/command/base.rb', line 50 def inherited(base) #:nodoc: super if base.name && base.name !~ /Base$/ Rails::Command.subclasses << base end end |
.namespace(name = nil) ⇒ Object
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.
36 37 38 39 40 41 42 |
# File 'lib/rails/command/base.rb', line 36 def namespace(name = nil) if name super else @namespace ||= super.chomp("_command").sub(/:command:/, ":") end end |
.perform(command, args, config) ⇒ Object
:nodoc:
58 59 60 61 62 63 64 |
# File 'lib/rails/command/base.rb', line 58 def perform(command, args, config) # :nodoc: if Rails::Command::HELP_MAPPINGS.include?(args.first) command, args = "help", [] end dispatch(command, args.dup, nil, config) end |
.printing_commands ⇒ Object
66 67 68 |
# File 'lib/rails/command/base.rb', line 66 def printing_commands namespaced_commands end |
.usage_path ⇒ Object
Path to lookup a USAGE description in a file.
103 104 105 106 107 108 |
# File '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 |
Instance Method Details
#help ⇒ Object
146 147 148 149 150 151 152 |
# File '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 |