railties 5.0.0.beta3 → 5.0.0.beta4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -19
  3. data/lib/rails/all.rb +2 -2
  4. data/lib/rails/app_loader.rb +1 -1
  5. data/lib/rails/application.rb +8 -6
  6. data/lib/rails/application/bootstrap.rb +4 -3
  7. data/lib/rails/application/configuration.rb +5 -5
  8. data/lib/rails/application/default_middleware_stack.rb +3 -19
  9. data/lib/rails/application/finisher.rb +73 -13
  10. data/lib/rails/code_statistics.rb +1 -0
  11. data/lib/rails/commands.rb +2 -2
  12. data/lib/rails/commands/runner.rb +4 -3
  13. data/lib/rails/commands/server.rb +10 -18
  14. data/lib/rails/console/app.rb +1 -2
  15. data/lib/rails/dev_caching.rb +43 -0
  16. data/lib/rails/gem_version.rb +1 -1
  17. data/lib/rails/generators/actions.rb +21 -8
  18. data/lib/rails/generators/actions/create_migration.rb +1 -0
  19. data/lib/rails/generators/app_base.rb +2 -1
  20. data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -1
  21. data/lib/rails/generators/rails/app/app_generator.rb +20 -2
  22. data/lib/rails/generators/rails/app/templates/Gemfile +3 -3
  23. data/lib/rails/generators/rails/app/templates/README.md +1 -1
  24. data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
  25. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js +13 -0
  26. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +2 -5
  27. data/lib/rails/generators/rails/app/templates/bin/rails +1 -1
  28. data/lib/rails/generators/rails/app/templates/bin/setup +1 -1
  29. data/lib/rails/generators/rails/app/templates/bin/update +1 -1
  30. data/lib/rails/generators/rails/app/templates/config.ru +5 -0
  31. data/lib/rails/generators/rails/app/templates/config/application.rb +1 -1
  32. data/lib/rails/generators/rails/app/templates/config/boot.rb +1 -1
  33. data/lib/rails/generators/rails/app/templates/config/environment.rb +1 -1
  34. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +2 -17
  35. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +13 -12
  36. data/lib/rails/generators/rails/app/templates/config/initializers/ssl_options.rb +4 -0
  37. data/lib/rails/generators/rails/app/templates/config/initializers/to_time_preserves_timezone.rb +10 -0
  38. data/lib/rails/generators/rails/app/templates/config/routes.rb +0 -3
  39. data/lib/rails/generators/rails/app/templates/config/spring.rb +6 -0
  40. data/lib/rails/generators/rails/plugin/templates/Rakefile +1 -1
  41. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +2 -1
  42. data/lib/rails/generators/rails/plugin/templates/rails/application.rb +5 -3
  43. data/lib/rails/generators/rails/plugin/templates/rails/boot.rb +2 -2
  44. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +1 -1
  45. data/lib/rails/railtie.rb +37 -38
  46. data/lib/rails/tasks/dev.rake +3 -9
  47. data/lib/rails/tasks/framework.rake +20 -5
  48. data/lib/rails/tasks/misc.rake +23 -6
  49. data/lib/rails/tasks/restart.rake +6 -3
  50. data/lib/rails/tasks/routes.rake +3 -0
  51. data/lib/rails/tasks/statistics.rake +1 -0
  52. data/lib/rails/tasks/tmp.rake +4 -6
  53. data/lib/rails/test_unit/minitest_plugin.rb +10 -9
  54. metadata +16 -13
  55. data/lib/rails/command.rb +0 -70
  56. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee +0 -11
  57. data/lib/rails/generators/rails/app/templates/config.ru.tt +0 -10
@@ -1,4 +1,5 @@
1
1
  require 'rails/code_statistics_calculator'
2
+ require 'active_support/core_ext/enumerable'
2
3
 
3
4
  class CodeStatistics #:nodoc:
4
5
 
