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,49 @@
|
|
1
|
+
module Rails
|
2
|
+
module Command
|
3
|
+
class RakeCommand < Base # :nodoc:
|
4
|
+
extend Rails::Command::Actions
|
5
|
+
|
6
|
+
namespace "rake"
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def printing_commands
|
10
|
+
formatted_rake_tasks.map(&:first)
|
11
|
+
end
|
12
|
+
|
13
|
+
def perform(task, *)
|
14
|
+
require_rake
|
15
|
+
|
16
|
+
ARGV.unshift(task) # Prepend the task, so Rake knows how to run it.
|
17
|
+
|
18
|
+
Rake.application.standard_exception_handling do
|
19
|
+
Rake.application.init("rails")
|
20
|
+
Rake.application.load_rakefile
|
21
|
+
Rake.application.top_level
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def rake_tasks
|
27
|
+
require_rake
|
28
|
+
|
29
|
+
return @rake_tasks if defined?(@rake_tasks)
|
30
|
+
|
31
|
+
require_application_and_environment!
|
32
|
+
|
33
|
+
Rake::TaskManager.record_task_metadata = true
|
34
|
+
Rake.application.instance_variable_set(:@name, "rails")
|
35
|
+
load_tasks
|
36
|
+
@rake_tasks = Rake.application.tasks.select(&:comment)
|
37
|
+
end
|
38
|
+
|
39
|
+
def formatted_rake_tasks
|
40
|
+
rake_tasks.map { |t| [ t.name_with_args, t.comment ] }
|
41
|
+
end
|
42
|
+
|
43
|
+
def require_rake
|
44
|
+
require "rake" # Defer booting Rake until we know it's needed.
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Examples:
|
2
|
+
|
3
|
+
Run `puts Rails.env` after loading the app:
|
4
|
+
|
5
|
+
<%= executable %> 'puts Rails.env'
|
6
|
+
|
7
|
+
Run the Ruby file located at `path/to/filename.rb` after loading the app:
|
8
|
+
|
9
|
+
<%= executable %> path/to/filename.rb
|
10
|
+
|
11
|
+
<% unless Gem.win_platform? %>
|
12
|
+
You can also use the runner command as a shebang line for your executables:
|
13
|
+
|
14
|
+
#!/usr/bin/env <%= File.expand_path(executable) %>
|
15
|
+
|
16
|
+
Product.all.each { |p| p.price *= 2 ; p.save! }
|
17
|
+
<% end %>
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Rails
|
2
|
+
module Command
|
3
|
+
class RunnerCommand < Base # :nodoc:
|
4
|
+
class_option :environment, aliases: "-e", type: :string,
|
5
|
+
default: Rails::Command.environment.dup,
|
6
|
+
desc: "The environment for the runner to operate under (test/development/production)"
|
7
|
+
|
8
|
+
def help
|
9
|
+
super
|
10
|
+
puts self.class.desc
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.banner(*)
|
14
|
+
"#{super} [<'Some.ruby(code)'> | <filename.rb>]"
|
15
|
+
end
|
16
|
+
|
17
|
+
def perform(code_or_file = nil, *file_argv)
|
18
|
+
unless code_or_file
|
19
|
+
help
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
|
23
|
+
ENV["RAILS_ENV"] = options[:environment]
|
24
|
+
|
25
|
+
require_application_and_environment!
|
26
|
+
Rails.application.load_runner
|
27
|
+
|
28
|
+
if File.exist?(code_or_file)
|
29
|
+
$0 = code_or_file
|
30
|
+
ARGV.replace(file_argv)
|
31
|
+
Kernel.load code_or_file
|
32
|
+
else
|
33
|
+
begin
|
34
|
+
eval(code_or_file, binding, __FILE__, __LINE__)
|
35
|
+
rescue SyntaxError, NameError => error
|
36
|
+
$stderr.puts "Please specify a valid ruby command or the path of a script to run."
|
37
|
+
$stderr.puts "Run '#{self.class.executable} -h' for help."
|
38
|
+
$stderr.puts
|
39
|
+
$stderr.puts error
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
=== Storing Encrypted Secrets in Source Control
|
2
|
+
|
3
|
+
The Rails `secrets` commands helps encrypting secrets to slim a production
|
4
|
+
environment's `ENV` hash. It's also useful for atomic deploys: no need to
|
5
|
+
coordinate key changes to get everything working as the keys are shipped
|
6
|
+
with the code.
|
7
|
+
|
8
|
+
=== Setup
|
9
|
+
|
10
|
+
Run `bin/rails secrets:setup` to opt in and generate the `config/secrets.yml.key`
|
11
|
+
and `config/secrets.yml.enc` files.
|
12
|
+
|
13
|
+
The latter contains all the keys to be encrypted while the former holds the
|
14
|
+
encryption key.
|
15
|
+
|
16
|
+
Don't lose the key! Put it in a password manager your team can access.
|
17
|
+
Should you lose it no one, including you, will be able to access any encrypted
|
18
|
+
secrets.
|
19
|
+
Don't commit the key! Add `config/secrets.yml.key` to your source control's
|
20
|
+
ignore file. If you use Git, Rails handles this for you.
|
21
|
+
|
22
|
+
Rails also looks for the key in `ENV["RAILS_MASTER_KEY"]` if that's easier to
|
23
|
+
manage.
|
24
|
+
|
25
|
+
You could prepend that to your server's start command like this:
|
26
|
+
|
27
|
+
RAILS_MASTER_KEY="im-the-master-now-hahaha" server.start
|
28
|
+
|
29
|
+
|
30
|
+
The `config/secrets.yml.enc` has much the same format as `config/secrets.yml`:
|
31
|
+
|
32
|
+
production:
|
33
|
+
secret_key_base: so-secret-very-hidden-wow
|
34
|
+
payment_processing_gateway_key: much-safe-very-gaedwey-wow
|
35
|
+
|
36
|
+
But that's where the similarities between `secrets.yml` and `secrets.yml.enc`
|
37
|
+
end, e.g. no keys from `secrets.yml` will be moved to `secrets.yml.enc` and
|
38
|
+
be encrypted.
|
39
|
+
|
40
|
+
A `shared:` top level key is also supported such that any keys there is merged
|
41
|
+
into the other environments.
|
42
|
+
|
43
|
+
=== Editing Secrets
|
44
|
+
|
45
|
+
After `bin/rails secrets:setup`, run `bin/rails secrets:edit`.
|
46
|
+
|
47
|
+
That command opens a temporary file in `$EDITOR` with the decrypted contents of
|
48
|
+
`config/secrets.yml.enc` to edit the encrypted secrets.
|
49
|
+
|
50
|
+
When the temporary file is next saved the contents are encrypted and written to
|
51
|
+
`config/secrets.yml.enc` while the file itself is destroyed to prevent secrets
|
52
|
+
from leaking.
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "rails/secrets"
|
3
|
+
|
4
|
+
module Rails
|
5
|
+
module Command
|
6
|
+
class SecretsCommand < Rails::Command::Base # :nodoc:
|
7
|
+
def help
|
8
|
+
say "Usage:\n #{self.class.banner}"
|
9
|
+
say ""
|
10
|
+
say self.class.desc
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup
|
14
|
+
require "rails/generators"
|
15
|
+
require "rails/generators/rails/encrypted_secrets/encrypted_secrets_generator"
|
16
|
+
|
17
|
+
Rails::Generators::EncryptedSecretsGenerator.start
|
18
|
+
end
|
19
|
+
|
20
|
+
def edit
|
21
|
+
require_application_and_environment!
|
22
|
+
|
23
|
+
Rails::Secrets.read_for_editing do |tmp_path|
|
24
|
+
puts "Waiting for secrets file to be saved. Abort with Ctrl-C."
|
25
|
+
system("\$EDITOR #{tmp_path}")
|
26
|
+
end
|
27
|
+
|
28
|
+
puts "New secrets encrypted and saved."
|
29
|
+
rescue Interrupt
|
30
|
+
puts "Aborted changing encrypted secrets: nothing saved."
|
31
|
+
rescue Rails::Secrets::MissingKeyError => error
|
32
|
+
say error.message
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "optparse"
|
3
|
+
require "action_dispatch"
|
4
|
+
require "rails"
|
5
|
+
require "rails/dev_caching"
|
6
|
+
|
7
|
+
module Rails
|
8
|
+
class Server < ::Rack::Server
|
9
|
+
class Options
|
10
|
+
def parse!(args)
|
11
|
+
Rails::Command::ServerCommand.new([], args).server_options
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(options = nil)
|
16
|
+
@default_options = options || {}
|
17
|
+
super(@default_options)
|
18
|
+
set_environment
|
19
|
+
end
|
20
|
+
|
21
|
+
# TODO: this is no longer required but we keep it for the moment to support older config.ru files.
|
22
|
+
def app
|
23
|
+
@app ||= begin
|
24
|
+
app = super
|
25
|
+
app.respond_to?(:to_app) ? app.to_app : app
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def opt_parser
|
30
|
+
Options.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_environment
|
34
|
+
ENV["RAILS_ENV"] ||= options[:environment]
|
35
|
+
end
|
36
|
+
|
37
|
+
def start
|
38
|
+
print_boot_information
|
39
|
+
trap(:INT) { exit }
|
40
|
+
create_tmp_directories
|
41
|
+
setup_dev_caching
|
42
|
+
log_to_stdout if options[:log_stdout]
|
43
|
+
|
44
|
+
super
|
45
|
+
ensure
|
46
|
+
# The '-h' option calls exit before @options is set.
|
47
|
+
# If we call 'options' with it unset, we get double help banners.
|
48
|
+
puts "Exiting" unless @options && options[:daemonize]
|
49
|
+
end
|
50
|
+
|
51
|
+
def middleware
|
52
|
+
Hash.new([])
|
53
|
+
end
|
54
|
+
|
55
|
+
def default_options
|
56
|
+
super.merge(@default_options)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def setup_dev_caching
|
61
|
+
if options[:environment] == "development"
|
62
|
+
Rails::DevCaching.enable_by_argument(options[:caching])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def print_boot_information
|
67
|
+
url = "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}"
|
68
|
+
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
|
69
|
+
puts "=> Rails #{Rails.version} application starting in #{Rails.env} on #{url}"
|
70
|
+
puts "=> Run `rails server -h` for more startup options"
|
71
|
+
end
|
72
|
+
|
73
|
+
def create_tmp_directories
|
74
|
+
%w(cache pids sockets).each do |dir_to_make|
|
75
|
+
FileUtils.mkdir_p(File.join(Rails.root, "tmp", dir_to_make))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def log_to_stdout
|
80
|
+
wrapped_app # touch the app so the logger is set up
|
81
|
+
|
82
|
+
console = ActiveSupport::Logger.new(STDOUT)
|
83
|
+
console.formatter = Rails.logger.formatter
|
84
|
+
console.level = Rails.logger.level
|
85
|
+
|
86
|
+
unless ActiveSupport::Logger.logger_outputs_to?(Rails.logger, STDOUT)
|
87
|
+
Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def restart_command
|
92
|
+
"bin/rails server #{ARGV.join(' ')}"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
module Command
|
97
|
+
class ServerCommand < Base # :nodoc:
|
98
|
+
DEFAULT_PID_PATH = "tmp/pids/server.pid".freeze
|
99
|
+
|
100
|
+
class_option :port, aliases: "-p", type: :numeric,
|
101
|
+
desc: "Runs Rails on the specified port.", banner: :port, default: 3000
|
102
|
+
class_option :binding, aliases: "-b", type: :string, default: "localhost",
|
103
|
+
desc: "Binds Rails to the specified IP.", banner: :IP
|
104
|
+
class_option :config, aliases: "-c", type: :string, default: "config.ru",
|
105
|
+
desc: "Uses a custom rackup configuration.", banner: :file
|
106
|
+
class_option :daemon, aliases: "-d", type: :boolean, default: false,
|
107
|
+
desc: "Runs server as a Daemon."
|
108
|
+
class_option :environment, aliases: "-e", type: :string,
|
109
|
+
desc: "Specifies the environment to run this server under (development/test/production).", banner: :name
|
110
|
+
class_option :pid, aliases: "-P", type: :string, default: DEFAULT_PID_PATH,
|
111
|
+
desc: "Specifies the PID file."
|
112
|
+
class_option "dev-caching", aliases: "-C", type: :boolean, default: nil,
|
113
|
+
desc: "Specifies whether to perform caching in development."
|
114
|
+
|
115
|
+
def initialize(args = [], local_options = {}, config = {})
|
116
|
+
@original_options = local_options
|
117
|
+
super
|
118
|
+
@server = self.args.shift
|
119
|
+
@log_stdout = options[:daemon].blank? && (options[:environment] || Rails.env) == "development"
|
120
|
+
end
|
121
|
+
|
122
|
+
def perform
|
123
|
+
set_application_directory!
|
124
|
+
Rails::Server.new(server_options).tap do |server|
|
125
|
+
# Require application after server sets environment to propagate
|
126
|
+
# the --environment option.
|
127
|
+
require APP_PATH
|
128
|
+
Dir.chdir(Rails.application.root)
|
129
|
+
server.start
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
no_commands do
|
134
|
+
def server_options
|
135
|
+
{
|
136
|
+
server: @server,
|
137
|
+
log_stdout: @log_stdout,
|
138
|
+
Port: port,
|
139
|
+
Host: host,
|
140
|
+
DoNotReverseLookup: true,
|
141
|
+
config: options[:config],
|
142
|
+
environment: environment,
|
143
|
+
daemonize: options[:daemon],
|
144
|
+
pid: pid,
|
145
|
+
caching: options["dev-caching"],
|
146
|
+
restart_cmd: restart_command
|
147
|
+
}
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
private
|
152
|
+
def port
|
153
|
+
ENV.fetch("PORT", options[:port]).to_i
|
154
|
+
end
|
155
|
+
|
156
|
+
def host
|
157
|
+
ENV.fetch("HOST", options[:binding])
|
158
|
+
end
|
159
|
+
|
160
|
+
def environment
|
161
|
+
options[:environment] || Rails::Command.environment
|
162
|
+
end
|
163
|
+
|
164
|
+
def restart_command
|
165
|
+
"bin/rails server #{@server} #{@original_options.join(" ")}"
|
166
|
+
end
|
167
|
+
|
168
|
+
def pid
|
169
|
+
File.expand_path(options[:pid])
|
170
|
+
end
|
171
|
+
|
172
|
+
def self.banner(*)
|
173
|
+
"rails server [puma, thin etc] [options]"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "rails/command"
|
2
|
+
require "rails/test_unit/minitest_plugin"
|
3
|
+
|
4
|
+
module Rails
|
5
|
+
module Command
|
6
|
+
class TestCommand < Base # :nodoc:
|
7
|
+
def help
|
8
|
+
perform # Hand over help printing to minitest.
|
9
|
+
end
|
10
|
+
|
11
|
+
def perform(*)
|
12
|
+
$LOAD_PATH << Rails::Command.root.join("test")
|
13
|
+
|
14
|
+
Minitest.run_via = :rails
|
15
|
+
|
16
|
+
require "active_support/testing/autorun"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/rails/configuration.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "active_support/ordered_options"
|
2
|
+
require "active_support/core_ext/object"
|
3
|
+
require "rails/paths"
|
4
|
+
require "rails/rack"
|
5
5
|
|
6
6
|
module Rails
|
7
7
|
module Configuration
|
@@ -91,8 +91,8 @@ module Rails
|
|
91
91
|
attr_reader :hidden_namespaces
|
92
92
|
|
93
93
|
def initialize
|
94
|
-
@aliases = Hash.new { |h,k| h[k] = {} }
|
95
|
-
@options = Hash.new { |h,k| h[k] = {} }
|
94
|
+
@aliases = Hash.new { |h, k| h[k] = {} }
|
95
|
+
@options = Hash.new { |h, k| h[k] = {} }
|
96
96
|
@fallbacks = {}
|
97
97
|
@templates = []
|
98
98
|
@colorize_logging = true
|
@@ -112,7 +112,7 @@ module Rails
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def method_missing(method, *args)
|
115
|
-
method = method.to_s.sub(/=$/,
|
115
|
+
method = method.to_s.sub(/=$/, "").to_sym
|
116
116
|
|
117
117
|
return @options[method] if args.empty?
|
118
118
|
|