Methods

Included Modules

Class Public methods

banner(command = nil, *)

πŸ“ Source code
# File railties/lib/rails/command/base.rb, line 86
        def banner(command = nil, *)
          if command
            # Similar to Thor's banner, but show the namespace (minus the
            # "rails:" prefix), and show the command's declared bin instead of
            # the command runner.
            command.formatted_usage(self).gsub(/^#{namespace}:(\w+)/) { executable($1) }
          else
            executable
          end
        end
πŸ”Ž See on GitHub

base_name()

Sets the base_name taking into account the current class namespace.

Rails::Command::TestCommand.base_name # => 'rails'
πŸ“ Source code
# File railties/lib/rails/command/base.rb, line 106
        def base_name
          @base_name ||= if base = name.to_s.split("::").first
            base.underscore
          end
        end
πŸ”Ž See on GitHub

command_name()

Return command name without namespaces.

Rails::Command::TestCommand.command_name # => 'test'
πŸ“ Source code
# File railties/lib/rails/command/base.rb, line 115
        def command_name
          @command_name ||= if command = name.to_s.split("::").last
            command.chomp!("Command")
            command.underscore
          end
        end
πŸ”Ž See on GitHub

default_command_root()

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 code
# File railties/lib/rails/command/base.rb, line 139
        def default_command_root
          @default_command_root = resolve_path(".") unless defined?(@default_command_root)
          @default_command_root
        end
πŸ”Ž See on GitHub

desc(usage = nil, description = nil, options = {})

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

πŸ“ Source code
# File railties/lib/rails/command/base.rb, line 34
        def desc(usage = nil, description = nil, options = {})
          if usage
            super
          else
            class_usage
          end
        end
πŸ”Ž See on GitHub

engine?()

Returns true when the app is a Rails engine.

πŸ“ Source code
# File railties/lib/rails/command/base.rb, line 28
        def engine?
          defined?(ENGINE_ROOT)
        end
πŸ”Ž See on GitHub

executable(command_name = self.command_name)

πŸ“ Source code
# File railties/lib/rails/command/base.rb, line 82
        def executable(command_name = self.command_name)
          "#{bin} #{namespaced_name(command_name)}"
        end
πŸ”Ž See on GitHub

hide_command!()

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

πŸ“ Source code
# File railties/lib/rails/command/base.rb, line 55
        def hide_command!
          Rails::Command.hidden_commands << self
        end
πŸ”Ž See on GitHub

namespace(name = nil)

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.

πŸ“ Source code
# File railties/lib/rails/command/base.rb, line 45
        def namespace(name = nil)
          if name
            super
          else
            @namespace ||= super.chomp("_command").sub(/:command:/, ":")
          end
        end
πŸ”Ž See on GitHub

printing_commands()

πŸ“ Source code
# File railties/lib/rails/command/base.rb, line 76
        def printing_commands
          commands.filter_map do |name, command|
            [namespaced_name(name), command.description] unless command.hidden?
          end
        end
πŸ”Ž See on GitHub

usage_path()

Path to lookup a USAGE description in a file.

πŸ“ Source code
# File railties/lib/rails/command/base.rb, line 129
        def usage_path
          @usage_path = resolve_path("USAGE") unless defined?(@usage_path)
          @usage_path
        end
πŸ”Ž See on GitHub