Class: Rails::CommandsTasks
- Inherits:
-
Object
- Object
- Rails::CommandsTasks
- Defined in:
- lib/rails/commands/commands_tasks.rb
Overview
This is a class which takes in a rails command and initiates the appropriate initiation sequence.
Warning: This class mutates ARGV because some commands require manipulating it before they are run.
Constant Summary collapse
- HELP_MESSAGE =
<<-EOT Usage: rails COMMAND [ARGS] The most common rails commands are: generate Generate new code (short-cut alias: "g") console Start the Rails console (short-cut alias: "c") server Start the Rails server (short-cut alias: "s") dbconsole Start a console for the database specified in config/database.yml (short-cut alias: "db") new Create a new Rails application. "rails new my_app" creates a new application called MyApp in "./my_app" In addition to those, there are: destroy Undo code generated with "generate" (short-cut alias: "d") plugin new Generates skeleton for developing a Rails plugin runner Run a piece of code in the application environment (short-cut alias: "r") All commands can be run with -h (or --help) for more information. EOT
- COMMAND_WHITELIST =
%w(plugin generate destroy console server dbconsole runner new version help)
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
- #console ⇒ Object
- #dbconsole ⇒ Object
- #destroy ⇒ Object
- #generate ⇒ Object
- #help ⇒ Object
-
#initialize(argv) ⇒ CommandsTasks
constructor
A new instance of CommandsTasks.
- #new ⇒ Object
- #plugin ⇒ Object
- #run_command!(command) ⇒ Object
- #runner ⇒ Object
- #server ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(argv) ⇒ CommandsTasks
Returns a new instance of CommandsTasks.
32 33 34 |
# File 'lib/rails/commands/commands_tasks.rb', line 32 def initialize(argv) @argv = argv end |
Instance Attribute Details
#argv ⇒ Object (readonly)
:nodoc:
8 9 10 |
# File 'lib/rails/commands/commands_tasks.rb', line 8 def argv @argv end |
Instance Method Details
#console ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rails/commands/commands_tasks.rb', line 57 def console require_command!("console") = Rails::Console.parse_arguments(argv) # RAILS_ENV needs to be set before config/application is required ENV['RAILS_ENV'] = [:environment] if [:environment] # shift ARGV so IRB doesn't freak shift_argv! require_application_and_environment! Rails::Console.start(Rails.application, ) end |
#dbconsole ⇒ Object
84 85 86 87 |
# File 'lib/rails/commands/commands_tasks.rb', line 84 def dbconsole require_command!("dbconsole") Rails::DBConsole.start end |
#destroy ⇒ Object
53 54 55 |
# File 'lib/rails/commands/commands_tasks.rb', line 53 def destroy generate_or_destroy(:destroy) end |
#generate ⇒ Object
49 50 51 |
# File 'lib/rails/commands/commands_tasks.rb', line 49 def generate generate_or_destroy(:generate) end |
#help ⇒ Object
106 107 108 |
# File 'lib/rails/commands/commands_tasks.rb', line 106 def help end |
#new ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/rails/commands/commands_tasks.rb', line 93 def new if %w(-h --help).include?(argv.first) require_command!("application") else exit_with_initialization_warning! end end |
#plugin ⇒ Object
45 46 47 |
# File 'lib/rails/commands/commands_tasks.rb', line 45 def plugin require_command!("plugin") end |
#run_command!(command) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/rails/commands/commands_tasks.rb', line 36 def run_command!(command) command = parse_command(command) if COMMAND_WHITELIST.include?(command) send(command) else (command) end end |
#runner ⇒ Object
89 90 91 |
# File 'lib/rails/commands/commands_tasks.rb', line 89 def runner require_command!("runner") end |
#server ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rails/commands/commands_tasks.rb', line 71 def server set_application_directory! require_command!("server") Rails::Server.new.tap do |server| # We need to require application after the server sets environment, # otherwise the --environment option given to the server won't propagate. require APP_PATH Dir.chdir(Rails.application.root) server.start end end |
#version ⇒ Object
101 102 103 104 |
# File 'lib/rails/commands/commands_tasks.rb', line 101 def version argv.unshift '--version' require_command!("application") end |