railties 5.0.0.beta3 → 5.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -26,10 +26,6 @@ Rails.application.configure do
26
26
  # Do not fallback to assets pipeline if a precompiled asset is missed.
27
27
  config.assets.compile = false
28
28
 
29
- # Asset digests allow you to set far-future HTTP expiration dates on all assets,
30
- # yet still be able to expire them through the digest params.
31
- config.assets.digest = true
32
-
33
29
  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
34
30
  <%- end -%>
35
31
 
@@ -44,6 +40,9 @@ Rails.application.configure do
44
40
  # Action Cable endpoint configuration
45
41
  # config.action_cable.url = 'wss://example.com/cable'
46
42
  # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
43
+
44
+ # Don't mount Action Cable in the main server process.
45
+ # config.action_cable.mount_path = nil
47
46
  <%- end -%>
48
47
 
49
48
  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
@@ -56,14 +55,6 @@ Rails.application.configure do
56
55
  # Prepend all log lines with the following tags.
57
56
  config.log_tags = [ :request_id ]
58
57
 
59
- # Use a different logger for distributed setups.
60
- # require 'syslog/logger'
61
- # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
62
-
63
- if ENV["RAILS_LOG_TO_STDOUT"].present?
64
- config.logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
65
- end
66
-
67
58
  # Use a different cache store in production.
68
59
  # config.cache_store = :mem_cache_store
69
60
 
@@ -87,6 +78,16 @@ Rails.application.configure do
87
78
 
88
79
  # Use default logging formatter so that PID and timestamp are not suppressed.
89
80
  config.log_formatter = ::Logger::Formatter.new
81
+
82
+ # Use a different logger for distributed setups.
83
+ # require 'syslog/logger'
84
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
85
+
86
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
87
+ logger = ActiveSupport::Logger.new(STDOUT)
88
+ logger.formatter = config.log_formatter
89
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
90
+ end
90
91
  <%- unless options.skip_active_record? -%>
91
92
 
92
93
  # Do not dump schema after migrations.
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure SSL options to enable HSTS with subdomains.
4
+ Rails.application.config.ssl_options = { hsts: { subdomains: true } }
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Preserve the timezone of the receiver when calling to `to_time`.
4
+ # Ruby 2.4 will change the behavior of `to_time` to preserve the timezone
5
+ # when converting to an instance of `Time` instead of the previous behavior
6
+ # of converting to the local system timezone.
7
+ #
8
+ # Rails 5.0 introduced this config option so that apps made with earlier
9
+ # versions of Rails are not affected when upgrading.
10
+ ActiveSupport.to_time_preserves_timezone = true
@@ -1,6 +1,3 @@
1
1
  Rails.application.routes.draw do
2
2
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
3
-
4
- # Serve websocket cable requests in-process
5
- # mount ActionCable.server => '/cable'
6
3
  end
@@ -0,0 +1,6 @@
1
+ %w(
2
+ .ruby-version
3
+ .rbenv-vars
4
+ tmp/restart.txt
5
+ tmp/caching-dev.txt
6
+ ).each { |path| Spring.watch(path) }
@@ -25,5 +25,5 @@ load 'rails/tasks/statistics.rake'
25
25
 
26
26
  <% unless options[:skip_gemspec] -%>
27
27
 
28
- Bundler::GemHelper.install_tasks
28
+ require 'bundler/gem_tasks'
29
29
  <% end %>
@@ -1,4 +1,5 @@
1
- # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
1
+ # This command will automatically be run when you run "rails" with Rails gems
2
+ # installed from the root of your application.
2
3
 
3
4
  ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
5
  ENGINE_PATH = File.expand_path('../../lib/<%= namespaced_name -%>/engine', __FILE__)
@@ -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'
@@ -6,10 +6,12 @@ require 'rails/all'
6
6
  # Pick the frameworks you want:
7
7
  <%= comment_if :skip_active_record %>require "active_record/railtie"
8
8
  require "action_controller/railtie"
9
- <%= comment_if :skip_action_mailer %>require "action_mailer/railtie"
10
9
  require "action_view/railtie"
11
- <%= comment_if :skip_sprockets %>require "sprockets/railtie"
10
+ <%= comment_if :skip_action_mailer %>require "action_mailer/railtie"
11
+ require "active_job/railtie"
12
+ <%= comment_if :skip_action_cable %>require "action_cable/engine"
12
13
  <%= comment_if :skip_test %>require "rails/test_unit/railtie"
14
+ <%= comment_if :skip_sprockets %>require "sprockets/railtie"
13
15
  <% end -%>
14
16
 
15
17
  Bundler.require(*Rails.groups)
@@ -1,5 +1,5 @@
1
1
  # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