@@ -13,6 +13,6 @@ aliases = {
13
13
  command = ARGV.shift
14
14
  command = aliases[command] || command
15
15
 
16
- require 'rails/command'
16
+ require 'rails/commands/commands_tasks'
17
17
 
18
- Rails::Command.run(command, ARGV)
18
+ Rails::CommandsTasks.new(ARGV).run_command!(command)
@@ -2,6 +2,7 @@ require 'optparse'
2
2
 
3
3
  options = { environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup }
4
4
  code_or_file = nil
5
+ command = 'bin/rails runner'
5
6
 
6
7
  if ARGV.first.nil?
7
8
  ARGV.push "-h"
@@ -34,7 +35,7 @@ ARGV.clone.options do |opts|
34
35
  opts.separator ""
35
36
  opts.separator "You can also use runner as a shebang line for your executables:"
36
37
  opts.separator " -------------------------------------------------------------"
37
- opts.separator " #!/usr/bin/env #{File.expand_path($0)} runner"
38
+ opts.separator " #!/usr/bin/env #{File.expand_path(command)}"
38
39
  opts.separator ""
39
40
  opts.separator " Product.all.each { |p| p.price *= 2 ; p.save! }"
40
41
  opts.separator " -------------------------------------------------------------"
@@ -52,7 +53,7 @@ Rails.application.require_environment!
52
53
  Rails.application.load_runner
53
54
 
54
55
  if code_or_file.nil?
55
- $stderr.puts "Run '#{$0} -h' for help."
56
+ $stderr.puts "Run '#{command} -h' for help."
56
57
  exit 1
57
58
  elsif File.exist?(code_or_file)
58
59
  $0 = code_or_file
@@ -62,7 +63,7 @@ else
62
63
  eval(code_or_file, binding, __FILE__, __LINE__)
63
64
  rescue SyntaxError, NameError
64
65
  $stderr.puts "Please specify a valid ruby command or the path of a script to run."
65
- $stderr.puts "Run '#{$0} -h' for help."
66
+ $stderr.puts "Run '#{command} -h' for help."
66
67
  exit 1
67
68
  end
68
69
  end
@@ -2,6 +2,7 @@ require 'fileutils'
2
2
  require 'optparse'
3
3
  require 'action_dispatch'
4
4
  require 'rails'
5
+ require 'rails/dev_caching'
5
6
 
6
7
  module Rails
7
8
  class Server < ::Rack::Server
@@ -92,20 +93,17 @@ module Rails
92
93
  DoNotReverseLookup: true,
93
94
  environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup,
94
95
  daemonize: false,
95
- caching: false,
96
- pid: Options::DEFAULT_PID_PATH
96
+ caching: nil,
97
+ pid: Options::DEFAULT_PID_PATH,
98
+ restart_cmd: restart_command
97
99
  })
98
100
  end
99
101
 
100
102
  private
101
103
 
102
104
  def setup_dev_caching
103
- return unless options[:environment] == "development"
104
-
105
- if options[:caching] == false
106
- delete_cache_file
107
- elsif options[:caching]
108
- create_cache_file
105
+ if options[:environment] == "development"
106
+ Rails::DevCaching.enable_by_argument(options[:caching])
109
107
  end
110
108
  end
111
109
 
@@ -114,16 +112,6 @@ module Rails
114
112
  puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
115
113
  puts "=> Rails #{Rails.version} application starting in #{Rails.env} on #{url}"
116
114
  puts "=> Run `rails server -h` for more startup options"
117
-
118
- puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
119
- end
120
-
121
- def create_cache_file
122
- FileUtils.touch("tmp/caching-dev.txt")
123
- end
124
-
125
- def delete_cache_file
126
- FileUtils.rm("tmp/caching-dev.txt") if File.exist?("tmp/caching-dev.txt")
127
115
  end
128
116
 
129
117
  def create_tmp_directories
@@ -143,5 +131,9 @@ module Rails
143
131
  Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
144
132
  end
145
133
  end
134
+
135
+ def restart_command
136
+ "bin/rails server #{ARGV.join(' ')}"
137
+ end
146
138
  end
147
139
  end
@@ -29,8 +29,7 @@ module Rails
29
29
  # reloads the environment
30
30
  def reload!(print=true)
31
31
  puts "Reloading..." if print
32
- ActionDispatch::Reloader.cleanup!
33
- ActionDispatch::Reloader.prepare!
32
+ Rails.application.reloader.reload!
34
33
  true
35
34
  end
36
35
  end
