Module: Rails::Command
- Extended by:
- ActiveSupport::Autoload
- Includes:
- Behavior
- Defined in:
- lib/rails/command.rb,
lib/rails/command/base.rb,
lib/rails/command/actions.rb,
lib/rails/command/behavior.rb,
lib/rails/command/helpers/editor.rb,
lib/rails/commands/dev/dev_command.rb,
lib/rails/commands/new/new_command.rb,
lib/rails/commands/boot/boot_command.rb,
lib/rails/commands/help/help_command.rb,
lib/rails/commands/rake/rake_command.rb,
lib/rails/commands/test/test_command.rb,
lib/rails/commands/app/update_command.rb,
lib/rails/command/environment_argument.rb,
lib/rails/commands/about/about_command.rb,
lib/rails/commands/notes/notes_command.rb,
lib/rails/commands/plugin/plugin_command.rb,
lib/rails/commands/routes/routes_command.rb,
lib/rails/commands/runner/runner_command.rb,
lib/rails/commands/secret/secret_command.rb,
lib/rails/commands/server/server_command.rb,
lib/rails/commands/console/console_command.rb,
lib/rails/commands/destroy/destroy_command.rb,
lib/rails/commands/restart/restart_command.rb,
lib/rails/commands/version/version_command.rb,
lib/rails/commands/gem_help/gem_help_command.rb,
lib/rails/commands/generate/generate_command.rb,
lib/rails/commands/dbconsole/dbconsole_command.rb,
lib/rails/commands/encrypted/encrypted_command.rb,
lib/rails/commands/middleware/middleware_command.rb,
lib/rails/commands/application/application_command.rb,
lib/rails/commands/credentials/credentials_command.rb,
lib/rails/commands/db/system/change/change_command.rb,
lib/rails/commands/devcontainer/devcontainer_command.rb,
lib/rails/commands/initializers/initializers_command.rb,
lib/rails/commands/unused_routes/unused_routes_command.rb
Defined Under Namespace
Modules: Actions, App, Behavior, Db, EnvironmentArgument, Helpers Classes: AboutCommand, ApplicationCommand, Base, BootCommand, ConsoleCommand, CorrectableNameError, CredentialsCommand, DbconsoleCommand, DestroyCommand, DevCommand, DevcontainerCommand, EncryptedCommand, GemHelpCommand, GenerateCommand, HelpCommand, InitializersCommand, MiddlewareCommand, NewCommand, NotesCommand, PluginCommand, RakeCommand, RestartCommand, RoutesCommand, RunnerCommand, SecretCommand, ServerCommand, TestCommand, UnrecognizedCommandError, UnusedRoutesCommand, VersionCommand
Constant Summary collapse
- HELP_MAPPINGS =
%w(-h -? --help).to_set
- VERSION_MAPPINGS =
%w(-v --version).to_set
Class Method Summary collapse
-
.application_root ⇒ Object
:nodoc:.
-
.environment ⇒ Object
:nodoc:.
-
.find_by_namespace(namespace, command_name = nil) ⇒ Object
Rails finds namespaces similar to Thor, it only adds one rule:.
-
.hidden_commands ⇒ Object
:nodoc:.
-
.invoke(full_namespace, args = [], **config) ⇒ Object
Receives a namespace, arguments, and the behavior to invoke the command.
-
.printing_commands ⇒ Object
:nodoc:.
-
.root ⇒ Object
Returns the root of the Rails engine or app running the command.
Class Method Details
.application_root ⇒ Object
:nodoc:
116 117 118 |
# File 'lib/rails/command.rb', line 116 def application_root # :nodoc: Pathname.new(File.("../..", APP_PATH)) if defined?(APP_PATH) end |
.environment ⇒ Object
:nodoc:
57 58 59 |
# File 'lib/rails/command.rb', line 57 def environment # :nodoc: ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || "development" end |
.find_by_namespace(namespace, command_name = nil) ⇒ Object
Rails finds namespaces similar to Thor, it only adds one rule:
Command names must end with “_command.rb”. This is required because Rails looks in load paths and loads the command just before it’s going to be used.
find_by_namespace :webrat, :integration
Will search for the following commands:
"webrat", "webrat:integration", "rails:webrat", "rails:webrat:integration"
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rails/command.rb', line 96 def find_by_namespace(namespace, command_name = nil) # :nodoc: lookups = [ namespace ] lookups << "#{namespace}:#{command_name}" if command_name lookups.concat lookups.map { |lookup| "rails:#{lookup}" } lookup(lookups) namespaces = subclasses.index_by(&:namespace) namespaces[(lookups & namespaces.keys).first] end |
.hidden_commands ⇒ Object
:nodoc:
53 54 55 |
# File 'lib/rails/command.rb', line 53 def hidden_commands # :nodoc: @hidden_commands ||= [] end |
.invoke(full_namespace, args = [], **config) ⇒ Object
Receives a namespace, arguments, and the behavior to invoke the command.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rails/command.rb', line 62 def invoke(full_namespace, args = [], **config) args = ["--help"] if rails_new_with_no_path?(args) full_namespace = full_namespace.to_s namespace, command_name = split_namespace(full_namespace) command = find_by_namespace(namespace, command_name) with_argv(args) do if command && command.all_commands[command_name] command.perform(command_name, args, config) else invoke_rake(full_namespace, args, config) end end rescue UnrecognizedCommandError => error if error.name == full_namespace && command && command_name == full_namespace command.perform("help", [], config) else puts error. end exit(1) end |
.printing_commands ⇒ Object
:nodoc:
120 121 122 123 124 |
# File 'lib/rails/command.rb', line 120 def printing_commands # :nodoc: lookup! (subclasses - hidden_commands).flat_map(&:printing_commands) end |
.root ⇒ Object
Returns the root of the Rails engine or app running the command.
108 109 110 111 112 113 114 |
# File 'lib/rails/command.rb', line 108 def root if defined?(ENGINE_ROOT) Pathname.new(ENGINE_ROOT) else application_root end end |