3
3
 
4
4
  require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
- $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
5
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -19,7 +19,7 @@ module TestUnit # :nodoc:
19
19
 
20
20
  protected
21
21
  def file_name
22
- @_file_name ||= super.gsub(/\_mailer/i, '')
22
+ @_file_name ||= super.gsub(/_mailer/i, '')
23
23
  end
24
24
  end
25
25
  end
@@ -1,38 +1,37 @@
1
1
  require 'rails/initializable'
2
- require 'rails/configuration'
3
2
  require 'active_support/inflector'
4
3
  require 'active_support/core_ext/module/introspection'
5
4
  require 'active_support/core_ext/module/delegation'
6
5
 
7
6
  module Rails
8
- # Railtie is the core of the Rails framework and provides several hooks to extend
9
- # Rails and/or modify the initialization process.
7
+ # <tt>Rails::Railtie</tt> is the core of the Rails framework and provides
8
+ # several hooks to extend Rails and/or modify the initialization process.
10
9
  #
11
- # Every major component of Rails (Action Mailer, Action Controller,
12
- # Action View and Active Record) is a Railtie. Each of
13
- # them is responsible for their own initialization. This makes Rails itself
14
- # absent of any component hooks, allowing other components to be used in
15
- # place of any of the Rails defaults.
10
+ # Every major component of Rails (Action Mailer, Action Controller, Active
11
+ # Record, etc.) implements a railtie. Each of them is responsible for their
12
+ # own initialization. This makes Rails itself absent of any component hooks,
13
+ # allowing other components to be used in place of any of the Rails defaults.
16
14
  #
17
- # Developing a Rails extension does _not_ require any implementation of
18
- # Railtie, but if you need to interact with the Rails framework during
19
- # or after boot, then Railtie is needed.
15
+ # Developing a Rails extension does _not_ require implementing a railtie, but
16
+ # if you need to interact with the Rails framework during or after boot, then
17
+ # a railtie is needed.
20
18
  #
21
- # For example, an extension doing any of the following would require Railtie:
19
+ # For example, an extension doing any of the following would need a railtie:
22
20
  #
23
21
  # * creating initializers
24
22
  # * configuring a Rails framework for the application, like setting a generator
25
23
  # * adding <tt>config.*</tt> keys to the environment
26
- # * setting up a subscriber with ActiveSupport::Notifications
27
- # * adding rake tasks
24
+ # * setting up a subscriber with <tt>ActiveSupport::Notifications</tt>
25
+ # * adding Rake tasks
28
26
  #
29
- # == Creating your Railtie
27
+ # == Creating a Railtie
30
28
  #
31
- # To extend Rails using Railtie, create a Railtie class which inherits
32
- # from Rails::Railtie within your extension's namespace. This class must be
33
- # loaded during the Rails boot process.
29
+ # To extend Rails using a railtie, create a subclass of <tt>Rails::Railtie</tt>.
30
+ # This class must be loaded during the Rails boot process, and is conventionally
31
+ # called <tt>MyNamespace::Railtie</tt>.
34
32
  #
35
- # The following example demonstrates an extension which can be used with or without Rails.
33
+ # The following example demonstrates an extension which can be used with or
34
+ # without Rails.
36
35
  #
37
36
  # # lib/my_gem/railtie.rb
38
37
  # module MyGem
@@ -45,8 +44,8 @@ module Rails
45
44
  #
46
45
  # == Initializers
47
46
  #
48
- # To add an initialization step from your Railtie to Rails boot process, you just need
49
- # to create an initializer block:
47
+ # To add an initialization step to the Rails boot process from your railtie, just
48
+ # define the initialization code with the +initializer+ macro:
50
49
  #
51
50
  # class MyRailtie < Rails::Railtie
52
51
  # initializer "my_railtie.configure_rails_initialization" do
@@ -55,7 +54,7 @@ module Rails
55
54
  # end
56
55
  #
57
56
  # If specified, the block can also receive the application object, in case you
58
- # need to access some application specific configuration, like middleware:
57
+ # need to access some application-specific configuration, like middleware:
59
58
  #
60
59
  # class MyRailtie < Rails::Railtie
61
60
  # initializer "my_railtie.configure_rails_initialization" do |app|
@@ -63,56 +62,56 @@ module Rails
63
62
  # end
64
63
  # end
65
64
  #
66
- # Finally, you can also pass <tt>:before</tt> and <tt>:after</tt> as option to initializer,
67
- # in case you want to couple it with a specific step in the initialization process.
65
+ # Finally, you can also pass <tt>:before</tt> and <tt>:after</tt> as options to
66
+ # +initializer+, in case you want to couple it with a specific step in the
67
+ # initialization process.
68
68
  #
