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.
Files changed (197) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +77 -567
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +3 -3
  5. data/README.rdoc +1 -1
  6. data/exe/rails +2 -2
  7. data/lib/rails.rb +18 -18
  8. data/lib/rails/all.rb +1 -1
  9. data/lib/rails/api/generator.rb +28 -0
  10. data/lib/rails/api/task.rb +54 -42
  11. data/lib/rails/app_loader.rb +9 -9
  12. data/lib/rails/application.rb +30 -35
  13. data/lib/rails/application/bootstrap.rb +13 -7
  14. data/lib/rails/application/configuration.rb +30 -53
  15. data/lib/rails/application/default_middleware_stack.rb +3 -5
  16. data/lib/rails/application/finisher.rb +16 -7
  17. data/lib/rails/application/routes_reloader.rb +16 -1
  18. data/lib/rails/application_controller.rb +10 -10
  19. data/lib/rails/backtrace_cleaner.rb +5 -5
  20. data/lib/rails/cli.rb +7 -5
  21. data/lib/rails/code_statistics.rb +16 -17
  22. data/lib/rails/code_statistics_calculator.rb +3 -3
  23. data/lib/rails/command.rb +111 -0
  24. data/lib/rails/command/actions.rb +42 -0
  25. data/lib/rails/command/base.rb +149 -0
  26. data/lib/rails/command/behavior.rb +123 -0
  27. data/lib/rails/command/environment_argument.rb +34 -0
  28. data/lib/rails/commands.rb +2 -4
  29. data/lib/rails/commands/application/application_command.rb +29 -0
  30. data/lib/rails/commands/console/console_command.rb +89 -0
  31. data/lib/rails/commands/dbconsole/dbconsole_command.rb +155 -0
  32. data/lib/rails/commands/destroy/destroy_command.rb +21 -0
  33. data/lib/rails/commands/generate/generate_command.rb +23 -0
  34. data/lib/rails/commands/help/USAGE +15 -0
  35. data/lib/rails/commands/help/help_command.rb +13 -0
  36. data/lib/rails/commands/new/new_command.rb +15 -0
  37. data/lib/rails/commands/plugin/plugin_command.rb +43 -0
  38. data/lib/rails/commands/rake/rake_command.rb +49 -0
  39. data/lib/rails/commands/runner/USAGE +17 -0
  40. data/lib/rails/commands/runner/runner_command.rb +46 -0
  41. data/lib/rails/commands/secrets/USAGE +52 -0
  42. data/lib/rails/commands/secrets/secrets_command.rb +36 -0
  43. data/lib/rails/commands/server/server_command.rb +177 -0
  44. data/lib/rails/commands/test/test_command.rb +20 -0
  45. data/lib/rails/commands/version/version_command.rb +9 -0
  46. data/lib/rails/configuration.rb +7 -7
  47. data/lib/rails/console/app.rb +4 -4
  48. data/lib/rails/dev_caching.rb +8 -8
  49. data/lib/rails/engine.rb +62 -63
  50. data/lib/rails/engine/commands.rb +6 -13
  51. data/lib/rails/engine/configuration.rb +2 -2
  52. data/lib/rails/gem_version.rb +3 -3
  53. data/lib/rails/generators.rb +229 -313
  54. data/lib/rails/generators/actions.rb +20 -21
  55. data/lib/rails/generators/actions/create_migration.rb +24 -25
  56. data/lib/rails/generators/active_model.rb +3 -3
  57. data/lib/rails/generators/app_base.rb +123 -93
  58. data/lib/rails/generators/base.rb +32 -33
  59. data/lib/rails/generators/css/assets/assets_generator.rb +1 -1
  60. data/lib/rails/generators/erb.rb +14 -14
  61. data/lib/rails/generators/erb/controller/controller_generator.rb +1 -1
  62. data/lib/rails/generators/erb/mailer/mailer_generator.rb +12 -12
  63. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +3 -3
  64. data/lib/rails/generators/generated_attribute.rb +27 -27
  65. data/lib/rails/generators/js/assets/assets_generator.rb +1 -1
  66. data/lib/rails/generators/migration.rb +8 -8
  67. data/lib/rails/generators/model_helpers.rb +2 -2
  68. data/lib/rails/generators/named_base.rb +56 -56
  69. data/lib/rails/generators/rails/app/app_generator.rb +98 -81
  70. data/lib/rails/generators/rails/app/templates/Gemfile +7 -2
  71. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -2
  72. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +6 -4
  73. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js +1 -1
  74. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +2 -2
  75. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
  76. data/lib/rails/generators/rails/app/templates/bin/{setup → setup.tt} +6 -0
  77. data/lib/rails/generators/rails/app/templates/bin/{update → update.tt} +2 -1
  78. data/lib/rails/generators/rails/app/templates/bin/yarn +9 -0
  79. data/lib/rails/generators/rails/app/templates/config/cable.yml +1 -0
  80. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +1 -0
  81. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +1 -0
  82. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +1 -0
  83. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +2 -1
  84. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -0
  85. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +1 -0
  86. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
  87. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -0
  88. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
  89. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +1 -1
  90. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -1
  91. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
  92. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -1
  93. data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +4 -6
  94. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +8 -3
  95. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt +6 -5
  96. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +10 -0
  97. data/lib/rails/generators/rails/app/templates/config/puma.rb +16 -7
  98. data/lib/rails/generators/rails/app/templates/config/secrets.yml +12 -2
  99. data/lib/rails/generators/rails/app/templates/gitignore +5 -1
  100. data/lib/rails/generators/rails/app/templates/package.json +5 -0
  101. data/lib/rails/generators/rails/app/templates/public/404.html +6 -6
  102. data/lib/rails/generators/rails/app/templates/public/422.html +6 -6
  103. data/lib/rails/generators/rails/app/templates/public/500.html +6 -6
  104. data/lib/rails/generators/rails/app/templates/public/robots.txt +0 -4
  105. data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb +5 -0
  106. data/lib/rails/generators/rails/app/templates/test/test_helper.rb +0 -1
  107. data/lib/rails/generators/rails/assets/assets_generator.rb +10 -10
  108. data/lib/rails/generators/rails/controller/controller_generator.rb +15 -12
  109. data/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +66 -0
  110. data/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc +3 -0
  111. data/lib/rails/generators/rails/generator/generator_generator.rb +2 -3
  112. data/lib/rails/generators/rails/helper/helper_generator.rb +1 -1
  113. data/lib/rails/generators/rails/model/model_generator.rb +1 -1
  114. data/lib/rails/generators/rails/plugin/plugin_generator.rb +21 -26
  115. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -0
  116. data/lib/rails/generators/rails/plugin/templates/bin/test.tt +3 -9
  117. data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb +5 -0
  118. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +0 -3
  119. data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
  120. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +5 -1
  121. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +4 -8
  122. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +2 -3
  123. data/lib/rails/generators/rails/system_test/USAGE +10 -0
  124. data/lib/rails/generators/rails/system_test/system_test_generator.rb +7 -0
  125. data/lib/rails/generators/rails/task/task_generator.rb +1 -2
  126. data/lib/rails/generators/resource_helpers.rb +13 -10
  127. data/lib/rails/generators/test_case.rb +5 -6
  128. data/lib/rails/generators/test_unit.rb +1 -1
  129. data/lib/rails/generators/test_unit/controller/controller_generator.rb +3 -3
  130. data/lib/rails/generators/test_unit/generator/generator_generator.rb +3 -3
  131. data/lib/rails/generators/test_unit/helper/helper_generator.rb +1 -1
  132. data/lib/rails/generators/test_unit/integration/integration_generator.rb +2 -2
  133. data/lib/rails/generators/test_unit/job/job_generator.rb +3 -3
  134. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +5 -5
  135. data/lib/rails/generators/test_unit/model/model_generator.rb +3 -4
  136. data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +2 -2
  137. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
  138. data/lib/rails/generators/test_unit/system/system_generator.rb +17 -0
  139. data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb +5 -0
  140. data/lib/rails/generators/test_unit/system/templates/system_test.rb +9 -0
  141. data/lib/rails/generators/testing/assertions.rb +4 -4
  142. data/lib/rails/generators/testing/behaviour.rb +20 -21
  143. data/lib/rails/info.rb +20 -20
  144. data/lib/rails/info_controller.rb +15 -15
  145. data/lib/rails/initializable.rb +6 -2
  146. data/lib/rails/mailers_controller.rb +11 -11
  147. data/lib/rails/paths.rb +4 -5
  148. data/lib/rails/plugin/test.rb +7 -0
  149. data/lib/rails/rack/logger.rb +44 -46
  150. data/lib/rails/railtie.rb +41 -38
  151. data/lib/rails/railtie/configurable.rb +6 -6
  152. data/lib/rails/railtie/configuration.rb +1 -1
  153. data/lib/rails/ruby_version_check.rb +1 -1
  154. data/lib/rails/secrets.rb +111 -0
  155. data/lib/rails/source_annotation_extractor.rb +15 -9
  156. data/lib/rails/tasks.rb +3 -2
  157. data/lib/rails/tasks/annotations.rake +3 -3
  158. data/lib/rails/tasks/dev.rake +2 -2
  159. data/lib/rails/tasks/engine.rake +4 -4
  160. data/lib/rails/tasks/framework.rake +4 -18
  161. data/lib/rails/tasks/initializers.rake +1 -1
  162. data/lib/rails/tasks/log.rake +14 -10
  163. data/lib/rails/tasks/middleware.rake +1 -1
  164. data/lib/rails/tasks/misc.rake +10 -10
  165. data/lib/rails/tasks/restart.rake +4 -4
  166. data/lib/rails/tasks/routes.rake +3 -12
  167. data/lib/rails/tasks/statistics.rake +3 -3
  168. data/lib/rails/tasks/tmp.rake +7 -7
  169. data/lib/rails/tasks/yarn.rake +11 -0
  170. data/lib/rails/templates/rails/mailers/email.html.erb +4 -1
  171. data/lib/rails/test_help.rb +28 -10
  172. data/lib/rails/test_unit/line_filtering.rb +69 -3
  173. data/lib/rails/test_unit/minitest_plugin.rb +139 -0
  174. data/lib/rails/test_unit/railtie.rb +2 -1
  175. data/lib/rails/test_unit/reporter.rb +3 -8
  176. data/lib/rails/test_unit/test_requirer.rb +28 -0
  177. data/lib/rails/test_unit/testing.rake +19 -14
  178. data/lib/rails/version.rb +1 -1
  179. data/lib/rails/welcome_controller.rb +1 -1
  180. metadata +53 -30
  181. data/lib/minitest/rails_plugin.rb +0 -49
  182. data/lib/rails/commands/application.rb +0 -17
  183. data/lib/rails/commands/commands_tasks.rb +0 -180
  184. data/lib/rails/commands/console.rb +0 -68
  185. data/lib/rails/commands/console_helper.rb +0 -34
  186. data/lib/rails/commands/dbconsole.rb +0 -173
  187. data/lib/rails/commands/destroy.rb +0 -11
  188. data/lib/rails/commands/generate.rb +0 -13
  189. data/lib/rails/commands/plugin.rb +0 -23
  190. data/lib/rails/commands/rake_proxy.rb +0 -41
  191. data/lib/rails/commands/runner.rb +0 -71
  192. data/lib/rails/commands/server.rb +0 -163
  193. data/lib/rails/commands/test.rb +0 -10
  194. data/lib/rails/engine/commands_tasks.rb +0 -118
  195. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +0 -3
  196. data/lib/rails/rack/debugger.rb +0 -3
  197. 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
@@ -0,0 +1,9 @@
1
+ module Rails
2
+ module Command
3
+ class VersionCommand < Base # :nodoc:
4
+ def perform
5
+ Rails::Command.invoke :application, [ "--version" ]
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,7 +1,7 @@
1
- require 'active_support/ordered_options'
2
- require 'active_support/core_ext/object'
3
- require 'rails/paths'
4
- require 'rails/rack'
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(/=$/, '').to_sym
115
+ method = method.to_s.sub(/=$/, "").to_sym
116
116
 
117
117
  return @options[method] if args.empty?
118
118