@@ -0,0 +1,43 @@
1
+ require 'fileutils'
2
+
3
+ module Rails
4
+ module DevCaching # :nodoc:
5
+ class << self
6
+ FILE = 'tmp/caching-dev.txt'
7
+
8
+ def enable_by_file
9
+ FileUtils.mkdir_p('tmp')
10
+
11
+ if File.exist?(FILE)
12
+ delete_cache_file
13
+ puts 'Development mode is no longer being cached.'
14
+ else
15
+ create_cache_file
16
+ puts 'Development mode is now being cached.'
17
+ end
18
+
19
+ FileUtils.touch 'tmp/restart.txt'
20
+ FileUtils.rm_f('tmp/pids/server.pid')
21
+ end
22
+
23
+ def enable_by_argument(caching)
24
+ FileUtils.mkdir_p('tmp')
25
+
26
+ if caching
27
+ create_cache_file
28
+ elsif caching == false && File.exist?(FILE)
29
+ delete_cache_file
30
+ end
31
+ end
32
+
33
+ private
34
+ def create_cache_file
35
+ FileUtils.touch FILE
36
+ end
37
+
38
+ def delete_cache_file
39
+ File.delete FILE
40
+ end
41
+ end
42
+ end
43
+ end
@@ -8,7 +8,7 @@ module Rails
8
8
  MAJOR = 5
9
9
  MINOR = 0
10
10
  TINY = 0
11
- PRE = "beta3"
11
+ PRE = "beta4"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -1,5 +1,3 @@
1
- require 'open-uri'
2
-
3
1
  module Rails
4
2
  module Generators
5
3
  module Actions
@@ -207,18 +205,23 @@ module Rails
207
205
  in_root { run_ruby_script("bin/rails generate #{what} #{argument}", verbose: false) }
208
206
  end
209
207
 
210
- # Runs the supplied rake task
208
+ # Runs the supplied rake task (invoked with 'rake ...')
211
209
  #
212
210
  # rake("db:migrate")
213
211
  # rake("db:migrate", env: "production")
214
212
  # rake("gems:install", sudo: true)
215
213
  def rake(command, options={})
216
- log :rake, command
217
- env = options[:env] || ENV["RAILS_ENV"] || 'development'
218
- sudo = options[:sudo] && RbConfig::CONFIG['host_os'] !~ /mswin|mingw/ ? 'sudo ' : ''
219
- in_root { run("#{sudo}#{extify(:rails)} #{command} RAILS_ENV=#{env}", verbose: false) }
214
+ execute_command :rake, command, options
215
+ end
216
+
217
+ # Runs the supplied rake task (invoked with 'rails ...')
218
+ #
219
+ # rails("db:migrate")
220
+ # rails("db:migrate", env: "production")
221
+ # rails("gems:install", sudo: true)
222
+ def rails_command(command, options={})
223
+ execute_command :rails, command, options
220
224
  end
221
- alias :rails_command :rake
222
225
 
223
226
  # Just run the capify command in root
224
227
  #
@@ -271,6 +274,16 @@ module Rails
271
274
  end
272
275
  end
273
276
 
277
+
278
+ # Runs the supplied command using either "rake ..." or "rails ..."
279
+ # based on the executor parameter provided.
280
+ def execute_command(executor, command, options={})
281
+ log executor, command
282
+ env = options[:env] || ENV["RAILS_ENV"] || 'development'
283
+ sudo = options[:sudo] && RbConfig::CONFIG['host_os'] !~ /mswin|mingw/ ? 'sudo ' : ''
284
+ in_root { run("#{sudo}#{extify(executor)} #{command} RAILS_ENV=#{env}", verbose: false) }
285
+ end
286
+
274
287
  # Add an extension to the given name based on the platform.
275
288
  def extify(name)
276
289
  if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
@@ -1,3 +1,4 @@
1
+ require 'fileutils'
1
2
  require 'thor/actions'
2
3
 
3
4
  module Rails
@@ -1,3 +1,4 @@
1
+ require 'fileutils'
1
2
  require 'digest/md5'
2
3
  require 'active_support/core_ext/string/strip'
3
4
  require 'rails/version' unless defined?(Rails::VERSION)
@@ -181,7 +182,7 @@ module Rails
181
182
  def webserver_gemfile_entry
182
183
  return [] if options[:skip_puma]
183
184
  comment = 'Use Puma as the app server'
184
- GemfileEntry.new('puma', nil, comment)
185
+ GemfileEntry.new('puma', '~> 3.0', comment)
185
186
  end
186
187
 
187
188
  def include_all_railties?
@@ -26,7 +26,7 @@ module Erb # :nodoc:
26
26
  end
27
27
 
28
28
  def file_name
29
- @_file_name ||= super.gsub(/\_mailer/i, '')
29
+ @_file_name ||= super.gsub(/_mailer/i, '')
30
30
  end
31
31
  end
32
32
  end
@@ -80,6 +80,7 @@ module Rails
80
80
  template "secrets.yml"