69
69
  # == Configuration
70
70
  #
71
- # Inside the Railtie class, you can access a config object which contains configuration
72
- # shared by all railties and the application:
71
+ # Railties can access a config object which contains configuration shared by all
72
+ # railties and the application:
73
73
  #
74
74
  # class MyRailtie < Rails::Railtie
75
75
  # # Customize the ORM
76
76
  # config.app_generators.orm :my_railtie_orm
77
77
  #
78
78
  # # Add a to_prepare block which is executed once in production
79
- # # and before each request in development
79
+ # # and before each request in development.
80
80
  # config.to_prepare do
81
81
  # MyRailtie.setup!
82
82
  # end
83
83
  # end
84
84
  #
85
- # == Loading rake tasks and generators
85
+ # == Loading Rake Tasks and Generators
86
86
  #
87
- # If your railtie has rake tasks, you can tell Rails to load them through the method
88
- # rake_tasks:
87
+ # If your railtie has Rake tasks, you can tell Rails to load them through the method
88
+ # +rake_tasks+:
89
89
  #
90
90
  # class MyRailtie < Rails::Railtie
91
91
  # rake_tasks do
92
- # load "path/to/my_railtie.tasks"
92
+ # load 'path/to/my_railtie.tasks'
93
93
  # end
94
94
  # end
95
95
  #
96
96
  # By default, Rails loads generators from your load path. However, if you want to place
97
- # your generators at a different location, you can specify in your Railtie a block which
97
+ # your generators at a different location, you can specify in your railtie a block which
98
98
  # will load them during normal generators lookup:
99
99
  #
100
100
  # class MyRailtie < Rails::Railtie
101
101
  # generators do
102
- # require "path/to/my_railtie_generator"
102
+ # require 'path/to/my_railtie_generator'
103
103
  # end
104
104
  # end
105
105
  #
106
106
  # == Application and Engine
107
107
  #
108
- # A Rails::Engine is nothing more than a Railtie with some initializers already set.
109
- # And since Rails::Application is an engine, the same configuration described here
110
- # can be used in both.
108
+ # An engine is nothing more than a railtie with some initializers already set. And since
109
+ # <tt>Rails::Application</tt> is an engine, the same configuration described here can be
110
+ # used in both.
111
111
  #
112
112
  # Be sure to look at the documentation of those specific classes for more information.
113
- #
114
113
  class Railtie
115
- autoload :Configuration, "rails/railtie/configuration"
114
+ autoload :Configuration, 'rails/railtie/configuration'
116
115
 
117
116
  include Initializable
118
117
 
@@ -1,14 +1,8 @@
1
+ require 'rails/dev_caching'
2
+
1
3
  namespace :dev do
2
4
  desc 'Toggle development mode caching on/off'
3
5
  task :cache do
4
- if File.exist? 'tmp/caching-dev.txt'
5
- File.delete 'tmp/caching-dev.txt'
6
- puts 'Development mode is no longer being cached.'
7
- else
8
- FileUtils.touch 'tmp/caching-dev.txt'
9
- puts 'Development mode is now being cached.'
10
- end
11
-
12
- FileUtils.touch 'tmp/restart.txt'
6
+ Rails::DevCaching.enable_by_file
13
7
  end
14
8
  end
@@ -1,4 +1,6 @@
1
- namespace :rails do
1
+ require 'active_support/deprecation'
2
+
3
+ namespace :app do
2
4
  desc "Update configs and some other initially generated files (or use just update:configs or update:bin)"
3
5
  task update: [ "update:configs", "update:bin" ]
4
6
 
@@ -24,12 +26,12 @@ namespace :rails do
24
26
 
25
27
  default_templates.each do |type, names|
26
28
  local_template_type_dir = File.join(project_templates, type)
27
- FileUtils.mkdir_p local_template_type_dir
29
+ mkdir_p local_template_type_dir, verbose: false
28
30
 
29
31
  names.each do |name|
30
32
  dst_name = File.join(local_template_type_dir, name)
31
33
  src_name = File.join(generators_lib, type, name, "templates")
32
- FileUtils.cp_r src_name, dst_name
34
+ cp_r src_name, dst_name, verbose: false
33
35
  end
34
36
  end
35
37
  end
@@ -45,8 +47,9 @@ namespace :rails do
45
47
  @app_generator ||= begin
46
48
  require 'rails/generators'
47
49
  require 'rails/generators/rails/app/app_generator'
48
- gen = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true, api: !!Rails.application.config.api_only },
49
- destination_root: Rails.root
50
+ gen = Rails::Generators::AppGenerator.new ["rails"],
51
+ { api: !!Rails.application.config.api_only },
52
+ destination_root: Rails.root
50
53
  File.exist?(Rails.root.join("config", "application.rb")) ?
