aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/commands
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/commands')
-rw-r--r--railties/lib/rails/commands/application.rb4
-rw-r--r--railties/lib/rails/commands/commands_tasks.rb26
-rw-r--r--railties/lib/rails/commands/console.rb10
-rw-r--r--railties/lib/rails/commands/console_helper.rb12
-rw-r--r--railties/lib/rails/commands/dbconsole.rb90
-rw-r--r--railties/lib/rails/commands/destroy.rb4
-rw-r--r--railties/lib/rails/commands/generate.rb4
-rw-r--r--railties/lib/rails/commands/plugin.rb15
-rw-r--r--railties/lib/rails/commands/rake_proxy.rb15
-rw-r--r--railties/lib/rails/commands/runner.rb26
-rw-r--r--railties/lib/rails/commands/server.rb73
-rw-r--r--railties/lib/rails/commands/test.rb4
12 files changed, 146 insertions, 137 deletions
diff --git a/railties/lib/rails/commands/application.rb b/railties/lib/rails/commands/application.rb
index c998e6b6a8..f6e7771cf3 100644
--- a/railties/lib/rails/commands/application.rb
+++ b/railties/lib/rails/commands/application.rb
@@ -1,5 +1,5 @@
-require 'rails/generators'
-require 'rails/generators/rails/app/app_generator'
+require "rails/generators"
+require "rails/generators/rails/app/app_generator"
module Rails
module Generators
diff --git a/railties/lib/rails/commands/commands_tasks.rb b/railties/lib/rails/commands/commands_tasks.rb
index da3b9452d5..02f6472330 100644
--- a/railties/lib/rails/commands/commands_tasks.rb
+++ b/railties/lib/rails/commands/commands_tasks.rb
@@ -1,4 +1,4 @@
-require 'rails/commands/rake_proxy'
+require "rails/commands/rake_proxy"
module Rails
# This is a class which takes in a rails command and initiates the appropriate
@@ -30,9 +30,9 @@ In addition to those commands, there are:
EOT
ADDITIONAL_COMMANDS = [
- [ 'destroy', 'Undo code generated with "generate" (short-cut alias: "d")' ],
- [ 'plugin new', 'Generates skeleton for developing a Rails plugin' ],
- [ 'runner',
+ [ "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")' ]
]
@@ -69,7 +69,7 @@ EOT
options = Rails::Console.parse_arguments(argv)
# RAILS_ENV needs to be set before config/application is required
- ENV['RAILS_ENV'] = options[:environment] if options[:environment]
+ ENV["RAILS_ENV"] = options[:environment] if options[:environment]
# shift ARGV so IRB doesn't freak
shift_argv!
@@ -113,7 +113,7 @@ EOT
end
def version
- argv.unshift '--version'
+ argv.unshift "--version"
require_command!("application")
end
@@ -131,7 +131,7 @@ EOT
end
def shift_argv!
- argv.shift if argv.first && argv.first[0] != '-'
+ argv.shift if argv.first && argv.first[0] != "-"
end
def require_command!(command)
@@ -139,7 +139,7 @@ EOT
end
def generate_or_destroy(command)
- require 'rails/generators'
+ require "rails/generators"
require_application_and_environment!
Rails.application.load_generators
require_command!(command)
@@ -149,7 +149,7 @@ EOT
# This allows us to run `rails server` from other directories, but still get
# the main config.ru and properly set the tmp directory.
def set_application_directory!
- Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
+ Dir.chdir(File.expand_path("../../", APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
end
def require_application_and_environment!
@@ -168,10 +168,10 @@ EOT
def parse_command(command)
case command
- when '--version', '-v'
- 'version'
- when '--help', '-h'
- 'help'
+ when "--version", "-v"
+ "version"
+ when "--help", "-h"
+ "help"
else
command
end
diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb
index a4ab31f793..e00887323e 100644
--- a/railties/lib/rails/commands/console.rb
+++ b/railties/lib/rails/commands/console.rb
@@ -1,7 +1,7 @@
-require 'optparse'
-require 'irb'
-require 'irb/completion'
-require 'rails/commands/console_helper'
+require "optparse"
+require "irb"
+require "irb/completion"
+require "rails/commands/console_helper"
module Rails
class Console
@@ -21,7 +21,7 @@ module Rails
OptionParser.new do |opt|
opt.banner = "Usage: rails console [environment] [options]"
- opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |v| options[:sandbox] = v }
+ opt.on("-s", "--sandbox", "Rollback database modifications on exit.") { |v| options[:sandbox] = v }
opt.on("-e", "--environment=name", String,
"Specifies the environment to run this console under (test/development/production).",
"Default: development") { |v| options[:environment] = v.strip }
diff --git a/railties/lib/rails/commands/console_helper.rb b/railties/lib/rails/commands/console_helper.rb
index 8ee0b60012..0b7f1c4249 100644
--- a/railties/lib/rails/commands/console_helper.rb
+++ b/railties/lib/rails/commands/console_helper.rb
@@ -1,4 +1,4 @@
-require 'active_support/concern'
+require "active_support/concern"
module Rails
module ConsoleHelper # :nodoc:
@@ -8,10 +8,10 @@ module Rails
def start(*args)
new(*args).start
end
-
+
private
def set_options_env(arguments, options)
- if arguments.first && arguments.first[0] != '-'
+ if arguments.first && arguments.first[0] != "-"
env = arguments.first
if available_environments.include? env
options[:environment] = env
@@ -23,12 +23,12 @@ module Rails
end
def available_environments
- Dir['config/environments/*.rb'].map { |fname| File.basename(fname, '.*') }
- end
+ Dir["config/environments/*.rb"].map { |fname| File.basename(fname, ".*") }
+ end
end
def environment
ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
end
end
-end \ No newline at end of file
+end
diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb
index 2c36edfa3f..66b7a14f16 100644
--- a/railties/lib/rails/commands/dbconsole.rb
+++ b/railties/lib/rails/commands/dbconsole.rb
@@ -1,7 +1,7 @@
-require 'erb'
-require 'yaml'
-require 'optparse'
-require 'rails/commands/console_helper'
+require "erb"
+require "yaml"
+require "optparse"
+require "rails/commands/console_helper"
module Rails
class DBConsole
@@ -16,16 +16,16 @@ module Rails
OptionParser.new do |opt|
opt.banner = "Usage: rails dbconsole [environment] [options]"
opt.on("-p", "--include-password", "Automatically provide the password from database.yml") do |v|
- options['include_password'] = true
+ options["include_password"] = true
end
- opt.on("--mode [MODE]", ['html', 'list', 'line', 'column'],
+ opt.on("--mode [MODE]", ["html", "list", "line", "column"],
"Automatically put the sqlite3 database in the specified mode (html, list, line, column).") do |mode|
- options['mode'] = mode
+ options["mode"] = mode
end
opt.on("--header") do |h|
- options['header'] = h
+ options["header"] = h
end
opt.on("-h", "--help", "Show this help message.") do
@@ -52,70 +52,70 @@ module Rails
def start
options = self.class.parse_arguments(arguments)
- ENV['RAILS_ENV'] = options[:environment] || environment
+ ENV["RAILS_ENV"] = options[:environment] || environment
case config["adapter"]
when /^(jdbc)?mysql/
args = {
- 'host' => '--host',
- 'port' => '--port',
- 'socket' => '--socket',
- 'username' => '--user',
- 'encoding' => '--default-character-set',
- 'sslca' => '--ssl-ca',
- 'sslcert' => '--ssl-cert',
- 'sslcapath' => '--ssl-capath',
- 'sslcipher' => '--ssl-cipher',
- 'sslkey' => '--ssl-key'
+ "host" => "--host",
+ "port" => "--port",
+ "socket" => "--socket",
+ "username" => "--user",
+ "encoding" => "--default-character-set",
+ "sslca" => "--ssl-ca",
+ "sslcert" => "--ssl-cert",
+ "sslcapath" => "--ssl-capath",
+ "sslcipher" => "--ssl-cipher",
+ "sslkey" => "--ssl-key"
}.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
- if config['password'] && options['include_password']
+ if config["password"] && options["include_password"]
args << "--password=#{config['password']}"
- elsif config['password'] && !config['password'].to_s.empty?
+ elsif config["password"] && !config["password"].to_s.empty?
args << "-p"
end
- args << config['database']
+ args << config["database"]
- find_cmd_and_exec(['mysql', 'mysql5'], *args)
+ find_cmd_and_exec(["mysql", "mysql5"], *args)
when /^postgres|^postgis/
- ENV['PGUSER'] = config["username"] if config["username"]
- ENV['PGHOST'] = config["host"] if config["host"]
- ENV['PGPORT'] = config["port"].to_s if config["port"]
- ENV['PGPASSWORD'] = config["password"].to_s if config["password"] && options['include_password']
- find_cmd_and_exec('psql', config["database"])
+ ENV["PGUSER"] = config["username"] if config["username"]
+ ENV["PGHOST"] = config["host"] if config["host"]
+ ENV["PGPORT"] = config["port"].to_s if config["port"]
+ ENV["PGPASSWORD"] = config["password"].to_s if config["password"] && options["include_password"]
+ find_cmd_and_exec("psql", config["database"])
when "sqlite3"
args = []
- args << "-#{options['mode']}" if options['mode']
- args << "-header" if options['header']
- args << File.expand_path(config['database'], Rails.respond_to?(:root) ? Rails.root : nil)
+ args << "-#{options['mode']}" if options["mode"]
+ args << "-header" if options["header"]
+ args << File.expand_path(config["database"], Rails.respond_to?(:root) ? Rails.root : nil)
- find_cmd_and_exec('sqlite3', *args)
+ find_cmd_and_exec("sqlite3", *args)
when "oracle", "oracle_enhanced"
logon = ""
- if config['username']
- logon = config['username']
- logon << "/#{config['password']}" if config['password'] && options['include_password']
- logon << "@#{config['database']}" if config['database']
+ if config["username"]
+ logon = config["username"]
+ logon << "/#{config['password']}" if config["password"] && options["include_password"]
+ logon << "@#{config['database']}" if config["database"]
end
- find_cmd_and_exec('sqlplus', logon)
+ find_cmd_and_exec("sqlplus", logon)
when "sqlserver"
args = []
- args += ["-D", "#{config['database']}"] if config['database']
- args += ["-U", "#{config['username']}"] if config['username']
- args += ["-P", "#{config['password']}"] if config['password']
+ args += ["-D", "#{config['database']}"] if config["database"]
+ args += ["-U", "#{config['username']}"] if config["username"]
+ args += ["-P", "#{config['password']}"] if config["password"]
- if config['host']
+ if config["host"]
host_arg = "#{config['host']}"
- host_arg << ":#{config['port']}" if config['port']
+ host_arg << ":#{config['port']}" if config["port"]
args += ["-S", host_arg]
end
@@ -150,9 +150,9 @@ module Rails
def find_cmd_and_exec(commands, *args)
commands = Array(commands)
- dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR)
- unless (ext = RbConfig::CONFIG['EXEEXT']).empty?
- commands = commands.map{|cmd| "#{cmd}#{ext}"}
+ dirs_on_path = ENV["PATH"].to_s.split(File::PATH_SEPARATOR)
+ unless (ext = RbConfig::CONFIG["EXEEXT"]).empty?
+ commands = commands.map { |cmd| "#{cmd}#{ext}" }
end
full_path_command = nil
diff --git a/railties/lib/rails/commands/destroy.rb b/railties/lib/rails/commands/destroy.rb
index ce26cc3fde..71c8c5e526 100644
--- a/railties/lib/rails/commands/destroy.rb
+++ b/railties/lib/rails/commands/destroy.rb
@@ -1,9 +1,9 @@
-require 'rails/generators'
+require "rails/generators"
#if no argument/-h/--help is passed to rails destroy command, then
#it generates the help associated.
if [nil, "-h", "--help"].include?(ARGV.first)
- Rails::Generators.help 'destroy'
+ Rails::Generators.help "destroy"
exit
end
diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb
index 926c36b967..ba6f14073e 100644
--- a/railties/lib/rails/commands/generate.rb
+++ b/railties/lib/rails/commands/generate.rb
@@ -1,9 +1,9 @@
-require 'rails/generators'
+require "rails/generators"
#if no argument/-h/--help is passed to rails generate command, then
#it generates the help associated.
if [nil, "-h", "--help"].include?(ARGV.first)
- Rails::Generators.help 'generate'
+ Rails::Generators.help "generate"
exit
end
diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb
index 52d8966ead..60653a2cee 100644
--- a/railties/lib/rails/commands/plugin.rb
+++ b/railties/lib/rails/commands/plugin.rb
@@ -3,12 +3,13 @@ if ARGV.first != "new"
else
ARGV.shift
unless ARGV.delete("--no-rc")
- customrc = ARGV.index{ |x| x.include?("--rc=") }
+ customrc = ARGV.index { |x| x.include?("--rc=") }
railsrc = if customrc
- File.expand_path(ARGV.delete_at(customrc).gsub(/--rc=/, ""))
- else
- File.join(File.expand_path("~"), '.railsrc')
- end
+ File.expand_path(ARGV.delete_at(customrc).gsub(/--rc=/, ""))
+ else
+ File.join(File.expand_path("~"), ".railsrc")
+ end
+
if File.exist?(railsrc)
extra_args_string = File.read(railsrc)
extra_args = extra_args_string.split(/\n+/).flat_map(&:split)
@@ -18,6 +19,6 @@ else
end
end
-require 'rails/generators'
-require 'rails/generators/rails/plugin/plugin_generator'
+require "rails/generators"
+require "rails/generators/rails/plugin/plugin_generator"
Rails::Generators::PluginGenerator.start
diff --git a/railties/lib/rails/commands/rake_proxy.rb b/railties/lib/rails/commands/rake_proxy.rb
index f7d5df6b2f..b9e50f3e5a 100644
--- a/railties/lib/rails/commands/rake_proxy.rb
+++ b/railties/lib/rails/commands/rake_proxy.rb
@@ -1,20 +1,23 @@
-require 'rake'
-require 'active_support'
+require "active_support"
module Rails
module RakeProxy #:nodoc:
private
def run_rake_task(command)
+ require_rake
+
ARGV.unshift(command) # Prepend the command, so Rake knows how to run it.
Rake.application.standard_exception_handling do
- Rake.application.init('rails')
+ Rake.application.init("rails")
Rake.application.load_rakefile
Rake.application.top_level
end
end
def rake_tasks
+ require_rake
+
return @rake_tasks if defined?(@rake_tasks)
ActiveSupport::Deprecation.silence do
@@ -22,7 +25,7 @@ module Rails
end
Rake::TaskManager.record_task_metadata = true
- Rake.application.instance_variable_set(:@name, 'rails')
+ Rake.application.instance_variable_set(:@name, "rails")
Rails.application.load_tasks
@rake_tasks = Rake.application.tasks.select(&:comment)
end
@@ -30,5 +33,9 @@ module Rails
def formatted_rake_tasks
rake_tasks.map { |t| [ t.name_with_args, t.comment ] }
end
+
+ def require_rake
+ require "rake" # Defer booting Rake until we know it's needed.
+ end
end
end
diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb
index f9c183ac86..b74addf587 100644
--- a/railties/lib/rails/commands/runner.rb
+++ b/railties/lib/rails/commands/runner.rb
@@ -1,8 +1,8 @@
-require 'optparse'
+require "optparse"
-options = { environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup }
+options = { environment: (ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development").dup }
code_or_file = nil
-command = 'bin/rails runner'
+command = "bin/rails runner"
if ARGV.first.nil?
ARGV.push "-h"
@@ -22,16 +22,16 @@ ARGV.clone.options do |opts|
opts.on("-h", "--help",
"Show this help message.") { $stdout.puts opts; exit }
- opts.separator ""
- opts.separator "Examples: "
+ opts.separator ""
+ opts.separator "Examples: "
- opts.separator " rails runner 'puts Rails.env'"
- opts.separator " This runs the code `puts Rails.env` after loading the app"
- opts.separator ""
- opts.separator " rails runner path/to/filename.rb"
- opts.separator " This runs the Ruby file located at `path/to/filename.rb` after loading the app"
+ opts.separator " rails runner 'puts Rails.env'"
+ opts.separator " This runs the code `puts Rails.env` after loading the app"
+ opts.separator ""
+ opts.separator " rails runner path/to/filename.rb"
+ opts.separator " This runs the Ruby file located at `path/to/filename.rb` after loading the app"
- if RbConfig::CONFIG['host_os'] !~ /mswin|mingw/
+ if RbConfig::CONFIG["host_os"] !~ /mswin|mingw/
opts.separator ""
opts.separator "You can also use runner as a shebang line for your executables:"
opts.separator " -------------------------------------------------------------"
@@ -61,9 +61,11 @@ elsif File.exist?(code_or_file)
else
begin
eval(code_or_file, binding, __FILE__, __LINE__)
- rescue SyntaxError, NameError
+ rescue SyntaxError, NameError => e
$stderr.puts "Please specify a valid ruby command or the path of a script to run."
$stderr.puts "Run '#{command} -h' for help."
+ $stderr.puts
+ $stderr.puts e
exit 1
end
end
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb
index f641d9bf2c..0339849bfe 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -1,8 +1,8 @@
-require 'fileutils'
-require 'optparse'
-require 'action_dispatch'
-require 'rails'
-require 'rails/dev_caching'
+require "fileutils"
+require "optparse"
+require "action_dispatch"
+require "rails"
+require "rails/dev_caching"
module Rails
class Server < ::Rack::Server
@@ -21,31 +21,31 @@ module Rails
private
- def option_parser(options)
- OptionParser.new do |opts|
- opts.banner = "Usage: rails server [mongrel, thin etc] [options]"
- opts.on("-p", "--port=port", Integer,
- "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
- opts.on("-b", "--binding=IP", String,
- "Binds Rails to the specified IP.", "Default: localhost") { |v| options[:Host] = v }
- opts.on("-c", "--config=file", String,
- "Uses a custom rackup configuration.") { |v| options[:config] = v }
- opts.on("-d", "--daemon", "Runs server as a Daemon.") { options[:daemonize] = true }
- opts.on("-e", "--environment=name", String,
- "Specifies the environment to run this server under (test/development/production).",
- "Default: development") { |v| options[:environment] = v }
- opts.on("-P", "--pid=pid", String,
- "Specifies the PID file.",
- "Default: tmp/pids/server.pid") { |v| options[:pid] = v }
- opts.on("-C", "--[no-]dev-caching",
- "Specifies whether to perform caching in development.",
- "true or false") { |v| options[:caching] = v }
-
- opts.separator ""
-
- opts.on("-h", "--help", "Shows this help message.") { puts opts; exit }
+ def option_parser(options)
+ OptionParser.new do |opts|
+ opts.banner = "Usage: rails server [mongrel, thin etc] [options]"
+ opts.on("-p", "--port=port", Integer,
+ "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
+ opts.on("-b", "--binding=IP", String,
+ "Binds Rails to the specified IP.", "Default: localhost") { |v| options[:Host] = v }
+ opts.on("-c", "--config=file", String,
+ "Uses a custom rackup configuration.") { |v| options[:config] = v }
+ opts.on("-d", "--daemon", "Runs server as a Daemon.") { options[:daemonize] = true }
+ opts.on("-e", "--environment=name", String,
+ "Specifies the environment to run this server under (test/development/production).",
+ "Default: development") { |v| options[:environment] = v }
+ opts.on("-P", "--pid=pid", String,
+ "Specifies the PID file.",
+ "Default: tmp/pids/server.pid") { |v| options[:pid] = v }
+ opts.on("-C", "--[no-]dev-caching",
+ "Specifies whether to perform caching in development.",
+ "true or false") { |v| options[:caching] = v }
+
+ opts.separator ""
+
+ opts.on("-h", "--help", "Shows this help message.") { puts opts; exit }
+ end
end
- end
end
def initialize(*)
@@ -80,7 +80,7 @@ module Rails
ensure
# The '-h' option calls exit before @options is set.
# If we call 'options' with it unset, we get double help banners.
- puts 'Exiting' unless @options && options[:daemonize]
+ puts "Exiting" unless @options && options[:daemonize]
end
def middleware
@@ -88,16 +88,15 @@ module Rails
end
def default_options
- super.merge({
- Port: ENV.fetch('PORT', 3000).to_i,
- Host: ENV.fetch('HOST', 'localhost').dup,
+ super.merge(
+ Port: ENV.fetch("PORT", 3000).to_i,
+ Host: ENV.fetch("HOST", "localhost").dup,
DoNotReverseLookup: true,
- environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup,
+ environment: (ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development").dup,
daemonize: false,
caching: nil,
pid: Options::DEFAULT_PID_PATH,
- restart_cmd: restart_command
- })
+ restart_cmd: restart_command)
end
private
@@ -117,7 +116,7 @@ module Rails
def create_tmp_directories
%w(cache pids sockets).each do |dir_to_make|
- FileUtils.mkdir_p(File.join(Rails.root, 'tmp', dir_to_make))
+ FileUtils.mkdir_p(File.join(Rails.root, "tmp", dir_to_make))
end
end
diff --git a/railties/lib/rails/commands/test.rb b/railties/lib/rails/commands/test.rb
index dd069f081f..219c2fa4e0 100644
--- a/railties/lib/rails/commands/test.rb
+++ b/railties/lib/rails/commands/test.rb
@@ -1,9 +1,9 @@
require "rails/test_unit/minitest_plugin"
if defined?(ENGINE_ROOT)
- $: << File.expand_path('test', ENGINE_ROOT)
+ $: << File.expand_path("test", ENGINE_ROOT)
else
- $: << File.expand_path('../../test', APP_PATH)
+ $: << File.expand_path("../../test", APP_PATH)
end
exit Minitest.run(ARGV)