railties 5.0.7.2 → 5.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +77 -567
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +3 -3
- data/README.rdoc +1 -1
- data/exe/rails +2 -2
- data/lib/rails.rb +18 -18
- data/lib/rails/all.rb +1 -1
- data/lib/rails/api/generator.rb +28 -0
- data/lib/rails/api/task.rb +54 -42
- data/lib/rails/app_loader.rb +9 -9
- data/lib/rails/application.rb +30 -35
- data/lib/rails/application/bootstrap.rb +13 -7
- data/lib/rails/application/configuration.rb +30 -53
- data/lib/rails/application/default_middleware_stack.rb +3 -5
- data/lib/rails/application/finisher.rb +16 -7
- data/lib/rails/application/routes_reloader.rb +16 -1
- data/lib/rails/application_controller.rb +10 -10
- data/lib/rails/backtrace_cleaner.rb +5 -5
- data/lib/rails/cli.rb +7 -5
- data/lib/rails/code_statistics.rb +16 -17
- data/lib/rails/code_statistics_calculator.rb +3 -3
- data/lib/rails/command.rb +111 -0
- data/lib/rails/command/actions.rb +42 -0
- data/lib/rails/command/base.rb +149 -0
- data/lib/rails/command/behavior.rb +123 -0
- data/lib/rails/command/environment_argument.rb +34 -0
- data/lib/rails/commands.rb +2 -4
- data/lib/rails/commands/application/application_command.rb +29 -0
- data/lib/rails/commands/console/console_command.rb +89 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +155 -0
- data/lib/rails/commands/destroy/destroy_command.rb +21 -0
- data/lib/rails/commands/generate/generate_command.rb +23 -0
- data/lib/rails/commands/help/USAGE +15 -0
- data/lib/rails/commands/help/help_command.rb +13 -0
- data/lib/rails/commands/new/new_command.rb +15 -0
- data/lib/rails/commands/plugin/plugin_command.rb +43 -0
- data/lib/rails/commands/rake/rake_command.rb +49 -0
- data/lib/rails/commands/runner/USAGE +17 -0
- data/lib/rails/commands/runner/runner_command.rb +46 -0
- data/lib/rails/commands/secrets/USAGE +52 -0
- data/lib/rails/commands/secrets/secrets_command.rb +36 -0
- data/lib/rails/commands/server/server_command.rb +177 -0
- data/lib/rails/commands/test/test_command.rb +20 -0
- data/lib/rails/commands/version/version_command.rb +9 -0
- data/lib/rails/configuration.rb +7 -7
- data/lib/rails/console/app.rb +4 -4
- data/lib/rails/dev_caching.rb +8 -8
- data/lib/rails/engine.rb +62 -63
- data/lib/rails/engine/commands.rb +6 -13
- data/lib/rails/engine/configuration.rb +2 -2
- data/lib/rails/gem_version.rb +3 -3
- data/lib/rails/generators.rb +229 -313
- data/lib/rails/generators/actions.rb +20 -21
- data/lib/rails/generators/actions/create_migration.rb +24 -25
- data/lib/rails/generators/active_model.rb +3 -3
- data/lib/rails/generators/app_base.rb +123 -93
- data/lib/rails/generators/base.rb +32 -33
- data/lib/rails/generators/css/assets/assets_generator.rb +1 -1
- data/lib/rails/generators/erb.rb +14 -14
- data/lib/rails/generators/erb/controller/controller_generator.rb +1 -1
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +12 -12
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +3 -3
- data/lib/rails/generators/generated_attribute.rb +27 -27
- data/lib/rails/generators/js/assets/assets_generator.rb +1 -1
- data/lib/rails/generators/migration.rb +8 -8
- data/lib/rails/generators/model_helpers.rb +2 -2
- data/lib/rails/generators/named_base.rb +56 -56
- data/lib/rails/generators/rails/app/app_generator.rb +98 -81
- data/lib/rails/generators/rails/app/templates/Gemfile +7 -2
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -2
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +6 -4
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +2 -2
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/bin/{setup → setup.tt} +6 -0
- data/lib/rails/generators/rails/app/templates/bin/{update → update.tt} +2 -1
- data/lib/rails/generators/rails/app/templates/bin/yarn +9 -0
- data/lib/rails/generators/rails/app/templates/config/cable.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +2 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +4 -6
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +8 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt +6 -5
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +10 -0
- data/lib/rails/generators/rails/app/templates/config/puma.rb +16 -7
- data/lib/rails/generators/rails/app/templates/config/secrets.yml +12 -2
- data/lib/rails/generators/rails/app/templates/gitignore +5 -1
- data/lib/rails/generators/rails/app/templates/package.json +5 -0
- data/lib/rails/generators/rails/app/templates/public/404.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/422.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/500.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/robots.txt +0 -4
- data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb +5 -0
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb +0 -1
- data/lib/rails/generators/rails/assets/assets_generator.rb +10 -10
- data/lib/rails/generators/rails/controller/controller_generator.rb +15 -12
- data/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +66 -0
- data/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc +3 -0
- data/lib/rails/generators/rails/generator/generator_generator.rb +2 -3
- data/lib/rails/generators/rails/helper/helper_generator.rb +1 -1
- data/lib/rails/generators/rails/model/model_generator.rb +1 -1
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +21 -26
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -0
- data/lib/rails/generators/rails/plugin/templates/bin/test.tt +3 -9
- data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb +5 -0
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +0 -3
- data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +5 -1
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css +4 -8
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +2 -3
- data/lib/rails/generators/rails/system_test/USAGE +10 -0
- data/lib/rails/generators/rails/system_test/system_test_generator.rb +7 -0
- data/lib/rails/generators/rails/task/task_generator.rb +1 -2
- data/lib/rails/generators/resource_helpers.rb +13 -10
- data/lib/rails/generators/test_case.rb +5 -6
- data/lib/rails/generators/test_unit.rb +1 -1
- data/lib/rails/generators/test_unit/controller/controller_generator.rb +3 -3
- data/lib/rails/generators/test_unit/generator/generator_generator.rb +3 -3
- data/lib/rails/generators/test_unit/helper/helper_generator.rb +1 -1
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +2 -2
- data/lib/rails/generators/test_unit/job/job_generator.rb +3 -3
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +5 -5
- data/lib/rails/generators/test_unit/model/model_generator.rb +3 -4
- data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
- data/lib/rails/generators/test_unit/system/system_generator.rb +17 -0
- data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb +5 -0
- data/lib/rails/generators/test_unit/system/templates/system_test.rb +9 -0
- data/lib/rails/generators/testing/assertions.rb +4 -4
- data/lib/rails/generators/testing/behaviour.rb +20 -21
- data/lib/rails/info.rb +20 -20
- data/lib/rails/info_controller.rb +15 -15
- data/lib/rails/initializable.rb +6 -2
- data/lib/rails/mailers_controller.rb +11 -11
- data/lib/rails/paths.rb +4 -5
- data/lib/rails/plugin/test.rb +7 -0
- data/lib/rails/rack/logger.rb +44 -46
- data/lib/rails/railtie.rb +41 -38
- data/lib/rails/railtie/configurable.rb +6 -6
- data/lib/rails/railtie/configuration.rb +1 -1
- data/lib/rails/ruby_version_check.rb +1 -1
- data/lib/rails/secrets.rb +111 -0
- data/lib/rails/source_annotation_extractor.rb +15 -9
- data/lib/rails/tasks.rb +3 -2
- data/lib/rails/tasks/annotations.rake +3 -3
- data/lib/rails/tasks/dev.rake +2 -2
- data/lib/rails/tasks/engine.rake +4 -4
- data/lib/rails/tasks/framework.rake +4 -18
- data/lib/rails/tasks/initializers.rake +1 -1
- data/lib/rails/tasks/log.rake +14 -10
- data/lib/rails/tasks/middleware.rake +1 -1
- data/lib/rails/tasks/misc.rake +10 -10
- data/lib/rails/tasks/restart.rake +4 -4
- data/lib/rails/tasks/routes.rake +3 -12
- data/lib/rails/tasks/statistics.rake +3 -3
- data/lib/rails/tasks/tmp.rake +7 -7
- data/lib/rails/tasks/yarn.rake +11 -0
- data/lib/rails/templates/rails/mailers/email.html.erb +4 -1
- data/lib/rails/test_help.rb +28 -10
- data/lib/rails/test_unit/line_filtering.rb +69 -3
- data/lib/rails/test_unit/minitest_plugin.rb +139 -0
- data/lib/rails/test_unit/railtie.rb +2 -1
- data/lib/rails/test_unit/reporter.rb +3 -8
- data/lib/rails/test_unit/test_requirer.rb +28 -0
- data/lib/rails/test_unit/testing.rake +19 -14
- data/lib/rails/version.rb +1 -1
- data/lib/rails/welcome_controller.rb +1 -1
- metadata +53 -30
- data/lib/minitest/rails_plugin.rb +0 -49
- data/lib/rails/commands/application.rb +0 -17
- data/lib/rails/commands/commands_tasks.rb +0 -180
- data/lib/rails/commands/console.rb +0 -68
- data/lib/rails/commands/console_helper.rb +0 -34
- data/lib/rails/commands/dbconsole.rb +0 -173
- data/lib/rails/commands/destroy.rb +0 -11
- data/lib/rails/commands/generate.rb +0 -13
- data/lib/rails/commands/plugin.rb +0 -23
- data/lib/rails/commands/rake_proxy.rb +0 -41
- data/lib/rails/commands/runner.rb +0 -71
- data/lib/rails/commands/server.rb +0 -163
- data/lib/rails/commands/test.rb +0 -10
- data/lib/rails/engine/commands_tasks.rb +0 -118
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +0 -3
- data/lib/rails/rack/debugger.rb +0 -3
- data/lib/rails/test_unit/runner.rb +0 -141
@@ -0,0 +1,34 @@
|
|
1
|
+
require "active_support"
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Command
|
5
|
+
module EnvironmentArgument #:nodoc:
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
argument :environment, optional: true, banner: "environment"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def extract_environment_option_from_argument
|
14
|
+
if environment
|
15
|
+
self.options = options.merge(environment: acceptable_environment(environment))
|
16
|
+
elsif !options[:environment]
|
17
|
+
self.options = options.merge(environment: Rails::Command.environment)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def acceptable_environment(env = nil)
|
22
|
+
if available_environments.include? env
|
23
|
+
env
|
24
|
+
else
|
25
|
+
%w( production development test ).detect { |e| e =~ /^#{env}/ } || env
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def available_environments
|
30
|
+
Dir["config/environments/*.rb"].map { |fname| File.basename(fname, ".*") }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/rails/commands.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require "rails/command"
|
2
2
|
|
3
3
|
aliases = {
|
4
4
|
"g" => "generate",
|
@@ -13,6 +13,4 @@ aliases = {
|
|
13
13
|
command = ARGV.shift
|
14
14
|
command = aliases[command] || command
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
Rails::CommandsTasks.new(ARGV).run_command!(command)
|
16
|
+
Rails::Command.invoke command, ARGV
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
require "rails/generators/rails/app/app_generator"
|
3
|
+
|
4
|
+
module Rails
|
5
|
+
module Generators
|
6
|
+
class AppGenerator # :nodoc:
|
7
|
+
# We want to exit on failure to be kind to other libraries
|
8
|
+
# This is only when accessing via CLI
|
9
|
+
def self.exit_on_failure?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Command
|
16
|
+
class ApplicationCommand < Base # :nodoc:
|
17
|
+
hide_command!
|
18
|
+
|
19
|
+
def help
|
20
|
+
perform # Punt help output to the generator.
|
21
|
+
end
|
22
|
+
|
23
|
+
def perform(*args)
|
24
|
+
Rails::Generators::AppGenerator.start \
|
25
|
+
Rails::Generators::ARGVScrubber.new(args).prepare!
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "irb"
|
2
|
+
require "irb/completion"
|
3
|
+
|
4
|
+
require "rails/command/environment_argument"
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
class Console
|
8
|
+
module BacktraceCleaner
|
9
|
+
def filter_backtrace(bt)
|
10
|
+
if result = super
|
11
|
+
Rails.backtrace_cleaner.filter([result]).first
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.start(*args)
|
17
|
+
new(*args).start
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :options, :app, :console
|
21
|
+
|
22
|
+
def initialize(app, options = {})
|
23
|
+
@app = app
|
24
|
+
@options = options
|
25
|
+
|
26
|
+
app.sandbox = sandbox?
|
27
|
+
app.load_console
|
28
|
+
|
29
|
+
@console = app.config.console || IRB
|
30
|
+
|
31
|
+
if @console == IRB
|
32
|
+
IRB::WorkSpace.prepend(BacktraceCleaner)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def sandbox?
|
37
|
+
options[:sandbox]
|
38
|
+
end
|
39
|
+
|
40
|
+
def environment
|
41
|
+
options[:environment]
|
42
|
+
end
|
43
|
+
alias_method :environment?, :environment
|
44
|
+
|
45
|
+
def set_environment!
|
46
|
+
Rails.env = environment
|
47
|
+
end
|
48
|
+
|
49
|
+
def start
|
50
|
+
set_environment! if environment?
|
51
|
+
|
52
|
+
if sandbox?
|
53
|
+
puts "Loading #{Rails.env} environment in sandbox (Rails #{Rails.version})"
|
54
|
+
puts "Any modifications you make will be rolled back on exit"
|
55
|
+
else
|
56
|
+
puts "Loading #{Rails.env} environment (Rails #{Rails.version})"
|
57
|
+
end
|
58
|
+
|
59
|
+
if defined?(console::ExtendCommandBundle)
|
60
|
+
console::ExtendCommandBundle.include(Rails::ConsoleMethods)
|
61
|
+
end
|
62
|
+
console.start
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module Command
|
67
|
+
class ConsoleCommand < Base # :nodoc:
|
68
|
+
include EnvironmentArgument
|
69
|
+
|
70
|
+
class_option :sandbox, aliases: "-s", type: :boolean, default: false,
|
71
|
+
desc: "Rollback database modifications on exit."
|
72
|
+
|
73
|
+
class_option :environment, aliases: "-e", type: :string,
|
74
|
+
desc: "Specifies the environment to run this console under (test/development/production)."
|
75
|
+
|
76
|
+
def perform
|
77
|
+
extract_environment_option_from_argument
|
78
|
+
|
79
|
+
# RAILS_ENV needs to be set before config/application is required.
|
80
|
+
ENV["RAILS_ENV"] = options[:environment]
|
81
|
+
|
82
|
+
ARGV.clear # Clear ARGV so IRB doesn't freak.
|
83
|
+
|
84
|
+
require_application_and_environment!
|
85
|
+
Rails::Console.start(Rails.application, options)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require "rails/command/environment_argument"
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
class DBConsole
|
5
|
+
def self.start(*args)
|
6
|
+
new(*args).start
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def start
|
14
|
+
ENV["RAILS_ENV"] = @options[:environment] || environment
|
15
|
+
|
16
|
+
case config["adapter"]
|
17
|
+
when /^(jdbc)?mysql/
|
18
|
+
args = {
|
19
|
+
"host" => "--host",
|
20
|
+
"port" => "--port",
|
21
|
+
"socket" => "--socket",
|
22
|
+
"username" => "--user",
|
23
|
+
"encoding" => "--default-character-set",
|
24
|
+
"sslca" => "--ssl-ca",
|
25
|
+
"sslcert" => "--ssl-cert",
|
26
|
+
"sslcapath" => "--ssl-capath",
|
27
|
+
"sslcipher" => "--ssl-cipher",
|
28
|
+
"sslkey" => "--ssl-key"
|
29
|
+
}.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
|
30
|
+
|
31
|
+
if config["password"] && @options["include_password"]
|
32
|
+
args << "--password=#{config['password']}"
|
33
|
+
elsif config["password"] && !config["password"].to_s.empty?
|
34
|
+
args << "-p"
|
35
|
+
end
|
36
|
+
|
37
|
+
args << config["database"]
|
38
|
+
|
39
|
+
find_cmd_and_exec(["mysql", "mysql5"], *args)
|
40
|
+
|
41
|
+
when /^postgres|^postgis/
|
42
|
+
ENV["PGUSER"] = config["username"] if config["username"]
|
43
|
+
ENV["PGHOST"] = config["host"] if config["host"]
|
44
|
+
ENV["PGPORT"] = config["port"].to_s if config["port"]
|
45
|
+
ENV["PGPASSWORD"] = config["password"].to_s if config["password"] && @options["include_password"]
|
46
|
+
find_cmd_and_exec("psql", config["database"])
|
47
|
+
|
48
|
+
when "sqlite3"
|
49
|
+
args = []
|
50
|
+
|
51
|
+
args << "-#{@options['mode']}" if @options["mode"]
|
52
|
+
args << "-header" if @options["header"]
|
53
|
+
args << File.expand_path(config["database"], Rails.respond_to?(:root) ? Rails.root : nil)
|
54
|
+
|
55
|
+
find_cmd_and_exec("sqlite3", *args)
|
56
|
+
|
57
|
+
when "oracle", "oracle_enhanced"
|
58
|
+
logon = ""
|
59
|
+
|
60
|
+
if config["username"]
|
61
|
+
logon = config["username"]
|
62
|
+
logon << "/#{config['password']}" if config["password"] && @options["include_password"]
|
63
|
+
logon << "@#{config['database']}" if config["database"]
|
64
|
+
end
|
65
|
+
|
66
|
+
find_cmd_and_exec("sqlplus", logon)
|
67
|
+
|
68
|
+
when "sqlserver"
|
69
|
+
args = []
|
70
|
+
|
71
|
+
args += ["-D", "#{config['database']}"] if config["database"]
|
72
|
+
args += ["-U", "#{config['username']}"] if config["username"]
|
73
|
+
args += ["-P", "#{config['password']}"] if config["password"]
|
74
|
+
|
75
|
+
if config["host"]
|
76
|
+
host_arg = "#{config['host']}"
|
77
|
+
host_arg << ":#{config['port']}" if config["port"]
|
78
|
+
args += ["-S", host_arg]
|
79
|
+
end
|
80
|
+
|
81
|
+
find_cmd_and_exec("sqsh", *args)
|
82
|
+
|
83
|
+
else
|
84
|
+
abort "Unknown command-line client for #{config['database']}."
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def config
|
89
|
+
@config ||= begin
|
90
|
+
if configurations[environment].blank?
|
91
|
+
raise ActiveRecord::AdapterNotSpecified, "'#{environment}' database is not configured. Available configuration: #{configurations.inspect}"
|
92
|
+
else
|
93
|
+
configurations[environment]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def environment
|
99
|
+
Rails.respond_to?(:env) ? Rails.env : Rails::Command.environment
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
def configurations # :doc:
|
104
|
+
require APP_PATH
|
105
|
+
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
|
106
|
+
ActiveRecord::Base.configurations
|
107
|
+
end
|
108
|
+
|
109
|
+
def find_cmd_and_exec(commands, *args) # :doc:
|
110
|
+
commands = Array(commands)
|
111
|
+
|
112
|
+
dirs_on_path = ENV["PATH"].to_s.split(File::PATH_SEPARATOR)
|
113
|
+
unless (ext = RbConfig::CONFIG["EXEEXT"]).empty?
|
114
|
+
commands = commands.map { |cmd| "#{cmd}#{ext}" }
|
115
|
+
end
|
116
|
+
|
117
|
+
full_path_command = nil
|
118
|
+
found = commands.detect do |cmd|
|
119
|
+
dirs_on_path.detect do |path|
|
120
|
+
full_path_command = File.join(path, cmd)
|
121
|
+
File.file?(full_path_command) && File.executable?(full_path_command)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
if found
|
126
|
+
exec full_path_command, *args
|
127
|
+
else
|
128
|
+
abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
module Command
|
134
|
+
class DbconsoleCommand < Base # :nodoc:
|
135
|
+
include EnvironmentArgument
|
136
|
+
|
137
|
+
class_option :include_password, aliases: "-p", type: :boolean,
|
138
|
+
desc: "Automatically provide the password from database.yml"
|
139
|
+
|
140
|
+
class_option :mode, enum: %w( html list line column ), type: :string,
|
141
|
+
desc: "Automatically put the sqlite3 database in the specified mode (html, list, line, column)."
|
142
|
+
|
143
|
+
class_option :header, type: :string
|
144
|
+
|
145
|
+
class_option :environment, aliases: "-e", type: :string,
|
146
|
+
desc: "Specifies the environment to run this console under (test/development/production)."
|
147
|
+
|
148
|
+
def perform
|
149
|
+
extract_environment_option_from_argument
|
150
|
+
|
151
|
+
Rails::DBConsole.start(options)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Command
|
5
|
+
class DestroyCommand < Base # :nodoc:
|
6
|
+
def help
|
7
|
+
Rails::Generators.help self.class.command_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def perform(*)
|
11
|
+
generator = args.shift
|
12
|
+
return help unless generator
|
13
|
+
|
14
|
+
require_application_and_environment!
|
15
|
+
Rails.application.load_generators
|
16
|
+
|
17
|
+
Rails::Generators.invoke generator, args, behavior: :revoke, destination_root: Rails.root
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Command
|
5
|
+
class GenerateCommand < Base # :nodoc:
|
6
|
+
def help
|
7
|
+
Rails::Generators.help self.class.command_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def perform(*)
|
11
|
+
generator = args.shift
|
12
|
+
return help unless generator
|
13
|
+
|
14
|
+
require_application_and_environment!
|
15
|
+
load_generators
|
16
|
+
|
17
|
+
ARGV.shift
|
18
|
+
|
19
|
+
Rails::Generators.invoke generator, args, behavior: :invoke, destination_root: Rails::Command.root
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
The most common rails commands are:
|
2
|
+
generate Generate new code (short-cut alias: "g")
|
3
|
+
console Start the Rails console (short-cut alias: "c")
|
4
|
+
server Start the Rails server (short-cut alias: "s")
|
5
|
+
test Run tests (short-cut alias: "t")
|
6
|
+
dbconsole Start a console for the database specified in config/database.yml
|
7
|
+
(short-cut alias: "db")
|
8
|
+
<% unless engine? %>
|
9
|
+
new Create a new Rails application. "rails new my_app" creates a
|
10
|
+
new application called MyApp in "./my_app"
|
11
|
+
<% end %>
|
12
|
+
|
13
|
+
All commands can be run with -h (or --help) for more information.
|
14
|
+
In addition to those commands, there are:
|
15
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Rails
|
2
|
+
module Command
|
3
|
+
class NewCommand < Base # :nodoc:
|
4
|
+
def help
|
5
|
+
Rails::Command.invoke :application, [ "--help" ]
|
6
|
+
end
|
7
|
+
|
8
|
+
def perform(*)
|
9
|
+
puts "Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.\n"
|
10
|
+
puts "Type 'rails' for help."
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Rails
|
2
|
+
module Command
|
3
|
+
class PluginCommand < Base # :nodoc:
|
4
|
+
hide_command!
|
5
|
+
|
6
|
+
def help
|
7
|
+
run_plugin_generator %w( --help )
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.banner(*) # :nodoc:
|
11
|
+
"#{executable} new [options]"
|
12
|
+
end
|
13
|
+
|
14
|
+
class_option :rc, type: :string, default: File.join("~", ".railsrc"),
|
15
|
+
desc: "Initialize the plugin command with previous defaults. Uses .railsrc in your home directory by default."
|
16
|
+
|
17
|
+
class_option :no_rc, desc: "Skip evaluating .railsrc."
|
18
|
+
|
19
|
+
def perform(type = nil, *plugin_args)
|
20
|
+
plugin_args << "--help" unless type == "new"
|
21
|
+
|
22
|
+
unless options.key?("no_rc") # Thor's not so indifferent access hash.
|
23
|
+
railsrc = File.expand_path(options[:rc])
|
24
|
+
|
25
|
+
if File.exist?(railsrc)
|
26
|
+
extra_args = File.read(railsrc).split(/\n+/).flat_map(&:split)
|
27
|
+
puts "Using #{extra_args.join(" ")} from #{railsrc}"
|
28
|
+
plugin_args.insert(1, *extra_args)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
run_plugin_generator plugin_args
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def run_plugin_generator(plugin_args)
|
37
|
+
require "rails/generators"
|
38
|
+
require "rails/generators/rails/plugin/plugin_generator"
|
39
|
+
Rails::Generators::PluginGenerator.start plugin_args
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|