81
81
  template "cable.yml" unless options[:skip_action_cable]
82
82
  template "puma.rb" unless options[:skip_puma]
83
+ template "spring.rb" if spring_install?
83
84
 
84
85
  directory "environments"
85
86
  directory "initializers"
@@ -91,25 +92,42 @@ module Rails
91
92
  cookie_serializer_config_exist = File.exist?('config/initializers/cookies_serializer.rb')
92
93
  callback_terminator_config_exist = File.exist?('config/initializers/callback_terminator.rb')
93
94
  active_record_belongs_to_required_by_default_config_exist = File.exist?('config/initializers/active_record_belongs_to_required_by_default.rb')
95
+ to_time_preserves_timezone_config_exist = File.exist?('config/initializers/to_time_preserves_timezone.rb')
94
96
  action_cable_config_exist = File.exist?('config/cable.yml')
97
+ ssl_options_exist = File.exist?('config/initializers/ssl_options.rb')
98
+ rack_cors_config_exist = File.exist?('config/initializers/cors.rb')
95
99
 
96
100
  config
97
101
 
102
+ gsub_file 'config/environments/development.rb', /^(\s+)config\.file_watcher/, '\1# config.file_watcher'
103
+
98
104
  unless callback_terminator_config_exist
99
105
  remove_file 'config/initializers/callback_terminator.rb'
100
106
  end
101
107
 
102
108
  unless cookie_serializer_config_exist
103
- gsub_file 'config/initializers/cookies_serializer.rb', /json/, 'marshal'
109
+ gsub_file 'config/initializers/cookies_serializer.rb', /json(?!,)/, 'marshal'
104
110
  end
105
111
 
106
112
  unless active_record_belongs_to_required_by_default_config_exist
107
113
  remove_file 'config/initializers/active_record_belongs_to_required_by_default.rb'
108
114
  end
109
115
 
116
+ unless to_time_preserves_timezone_config_exist
117
+ remove_file 'config/initializers/to_time_preserves_timezone.rb'
118
+ end
119
+
110
120
  unless action_cable_config_exist
111
121
  template 'config/cable.yml'
112
122
  end
123
+
124
+ unless ssl_options_exist
125
+ remove_file 'config/initializers/ssl_options.rb'
126
+ end
127
+
128
+ unless rack_cors_config_exist
129
+ remove_file 'config/initializers/cors.rb'
130
+ end
113
131
  end
114
132
 
115
133
  def database_yml
@@ -322,7 +340,7 @@ module Rails
322
340
  def delete_action_cable_files_skipping_action_cable
323
341
  if options[:skip_action_cable]
324
342
  remove_file 'config/cable.yml'
325
- remove_file 'app/assets/javascripts/cable.coffee'
343
+ remove_file 'app/assets/javascripts/cable.js'
326
344
  remove_dir 'app/channels'
327
345
  end
328
346
  end
@@ -26,16 +26,16 @@ source 'https://rubygems.org'
26
26
  <% if RUBY_ENGINE == 'ruby' -%>
27
27
  group :development, :test do
28
28
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
29
- gem 'byebug'
29
+ gem 'byebug', platform: :mri
30
30
  end
31
31
 
32
32
  group :development do
33
33
  <%- unless options.api? -%>
34
- # Access an IRB console on exception pages or by using <%%= console %> in views
34
+ # Access an IRB console on exception pages or by using <%%= console %> anywhere in the code.
35
35
  <%- if options.dev? || options.edge? -%>
36
36
  gem 'web-console', github: 'rails/web-console'
37
37
  <%- else -%>
38
- gem 'web-console', '~> 3.0'
38
+ gem 'web-console'
39
39
  <%- end -%>
40
40
  <%- end -%>
41
41
  <% if depend_on_listen? -%>
@@ -1,4 +1,4 @@
1
- ## README
1
+ # README
2
2
 
3
3
  This README would normally document whatever steps are necessary to get the
4
4
  application up and running.
@@ -1,6 +1,6 @@
1
1
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
2
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
3
 
4
- require File.expand_path('../config/application', __FILE__)
4
+ require_relative 'config/application'
5
5
 
6
6
  Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the rails generate channel command.
3
+ //
4
+ //= require action_cable
5
+ //= require_self
6
+ //= require_tree ./channels
7
+
8
+ (function() {
9
+ this.App || (this.App = {});
10
+
11
+ App.cable = ActionCable.createConsumer();
12
+
13
+ }).call(this);
@@ -3,16 +3,13 @@
3
3
  <head>
