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/stats/stats_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, StatsCommand, 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:
110 111 112 |
# File 'lib/rails/command.rb', line 110 def application_root # :nodoc: Pathname.new(File.("../..", APP_PATH)) if defined?(APP_PATH) end |
.environment ⇒ Object
:nodoc:
51 52 53 |
# File 'lib/rails/command.rb', line 51 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"
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rails/command.rb', line 90 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:
47 48 49 |
# File 'lib/rails/command.rb', line 47 def hidden_commands # :nodoc: @hidden_commands ||= [] end |
.invoke(full_namespace, args = [], **config) ⇒ Object
Receives a namespace, arguments, and the behavior to invoke the command.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rails/command.rb', line 56 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:
114 115 116 117 118 |
# File 'lib/rails/command.rb', line 114 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.
102 103 104 105 106 107 108 |
# File 'lib/rails/command.rb', line 102 def root if defined?(ENGINE_ROOT) Pathname.new(ENGINE_ROOT) else application_root end end |