51
54
  gen.send(:app_const) : gen.send(:valid_const?)
52
55
  gen
@@ -66,3 +69,15 @@ namespace :rails do
66
69
  end
67
70
  end
68
71
  end
72
+
73
+ namespace :rails do
74
+ %i(update template templates:copy update:configs update:bin).each do |task_name|
75
+ task "#{task_name}" do
76
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
77
+ Running #{task_name} with the rails: namespace is deprecated in favor of app: namespace.
78
+ Run bin/rails app:#{task_name} instead.
79
+ MSG
80
+ Rake.application.invoke_task("app:#{task_name}")
81
+ end
82
+ end
83
+ end
@@ -10,29 +10,46 @@ task about: :environment do
10
10
  end
11
11
 
12
12
  namespace :time do
13
+ desc 'List all time zones, list by two-letter country code (`rails time:zones[US]`), or list by UTC offset (`rails time:zones[-8]`)'
14
+ task :zones, :country_or_offset do |t, args|
15
+ zones, offset = ActiveSupport::TimeZone.all, nil
16
+
17
+ if country_or_offset = args[:country_or_offset]
18
+ begin
19
+ zones = ActiveSupport::TimeZone.country_zones(country_or_offset)
20
+ rescue TZInfo::InvalidCountryCode
21
+ offset = country_or_offset
22
+ end
23
+ end
24
+
25
+ build_time_zone_list zones, offset
26
+ end
27
+
13
28
  namespace :zones do
14
- desc 'Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6'
29
+ # desc 'Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6'
15
30
  task :all do
16
- build_time_zone_list(:all)
31
+ build_time_zone_list ActiveSupport::TimeZone.all
17
32
  end
18
33
 
19
34
  # desc 'Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6'
20
35
  task :us do
21
- build_time_zone_list(:us_zones)
36
+ build_time_zone_list ActiveSupport::TimeZone.us_zones
22
37
  end
23
38
 
24
39
  # desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time'
25
40
  task :local do
26
41
  require 'active_support'
27
42
  require 'active_support/time'
43
+
28
44
  jan_offset = Time.now.beginning_of_year.utc_offset
29
45
  jul_offset = Time.now.beginning_of_year.change(month: 7).utc_offset
30
46
  offset = jan_offset < jul_offset ? jan_offset : jul_offset
31
- build_time_zone_list(:all, offset)
47
+
48
+ build_time_zone_list(ActiveSupport::TimeZone.all, offset)
32
49
  end
33
50
 
34
51
  # to find UTC -06:00 zones, OFFSET can be set to either -6, -6:00 or 21600
35
- def build_time_zone_list(method, offset = ENV['OFFSET'])
52
+ def build_time_zone_list(zones, offset = ENV['OFFSET'])
36
53
  require 'active_support'
37
54
  require 'active_support/time'
38
55
  if offset
@@ -47,7 +64,7 @@ namespace :time do
47
64
  end
48
65
  end
49
66
  previous_offset = nil
50
- ActiveSupport::TimeZone.__send__(method).each do |zone|
67
+ zones.each do |zone|
51
68
  if offset.nil? || offset == zone.utc_offset
52
69
  puts "\n* UTC #{zone.formatted_offset} *" unless zone.utc_offset == previous_offset
53
70
  puts zone.name
@@ -1,5 +1,8 @@
1
- desc "Restart app by touching tmp/restart.txt"
1
+ desc 'Restart app by touching tmp/restart.txt'
2
2
  task :restart do
3
- FileUtils.mkdir_p('tmp')
4
- FileUtils.touch('tmp/restart.txt')
3
+ verbose(false) do
4
+ mkdir_p 'tmp'
5
+ touch 'tmp/restart.txt'
6
+ rm_f 'tmp/pids/server.pid'
7
+ end
5
8
  end
@@ -19,6 +19,9 @@ task routes: :environment do
19
19
 
20
20
  OptionParser.new do |opts|
21
21
  opts.banner = "Usage: rails routes [options]"
22
+
23
+ Rake.application.standard_rake_options.each { |args| opts.on(*args) }
24
+
22
25
  opts.on("-c CONTROLLER") do |controller|
23
26
  routes_filter = { controller: controller }
24
27
  end
@@ -7,6 +7,7 @@ STATS_DIRECTORIES = [
7
7
  %w(Jobs app/jobs),
8
8
  %w(Models app/models),
9
9
  %w(Mailers app/mailers),
10
+ %w(Channels app/channels),
10
11
  %w(Javascripts app/assets/javascripts),
11
12
  %w(Libraries lib/),
12
13
  %w(Tasks lib/tasks),