4
4
  <title><%= camelized %></title>
5
5
  <%%= csrf_meta_tags %>
6
- <%- unless options[:skip_action_cable] -%>
7
- <%%= action_cable_meta_tag %>
8
- <%- end -%>
9
6
 
10
7
  <%- if options[:skip_javascript] -%>
11
8
  <%%= stylesheet_link_tag 'application', media: 'all' %>
12
9
  <%- else -%>
13
10
  <%- if gemfile_entries.any? { |m| m.name == 'turbolinks' } -%>
14
- <%%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => 'reload' %>
15
- <%%= javascript_include_tag 'application', 'data-turbolinks-track' => 'reload' %>
11
+ <%%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
12
+ <%%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
16
13
  <%- else -%>
17
14
  <%%= stylesheet_link_tag 'application', media: 'all' %>
18
15
  <%%= javascript_include_tag 'application' %>
@@ -1,3 +1,3 @@
1
- APP_PATH = File.expand_path('../../config/application', __FILE__)
1
+ APP_PATH = File.expand_path('../config/application', __dir__)
2
2
  require_relative '../config/boot'
3
3
  require 'rails/commands'
@@ -15,7 +15,7 @@ chdir APP_ROOT do
15
15
 
16
16
  puts '== Installing dependencies =='
17
17
  system! 'gem install bundler --conservative'
18
- system('bundle check') or system!('bundle install')
18
+ system('bundle check') || system!('bundle install')
19
19
 
20
20
  # puts "\n== Copying sample files =="
21
21
  # unless File.exist?('config/database.yml')
@@ -15,7 +15,7 @@ chdir APP_ROOT do
15
15
 
16
16
  puts '== Installing dependencies =='
17
17
  system! 'gem install bundler --conservative'
18
- system 'bundle check' or system! 'bundle install'
18
+ system('bundle check') || system!('bundle install')
19
19
 
20
20
  puts "\n== Updating database =="
21
21
  system! 'bin/rails db:migrate'
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
@@ -1,4 +1,4 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require_relative 'boot'
2
2
 
3
3
  <% if include_all_railties? -%>
4
4
  require 'rails/all'
@@ -1,3 +1,3 @@
1
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2
2
 
3
3
  require 'bundler/setup' # Set up gems listed in the Gemfile.
@@ -1,5 +1,5 @@
1
1
  # Load the Rails application.
2
- require File.expand_path('../application', __FILE__)
2
+ require_relative 'application'
3
3
 
4
4
  # Initialize the Rails application.
5
5
  Rails.application.initialize!
@@ -16,10 +16,6 @@ Rails.application.configure do
16
16
  if Rails.root.join('tmp/caching-dev.txt').exist?
17
17
  config.action_controller.perform_caching = true
18
18
 
19
- <%- unless options.skip_action_mailer? -%>
20
- config.action_mailer.perform_caching = false
21
- <%- end -%>
22
-
23
19
  config.cache_store = :memory_store
24
20
  config.public_file_server.headers = {
25
21
  'Cache-Control' => 'public, max-age=172800'
@@ -27,16 +23,14 @@ Rails.application.configure do
27
23
  else
28
24
  config.action_controller.perform_caching = false
29
25
 
30
- <%- unless options.skip_action_mailer? -%>
31
- config.action_mailer.perform_caching = false
32
- <%- end -%>
33
-
34
26
  config.cache_store = :null_store
35
27
  end
36
28
  <%- unless options.skip_action_mailer? -%>
37
29
 
38
30
  # Don't care if the mailer can't send.
39
31
  config.action_mailer.raise_delivery_errors = false
32
+
33
+ config.action_mailer.perform_caching = false
40
34
  <%- end -%>
41
35
 
42
36
  # Print deprecation notices to the Rails logger.
@@ -52,15 +46,6 @@ Rails.application.configure do
52
46
  # This option may cause significant delays in view rendering with a large
53
47
  # number of complex assets.
54
48
  config.assets.debug = true
55
-
56
- # Asset digests allow you to set far-future HTTP expiration dates on all assets,
57
- # yet still be able to expire them through the digest params.
58
- config.assets.digest = true
59
-
60
- # Adds additional error checking when serving assets at runtime.
61
- # Checks for improperly declared sprockets dependencies.
62
- # Raises helpful error messages.
63
- config.assets.raise_runtime_errors = true
64
49
  <%- end -%>
65
50
 
66
51
  # Raises error for missing translations