railties 4.2.11.3 → 5.0.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 +262 -206
- data/MIT-LICENSE +20 -0
- data/README.rdoc +1 -1
- data/{bin → exe}/rails +0 -0
- data/lib/rails.rb +19 -1
- data/lib/rails/all.rb +10 -9
- data/lib/rails/api/task.rb +7 -14
- data/lib/rails/{app_rails_loader.rb → app_loader.rb} +4 -3
- data/lib/rails/application.rb +31 -41
- data/lib/rails/application/bootstrap.rb +1 -14
- data/lib/rails/application/configuration.rb +94 -95
- data/lib/rails/application/default_middleware_stack.rb +30 -16
- data/lib/rails/application/finisher.rb +11 -2
- data/lib/rails/application/routes_reloader.rb +1 -3
- data/lib/rails/application_controller.rb +1 -1
- data/lib/rails/cli.rb +2 -2
- data/lib/rails/code_statistics.rb +6 -8
- data/lib/rails/code_statistics_calculator.rb +8 -1
- data/lib/rails/command.rb +70 -0
- data/lib/rails/commands.rb +5 -3
- data/lib/rails/commands/commands_tasks.rb +25 -14
- data/lib/rails/commands/console.rb +7 -52
- data/lib/rails/commands/console_helper.rb +34 -0
- data/lib/rails/commands/dbconsole.rb +59 -78
- data/lib/rails/commands/dev_cache.rb +21 -0
- data/lib/rails/commands/plugin.rb +1 -1
- data/lib/rails/commands/rake_proxy.rb +34 -0
- data/lib/rails/commands/runner.rb +0 -1
- data/lib/rails/commands/server.rb +29 -36
- data/lib/rails/commands/test.rb +9 -0
- data/lib/rails/configuration.rb +21 -5
- data/lib/rails/console/app.rb +5 -0
- data/lib/rails/console/helpers.rb +1 -1
- data/lib/rails/engine.rb +68 -58
- data/lib/rails/engine/commands.rb +4 -2
- data/lib/rails/engine/configuration.rb +4 -10
- data/lib/rails/gem_version.rb +4 -4
- data/lib/rails/generators.rb +30 -7
- data/lib/rails/generators/.named_base.rb.swp +0 -0
- data/lib/rails/generators/actions.rb +19 -5
- data/lib/rails/generators/app_base.rb +65 -45
- data/lib/rails/generators/base.rb +6 -6
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +5 -8
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +9 -7
- data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +1 -1
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb +2 -2
- data/lib/rails/generators/erb/scaffold/templates/new.html.erb +1 -1
- data/lib/rails/generators/generated_attribute.rb +5 -1
- data/lib/rails/generators/migration.rb +7 -7
- data/lib/rails/generators/named_base.rb +21 -5
- data/lib/rails/generators/rails/app/USAGE +0 -1
- data/lib/rails/generators/rails/app/app_generator.rb +75 -11
- data/lib/rails/generators/rails/app/templates/Gemfile +17 -13
- data/lib/rails/generators/rails/app/templates/{README.rdoc → README.md} +1 -5
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +7 -0
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee +11 -0
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +3 -3
- data/lib/rails/generators/rails/app/templates/app/channels/application_cable/channel.rb +5 -0
- data/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb +5 -0
- data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +3 -1
- data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb +2 -0
- data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb +4 -0
- data/lib/rails/generators/rails/app/templates/app/models/application_record.rb +3 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +20 -17
- data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +13 -0
- data/lib/rails/generators/{erb/mailer/templates/layout.text.erb → rails/app/templates/app/views/layouts/mailer.text.erb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/bin/setup +17 -12
- data/lib/rails/generators/rails/app/templates/bin/update +28 -0
- data/lib/rails/generators/rails/app/templates/config.ru.tt +11 -0
- data/lib/rails/generators/rails/app/templates/config/application.rb +9 -14
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +20 -3
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +18 -11
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +7 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/active_record_belongs_to_required_by_default.rb +5 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +6 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/callback_terminator.rb +5 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb +1 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb +16 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/request_forgery_protection.rb +4 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/redis/cable.yml +9 -0
- data/lib/rails/generators/rails/app/templates/config/routes.rb +3 -53
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +3 -3
- data/lib/rails/generators/rails/app/templates/gitignore +7 -1
- data/lib/rails/generators/rails/controller/controller_generator.rb +6 -4
- data/lib/rails/generators/rails/migration/migration_generator.rb +1 -1
- data/lib/rails/generators/rails/model/USAGE +6 -1
- data/lib/rails/generators/rails/model/model_generator.rb +1 -1
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +88 -35
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec +6 -9
- data/lib/rails/generators/rails/plugin/templates/Gemfile +3 -7
- data/lib/rails/generators/rails/plugin/templates/README.md +3 -0
- data/lib/rails/generators/rails/plugin/templates/Rakefile +2 -2
- data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +5 -0
- data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +5 -0
- data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +5 -0
- data/lib/rails/generators/rails/plugin/templates/app/models/application_record.rb.tt +6 -0
- data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +14 -0
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/bin/test.tt +8 -0
- data/lib/rails/generators/rails/plugin/templates/config/routes.rb +1 -1
- data/lib/rails/generators/rails/plugin/templates/gitignore +2 -3
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb +5 -0
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb +7 -0
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb +1 -0
- data/lib/rails/generators/rails/plugin/templates/lib/tasks/{%name%_tasks.rake → %namespaced_name%_tasks.rake} +1 -1
- data/lib/rails/generators/rails/plugin/templates/rails/application.rb +3 -3
- data/lib/rails/generators/rails/plugin/templates/rails/dummy_manifest.js +11 -0
- data/lib/rails/generators/rails/plugin/templates/rails/engine_manifest.js +6 -0
- data/lib/rails/generators/rails/plugin/templates/rails/javascripts.js +1 -1
- data/lib/rails/generators/rails/plugin/templates/rails/routes.rb +1 -2
- data/lib/rails/generators/rails/plugin/templates/rails/stylesheets.css +3 -3
- data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb +7 -0
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +4 -2
- data/lib/rails/generators/rails/resource/resource_generator.rb +0 -1
- data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +0 -1
- data/lib/rails/generators/rails/scaffold/USAGE +1 -1
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -1
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css +35 -7
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +4 -1
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb +61 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +1 -1
- data/lib/rails/generators/resource_helpers.rb +3 -3
- data/lib/rails/generators/test_unit/controller/templates/.functional_test.rb.swp +0 -0
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +3 -5
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +8 -3
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +2 -2
- data/lib/rails/generators/test_unit/mailer/templates/preview.rb +4 -4
- data/lib/rails/generators/test_unit/model/model_generator.rb +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml +2 -0
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +5 -1
- data/lib/rails/generators/test_unit/scaffold/templates/.api_functional_test.rb.swp +0 -0
- data/lib/rails/generators/test_unit/scaffold/templates/.functional_test.rb.swp +0 -0
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb +44 -0
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +14 -14
- data/lib/rails/generators/testing/assertions.rb +0 -2
- data/lib/rails/generators/testing/behaviour.rb +4 -17
- data/lib/rails/info.rb +2 -2
- data/lib/rails/info_controller.rb +23 -2
- data/lib/rails/mailers_controller.rb +2 -2
- data/lib/rails/paths.rb +14 -6
- data/lib/rails/rack.rb +1 -3
- data/lib/rails/rack/debugger.rb +2 -23
- data/lib/rails/rack/logger.rb +4 -0
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/source_annotation_extractor.rb +1 -1
- data/lib/rails/tasks.rb +4 -1
- data/lib/rails/tasks/engine.rake +1 -1
- data/lib/rails/tasks/framework.rake +18 -16
- data/lib/rails/tasks/initializers.rake +6 -0
- data/lib/rails/tasks/restart.rake +5 -0
- data/lib/rails/tasks/statistics.rake +5 -6
- data/lib/rails/tasks/tmp.rake +4 -12
- data/lib/rails/templates/rails/mailers/email.html.erb +17 -3
- data/lib/rails/templates/rails/welcome/index.html.erb +10 -3
- data/lib/rails/test_help.rb +7 -8
- data/lib/rails/test_unit/minitest_plugin.rb +91 -0
- data/lib/rails/test_unit/reporter.rb +74 -0
- data/lib/rails/test_unit/test_requirer.rb +28 -0
- data/lib/rails/test_unit/testing.rake +18 -39
- metadata +80 -33
- data/lib/rails/deprecation.rb +0 -19
- data/lib/rails/generators/erb/mailer/templates/layout.html.erb +0 -5
- data/lib/rails/generators/rails/app/templates/config.ru +0 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/to_time_preserves_timezone.rb +0 -10
- data/lib/rails/generators/rails/plugin/templates/README.rdoc +0 -3
- data/lib/rails/generators/rails/plugin/templates/app/controllers/%name%/application_controller.rb.tt +0 -5
- data/lib/rails/generators/rails/plugin/templates/app/helpers/%name%/application_helper.rb.tt +0 -4
- data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%name%/application.html.erb.tt +0 -14
- data/lib/rails/generators/rails/plugin/templates/lib/%name%.rb +0 -6
- data/lib/rails/generators/rails/plugin/templates/lib/%name%/engine.rb +0 -7
- data/lib/rails/generators/rails/plugin/templates/lib/%name%/version.rb +0 -3
- data/lib/rails/generators/rails/plugin/templates/test/%name%_test.rb +0 -7
- data/lib/rails/rack/log_tailer.rb +0 -38
- data/lib/rails/tasks/documentation.rake +0 -70
- data/lib/rails/test_unit/sub_test_task.rb +0 -126
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module ConsoleHelper # :nodoc:
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def start(*args)
|
9
|
+
new(*args).start
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def set_options_env(arguments, options)
|
14
|
+
if arguments.first && arguments.first[0] != '-'
|
15
|
+
env = arguments.first
|
16
|
+
if available_environments.include? env
|
17
|
+
options[:environment] = env
|
18
|
+
else
|
19
|
+
options[:environment] = %w(production development test).detect { |e| e =~ /^#{env}/ } || env
|
20
|
+
end
|
21
|
+
end
|
22
|
+
options
|
23
|
+
end
|
24
|
+
|
25
|
+
def available_environments
|
26
|
+
Dir['config/environments/*.rb'].map { |fname| File.basename(fname, '.*') }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def environment
|
31
|
+
ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,14 +1,49 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'yaml'
|
3
3
|
require 'optparse'
|
4
|
-
require '
|
4
|
+
require 'rails/commands/console_helper'
|
5
5
|
|
6
6
|
module Rails
|
7
7
|
class DBConsole
|
8
|
+
include ConsoleHelper
|
9
|
+
|
8
10
|
attr_reader :arguments
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
class << self
|
13
|
+
def parse_arguments(arguments)
|
14
|
+
options = {}
|
15
|
+
|
16
|
+
OptionParser.new do |opt|
|
17
|
+
opt.banner = "Usage: rails dbconsole [environment] [options]"
|
18
|
+
opt.on("-p", "--include-password", "Automatically provide the password from database.yml") do |v|
|
19
|
+
options['include_password'] = true
|
20
|
+
end
|
21
|
+
|
22
|
+
opt.on("--mode [MODE]", ['html', 'list', 'line', 'column'],
|
23
|
+
"Automatically put the sqlite3 database in the specified mode (html, list, line, column).") do |mode|
|
24
|
+
options['mode'] = mode
|
25
|
+
end
|
26
|
+
|
27
|
+
opt.on("--header") do |h|
|
28
|
+
options['header'] = h
|
29
|
+
end
|
30
|
+
|
31
|
+
opt.on("-h", "--help", "Show this help message.") do
|
32
|
+
puts opt
|
33
|
+
exit
|
34
|
+
end
|
35
|
+
|
36
|
+
opt.on("-e", "--environment=name", String,
|
37
|
+
"Specifies the environment to run this console under (test/development/production).",
|
38
|
+
"Default: development"
|
39
|
+
) { |v| options[:environment] = v.strip }
|
40
|
+
|
41
|
+
opt.parse!(arguments)
|
42
|
+
abort opt.to_s unless (0..1).include?(arguments.size)
|
43
|
+
end
|
44
|
+
|
45
|
+
set_options_env(arguments, options)
|
46
|
+
end
|
12
47
|
end
|
13
48
|
|
14
49
|
def initialize(arguments = ARGV)
|
@@ -16,7 +51,7 @@ module Rails
|
|
16
51
|
end
|
17
52
|
|
18
53
|
def start
|
19
|
-
options = parse_arguments(arguments)
|
54
|
+
options = self.class.parse_arguments(arguments)
|
20
55
|
ENV['RAILS_ENV'] = options[:environment] || environment
|
21
56
|
|
22
57
|
case config["adapter"]
|
@@ -51,9 +86,6 @@ module Rails
|
|
51
86
|
ENV['PGPASSWORD'] = config["password"].to_s if config["password"] && options['include_password']
|
52
87
|
find_cmd_and_exec('psql', config["database"])
|
53
88
|
|
54
|
-
when "sqlite"
|
55
|
-
find_cmd_and_exec('sqlite', config["database"])
|
56
|
-
|
57
89
|
when "sqlite3"
|
58
90
|
args = []
|
59
91
|
|
@@ -105,88 +137,37 @@ module Rails
|
|
105
137
|
end
|
106
138
|
|
107
139
|
def environment
|
108
|
-
|
109
|
-
Rails.env
|
110
|
-
else
|
111
|
-
ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
|
112
|
-
end
|
140
|
+
Rails.respond_to?(:env) ? Rails.env : super
|
113
141
|
end
|
114
142
|
|
115
143
|
protected
|
144
|
+
def configurations
|
145
|
+
require APP_PATH
|
146
|
+
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
|
147
|
+
ActiveRecord::Base.configurations
|
148
|
+
end
|
116
149
|
|
117
|
-
|
118
|
-
|
119
|
-
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
|
120
|
-
ActiveRecord::Base.configurations
|
121
|
-
end
|
122
|
-
|
123
|
-
def parse_arguments(arguments)
|
124
|
-
options = {}
|
125
|
-
|
126
|
-
OptionParser.new do |opt|
|
127
|
-
opt.banner = "Usage: rails dbconsole [environment] [options]"
|
128
|
-
opt.on("-p", "--include-password", "Automatically provide the password from database.yml") do |v|
|
129
|
-
options['include_password'] = true
|
130
|
-
end
|
131
|
-
|
132
|
-
opt.on("--mode [MODE]", ['html', 'list', 'line', 'column'],
|
133
|
-
"Automatically put the sqlite3 database in the specified mode (html, list, line, column).") do |mode|
|
134
|
-
options['mode'] = mode
|
135
|
-
end
|
150
|
+
def find_cmd_and_exec(commands, *args)
|
151
|
+
commands = Array(commands)
|
136
152
|
|
137
|
-
|
138
|
-
|
153
|
+
dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR)
|
154
|
+
unless (ext = RbConfig::CONFIG['EXEEXT']).empty?
|
155
|
+
commands = commands.map{|cmd| "#{cmd}#{ext}"}
|
139
156
|
end
|
140
157
|
|
141
|
-
|
142
|
-
|
143
|
-
|
158
|
+
full_path_command = nil
|
159
|
+
found = commands.detect do |cmd|
|
160
|
+
dirs_on_path.detect do |path|
|
161
|
+
full_path_command = File.join(path, cmd)
|
162
|
+
File.file?(full_path_command) && File.executable?(full_path_command)
|
163
|
+
end
|
144
164
|
end
|
145
165
|
|
146
|
-
|
147
|
-
|
148
|
-
"Default: development"
|
149
|
-
) { |v| options[:environment] = v.strip }
|
150
|
-
|
151
|
-
opt.parse!(arguments)
|
152
|
-
abort opt.to_s unless (0..1).include?(arguments.size)
|
153
|
-
end
|
154
|
-
|
155
|
-
if arguments.first && arguments.first[0] != '-'
|
156
|
-
env = arguments.first
|
157
|
-
if available_environments.include? env
|
158
|
-
options[:environment] = env
|
166
|
+
if found
|
167
|
+
exec full_path_command, *args
|
159
168
|
else
|
160
|
-
|
169
|
+
abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
|
161
170
|
end
|
162
171
|
end
|
163
|
-
|
164
|
-
options
|
165
|
-
end
|
166
|
-
|
167
|
-
def available_environments
|
168
|
-
Dir['config/environments/*.rb'].map { |fname| File.basename(fname, '.*') }
|
169
|
-
end
|
170
|
-
|
171
|
-
def find_cmd_and_exec(commands, *args)
|
172
|
-
commands = Array(commands)
|
173
|
-
|
174
|
-
dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR)
|
175
|
-
commands += commands.map{|cmd| "#{cmd}.exe"} if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
176
|
-
|
177
|
-
full_path_command = nil
|
178
|
-
found = commands.detect do |cmd|
|
179
|
-
dirs_on_path.detect do |path|
|
180
|
-
full_path_command = File.join(path, cmd)
|
181
|
-
File.file?(full_path_command) && File.executable?(full_path_command)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
if found
|
186
|
-
exec full_path_command, *args
|
187
|
-
else
|
188
|
-
abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
|
189
|
-
end
|
190
|
-
end
|
191
172
|
end
|
192
173
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails/command'
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Commands
|
5
|
+
# This is a wrapper around the Rails dev:cache command
|
6
|
+
class DevCache < Command
|
7
|
+
set_banner :dev_cache, 'Toggle development mode caching on/off'
|
8
|
+
def dev_cache
|
9
|
+
if File.exist? 'tmp/caching-dev.txt'
|
10
|
+
File.delete 'tmp/caching-dev.txt'
|
11
|
+
puts 'Development mode is no longer being cached.'
|
12
|
+
else
|
13
|
+
FileUtils.touch 'tmp/caching-dev.txt'
|
14
|
+
puts 'Development mode is now being cached.'
|
15
|
+
end
|
16
|
+
|
17
|
+
FileUtils.touch 'tmp/restart.txt'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -11,7 +11,7 @@ else
|
|
11
11
|
end
|
12
12
|
if File.exist?(railsrc)
|
13
13
|
extra_args_string = File.read(railsrc)
|
14
|
-
extra_args = extra_args_string.split(/\n+/).flat_map
|
14
|
+
extra_args = extra_args_string.split(/\n+/).flat_map(&:split)
|
15
15
|
puts "Using #{extra_args.join(" ")} from #{railsrc}"
|
16
16
|
ARGV.insert(1, *extra_args)
|
17
17
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'active_support'
|
3
|
+
|
4
|
+
module Rails
|
5
|
+
module RakeProxy #:nodoc:
|
6
|
+
private
|
7
|
+
def run_rake_task(command)
|
8
|
+
ARGV.unshift(command) # Prepend the command, so Rake knows how to run it.
|
9
|
+
|
10
|
+
Rake.application.standard_exception_handling do
|
11
|
+
Rake.application.init('rails')
|
12
|
+
Rake.application.load_rakefile
|
13
|
+
Rake.application.top_level
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def rake_tasks
|
18
|
+
return @rake_tasks if defined?(@rake_tasks)
|
19
|
+
|
20
|
+
ActiveSupport::Deprecation.silence do
|
21
|
+
require_application_and_environment!
|
22
|
+
end
|
23
|
+
|
24
|
+
Rake::TaskManager.record_task_metadata = true
|
25
|
+
Rake.application.instance_variable_set(:@name, 'rails')
|
26
|
+
Rails.application.load_tasks
|
27
|
+
@rake_tasks = Rake.application.tasks.select(&:comment)
|
28
|
+
end
|
29
|
+
|
30
|
+
def formatted_rake_tasks
|
31
|
+
rake_tasks.map { |t| [ t.name_with_args, t.comment ] }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -28,20 +28,15 @@ module Rails
|
|
28
28
|
opts.on("-c", "--config=file", String,
|
29
29
|
"Uses a custom rackup configuration.") { |v| options[:config] = v }
|
30
30
|
opts.on("-d", "--daemon", "Runs server as a Daemon.") { options[:daemonize] = true }
|
31
|
-
opts.on("-u", "--debugger", "Enables the debugger.") do
|
32
|
-
if RUBY_VERSION < '2.0.0'
|
33
|
-
options[:debugger] = true
|
34
|
-
else
|
35
|
-
puts "=> Notice: debugger option is ignored since Ruby 2.0 and " \
|
36
|
-
"it will be removed in future versions."
|
37
|
-
end
|
38
|
-
end
|
39
31
|
opts.on("-e", "--environment=name", String,
|
40
32
|
"Specifies the environment to run this server under (test/development/production).",
|
41
33
|
"Default: development") { |v| options[:environment] = v }
|
42
34
|
opts.on("-P", "--pid=pid", String,
|
43
35
|
"Specifies the PID file.",
|
44
36
|
"Default: tmp/pids/server.pid") { |v| options[:pid] = v }
|
37
|
+
opts.on("-C", "--[no-]dev-caching",
|
38
|
+
"Specifies whether to perform caching in development.",
|
39
|
+
"true or false") { |v| options[:caching] = v }
|
45
40
|
|
46
41
|
opts.separator ""
|
47
42
|
|
@@ -75,6 +70,7 @@ module Rails
|
|
75
70
|
print_boot_information
|
76
71
|
trap(:INT) { exit }
|
77
72
|
create_tmp_directories
|
73
|
+
setup_dev_caching
|
78
74
|
log_to_stdout if options[:log_stdout]
|
79
75
|
|
80
76
|
super
|
@@ -85,41 +81,32 @@ module Rails
|
|
85
81
|
end
|
86
82
|
|
87
83
|
def middleware
|
88
|
-
|
89
|
-
if RUBY_VERSION < '2.0.0'
|
90
|
-
middlewares << [Rails::Rack::Debugger] if options[:debugger]
|
91
|
-
end
|
92
|
-
middlewares << [::Rack::ContentLength]
|
93
|
-
|
94
|
-
# FIXME: add Rack::Lock in the case people are using webrick.
|
95
|
-
# This is to remain backwards compatible for those who are
|
96
|
-
# running webrick in production. We should consider removing this
|
97
|
-
# in development.
|
98
|
-
if server.name == 'Rack::Handler::WEBrick'
|
99
|
-
middlewares << [::Rack::Lock]
|
100
|
-
end
|
101
|
-
|
102
|
-
Hash.new(middlewares)
|
103
|
-
end
|
104
|
-
|
105
|
-
def log_path
|
106
|
-
"log/#{options[:environment]}.log"
|
84
|
+
Hash.new([])
|
107
85
|
end
|
108
86
|
|
109
87
|
def default_options
|
110
88
|
super.merge({
|
111
|
-
Port: 3000,
|
89
|
+
Port: ENV.fetch('PORT', 3000).to_i,
|
112
90
|
DoNotReverseLookup: true,
|
113
91
|
environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup,
|
114
92
|
daemonize: false,
|
115
|
-
|
116
|
-
pid: File.expand_path("tmp/pids/server.pid")
|
117
|
-
config: File.expand_path("config.ru")
|
93
|
+
caching: false,
|
94
|
+
pid: File.expand_path("tmp/pids/server.pid")
|
118
95
|
})
|
119
96
|
end
|
120
97
|
|
121
98
|
private
|
122
99
|
|
100
|
+
def setup_dev_caching
|
101
|
+
return unless options[:environment] == "development"
|
102
|
+
|
103
|
+
if options[:caching] == false
|
104
|
+
delete_cache_file
|
105
|
+
elsif options[:caching]
|
106
|
+
create_cache_file
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
123
110
|
def print_boot_information
|
124
111
|
url = "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}"
|
125
112
|
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
|
@@ -129,8 +116,16 @@ module Rails
|
|
129
116
|
puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
|
130
117
|
end
|
131
118
|
|
119
|
+
def create_cache_file
|
120
|
+
FileUtils.touch("tmp/caching-dev.txt")
|
121
|
+
end
|
122
|
+
|
123
|
+
def delete_cache_file
|
124
|
+
FileUtils.rm("tmp/caching-dev.txt") if File.exist?("tmp/caching-dev.txt")
|
125
|
+
end
|
126
|
+
|
132
127
|
def create_tmp_directories
|
133
|
-
%w(cache pids
|
128
|
+
%w(cache pids sockets).each do |dir_to_make|
|
134
129
|
FileUtils.mkdir_p(File.join(Rails.root, 'tmp', dir_to_make))
|
135
130
|
end
|
136
131
|
end
|
@@ -138,13 +133,11 @@ module Rails
|
|
138
133
|
def log_to_stdout
|
139
134
|
wrapped_app # touch the app so the logger is set up
|
140
135
|
|
141
|
-
console = ActiveSupport::Logger.new(
|
136
|
+
console = ActiveSupport::Logger.new($stdout)
|
142
137
|
console.formatter = Rails.logger.formatter
|
143
138
|
console.level = Rails.logger.level
|
144
139
|
|
145
|
-
|
146
|
-
Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
|
147
|
-
end
|
140
|
+
Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
|
148
141
|
end
|
149
142
|
end
|
150
143
|
end
|
data/lib/rails/configuration.rb
CHANGED
@@ -33,8 +33,9 @@ module Rails
|
|
33
33
|
# config.middleware.delete ActionDispatch::Flash
|
34
34
|
#
|
35
35
|
class MiddlewareStackProxy
|
36
|
-
def initialize
|
37
|
-
@operations =
|
36
|
+
def initialize(operations = [], delete_operations = [])
|
37
|
+
@operations = operations
|
38
|
+
@delete_operations = delete_operations
|
38
39
|
end
|
39
40
|
|
40
41
|
def insert_before(*args, &block)
|
@@ -56,7 +57,7 @@ module Rails
|
|
56
57
|
end
|
57
58
|
|
58
59
|
def delete(*args, &block)
|
59
|
-
@
|
60
|
+
@delete_operations << [__method__, args, block]
|
60
61
|
end
|
61
62
|
|
62
63
|
def unshift(*args, &block)
|
@@ -64,15 +65,29 @@ module Rails
|
|
64
65
|
end
|
65
66
|
|
66
67
|
def merge_into(other) #:nodoc:
|
67
|
-
@operations.each do |operation, args, block|
|
68
|
+
(@operations + @delete_operations).each do |operation, args, block|
|
68
69
|
other.send(operation, *args, &block)
|
69
70
|
end
|
71
|
+
|
70
72
|
other
|
71
73
|
end
|
74
|
+
|
75
|
+
def +(other) # :nodoc:
|
76
|
+
MiddlewareStackProxy.new(@operations + other.operations, @delete_operations + other.delete_operations)
|
77
|
+
end
|
78
|
+
|
79
|
+
protected
|
80
|
+
def operations
|
81
|
+
@operations
|
82
|
+
end
|
83
|
+
|
84
|
+
def delete_operations
|
85
|
+
@delete_operations
|
86
|
+
end
|
72
87
|
end
|
73
88
|
|
74
89
|
class Generators #:nodoc:
|
75
|
-
attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging
|
90
|
+
attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging, :api_only
|
76
91
|
attr_reader :hidden_namespaces
|
77
92
|
|
78
93
|
def initialize
|
@@ -81,6 +96,7 @@ module Rails
|
|
81
96
|
@fallbacks = {}
|
82
97
|
@templates = []
|
83
98
|
@colorize_logging = true
|
99
|
+
@api_only = false
|
84
100
|
@hidden_namespaces = []
|
85
101
|
end
|
86
102
|
|