railties 7.0.4 → 7.1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +729 -174
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.md +99 -0
- data/README.rdoc +5 -5
- data/lib/minitest/rails_plugin.rb +63 -0
- data/lib/rails/api/task.rb +35 -4
- data/lib/rails/app_updater.rb +1 -1
- data/lib/rails/application/bootstrap.rb +23 -4
- data/lib/rails/application/configuration.rb +190 -70
- data/lib/rails/application/default_middleware_stack.rb +8 -2
- data/lib/rails/application/dummy_config.rb +19 -0
- data/lib/rails/application/finisher.rb +43 -33
- data/lib/rails/application.rb +159 -59
- data/lib/rails/application_controller.rb +1 -1
- data/lib/rails/backtrace_cleaner.rb +1 -1
- data/lib/rails/cli.rb +5 -2
- data/lib/rails/command/actions.rb +10 -12
- data/lib/rails/command/base.rb +55 -53
- data/lib/rails/command/environment_argument.rb +32 -16
- data/lib/rails/command/helpers/editor.rb +17 -12
- data/lib/rails/command.rb +84 -33
- data/lib/rails/commands/about/about_command.rb +14 -0
- data/lib/rails/commands/application/application_command.rb +2 -0
- data/lib/rails/commands/console/console_command.rb +17 -13
- data/lib/rails/commands/credentials/USAGE +53 -55
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +5 -3
- data/lib/rails/commands/credentials/credentials_command.rb +64 -70
- data/lib/rails/commands/db/system/change/change_command.rb +2 -1
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +25 -115
- data/lib/rails/commands/destroy/destroy_command.rb +3 -2
- data/lib/rails/commands/dev/dev_command.rb +1 -6
- data/lib/rails/commands/encrypted/USAGE +15 -20
- data/lib/rails/commands/encrypted/encrypted_command.rb +46 -35
- data/lib/rails/commands/gem_help/USAGE +16 -0
- data/lib/rails/commands/gem_help/gem_help_command.rb +13 -0
- data/lib/rails/commands/generate/generate_command.rb +2 -2
- data/lib/rails/commands/help/USAGE +13 -13
- data/lib/rails/commands/help/help_command.rb +21 -2
- data/lib/rails/commands/initializers/initializers_command.rb +1 -4
- data/lib/rails/commands/middleware/middleware_command.rb +17 -0
- data/lib/rails/commands/new/new_command.rb +2 -0
- data/lib/rails/commands/notes/notes_command.rb +2 -1
- data/lib/rails/commands/plugin/plugin_command.rb +2 -0
- data/lib/rails/commands/rake/rake_command.rb +25 -22
- data/lib/rails/commands/restart/restart_command.rb +14 -0
- data/lib/rails/commands/routes/routes_command.rb +13 -1
- data/lib/rails/commands/runner/USAGE +14 -12
- data/lib/rails/commands/runner/runner_command.rb +32 -20
- data/lib/rails/commands/secret/secret_command.rb +13 -0
- data/lib/rails/commands/secrets/USAGE +44 -49
- data/lib/rails/commands/secrets/secrets_command.rb +20 -38
- data/lib/rails/commands/server/server_command.rb +33 -32
- data/lib/rails/commands/test/USAGE +14 -0
- data/lib/rails/commands/test/test_command.rb +56 -14
- data/lib/rails/commands/unused_routes/unused_routes_command.rb +75 -0
- data/lib/rails/commands/version/version_command.rb +1 -0
- data/lib/rails/configuration.rb +5 -5
- data/lib/rails/console/app.rb +1 -4
- data/lib/rails/deprecator.rb +7 -0
- data/lib/rails/engine/configuration.rb +50 -6
- data/lib/rails/engine.rb +49 -21
- data/lib/rails/gem_version.rb +4 -4
- data/lib/rails/generators/actions.rb +178 -59
- data/lib/rails/generators/active_model.rb +28 -14
- data/lib/rails/generators/app_base.rb +355 -82
- data/lib/rails/generators/app_name.rb +3 -14
- data/lib/rails/generators/base.rb +17 -9
- data/lib/rails/generators/database.rb +39 -1
- data/lib/rails/generators/erb/mailer/templates/layout.html.erb.tt +1 -1
- data/lib/rails/generators/generated_attribute.rb +12 -0
- data/lib/rails/generators/migration.rb +1 -2
- data/lib/rails/generators/model_helpers.rb +2 -1
- data/lib/rails/generators/rails/app/USAGE +22 -6
- data/lib/rails/generators/rails/app/app_generator.rb +83 -62
- data/lib/rails/generators/rails/app/templates/Dockerfile.tt +103 -0
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +10 -10
- data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +10 -1
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +6 -17
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +4 -6
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/trilogy.yml.tt +59 -0
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +11 -1
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +31 -27
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +12 -8
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +2 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_1.rb.tt +284 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -9
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +11 -13
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +11 -19
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +5 -1
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +6 -4
- data/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +10 -0
- data/lib/rails/generators/rails/app/templates/dockerignore.tt +43 -0
- data/lib/rails/generators/rails/app/templates/gitignore.tt +4 -8
- data/lib/rails/generators/rails/app/templates/node-version.tt +1 -0
- data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +10 -8
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +9 -7
- data/lib/rails/generators/rails/application_record/application_record_generator.rb +4 -0
- data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +2 -1
- data/lib/rails/generators/rails/controller/USAGE +12 -4
- data/lib/rails/generators/rails/controller/controller_generator.rb +5 -0
- data/lib/rails/generators/rails/controller/templates/controller.rb.tt +1 -1
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +29 -24
- data/lib/rails/generators/rails/credentials/templates/credentials.yml.tt +8 -0
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +30 -0
- data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +1 -2
- data/lib/rails/generators/rails/migration/USAGE +21 -11
- data/lib/rails/generators/rails/model/model_generator.rb +4 -0
- data/lib/rails/generators/rails/plugin/USAGE +17 -6
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +4 -13
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -15
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +0 -2
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +4 -4
- data/lib/rails/generators/rails/resource/resource_generator.rb +6 -0
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -1
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -1
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +2 -2
- data/lib/rails/generators/test_case.rb +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +1 -1
- data/lib/rails/generators/testing/{behaviour.rb → behavior.rb} +5 -2
- data/lib/rails/generators.rb +6 -14
- data/lib/rails/health_controller.rb +55 -0
- data/lib/rails/info.rb +1 -1
- data/lib/rails/info_controller.rb +31 -11
- data/lib/rails/mailers_controller.rb +15 -5
- data/lib/rails/paths.rb +13 -10
- data/lib/rails/rack/logger.rb +15 -12
- data/lib/rails/rackup/server.rb +15 -0
- data/lib/rails/railtie/configuration.rb +14 -1
- data/lib/rails/railtie.rb +18 -18
- data/lib/rails/ruby_version_check.rb +2 -0
- data/lib/rails/secrets.rb +10 -8
- data/lib/rails/source_annotation_extractor.rb +67 -18
- data/lib/rails/tasks/engine.rake +8 -8
- data/lib/rails/tasks/framework.rake +4 -10
- data/lib/rails/tasks/log.rake +1 -1
- data/lib/rails/tasks/misc.rake +3 -14
- data/lib/rails/tasks/statistics.rake +5 -4
- data/lib/rails/tasks/tmp.rake +5 -5
- data/lib/rails/tasks/zeitwerk.rake +15 -35
- data/lib/rails/tasks.rb +0 -2
- data/lib/rails/templates/rails/mailers/email.html.erb +32 -0
- data/lib/rails/templates/rails/mailers/index.html.erb +14 -7
- data/lib/rails/templates/rails/mailers/mailer.html.erb +11 -5
- data/lib/rails/templates/rails/welcome/index.html.erb +1 -0
- data/lib/rails/test_help.rb +13 -14
- data/lib/rails/test_unit/line_filtering.rb +1 -1
- data/lib/rails/test_unit/reporter.rb +6 -2
- data/lib/rails/test_unit/runner.rb +36 -18
- data/lib/rails/test_unit/test_parser.rb +88 -0
- data/lib/rails/test_unit/testing.rake +13 -33
- data/lib/rails/testing/maintain_test_schema.rb +16 -0
- data/lib/rails/version.rb +1 -1
- data/lib/rails/zeitwerk_checker.rb +15 -0
- data/lib/rails.rb +15 -15
- metadata +66 -29
- data/RDOC_MAIN.rdoc +0 -97
- data/lib/rails/application/dummy_erb_compiler.rb +0 -18
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_0.rb.tt +0 -135
- data/lib/rails/generators/rails/model/USAGE +0 -113
- data/lib/rails/tasks/middleware.rake +0 -9
- data/lib/rails/tasks/restart.rake +0 -9
data/lib/rails/engine.rb
CHANGED
@@ -9,13 +9,14 @@ require "pathname"
|
|
9
9
|
require "thread"
|
10
10
|
|
11
11
|
module Rails
|
12
|
-
#
|
12
|
+
# +Rails::Engine+ allows you to wrap a specific \Rails application or subset of
|
13
13
|
# functionality and share it with other applications or within a larger packaged application.
|
14
14
|
# Every Rails::Application is just an engine, which allows for simple
|
15
15
|
# feature and application sharing.
|
16
16
|
#
|
17
|
-
# Any
|
18
|
-
# methods (like
|
17
|
+
# Any +Rails::Engine+ is also a Rails::Railtie, so the same
|
18
|
+
# methods (like {rake_tasks}[rdoc-ref:Rails::Railtie::rake_tasks] and
|
19
|
+
# {generators}[rdoc-ref:Rails::Railtie::generators]) and configuration
|
19
20
|
# options that are available in railties can also be used in engines.
|
20
21
|
#
|
21
22
|
# == Creating an Engine
|
@@ -116,7 +117,7 @@ module Rails
|
|
116
117
|
# An engine can also be a Rack application. It can be useful if you have a Rack application that
|
117
118
|
# you would like to provide with some of the +Engine+'s features.
|
118
119
|
#
|
119
|
-
# To do that, use the
|
120
|
+
# To do that, use the ::endpoint method:
|
120
121
|
#
|
121
122
|
# module MyEngine
|
122
123
|
# class Engine < Rails::Engine
|
@@ -181,7 +182,7 @@ module Rails
|
|
181
182
|
# it's used as default <tt>:as</tt> option
|
182
183
|
# * rake task for installing migrations <tt>my_engine:install:migrations</tt>
|
183
184
|
#
|
184
|
-
# Engine name is set by default based on class name. For
|
185
|
+
# Engine name is set by default based on class name. For +MyEngine::Engine+ it will be
|
185
186
|
# <tt>my_engine_engine</tt>. You can change it manually using the <tt>engine_name</tt> method:
|
186
187
|
#
|
187
188
|
# module MyEngine
|
@@ -197,7 +198,7 @@ module Rails
|
|
197
198
|
# named routes from the application will be available to your engine's controllers as well.
|
198
199
|
#
|
199
200
|
# However, sometimes you want to isolate your engine from the application, especially if your engine
|
200
|
-
# has its own router. To do that, you simply need to call
|
201
|
+
# has its own router. To do that, you simply need to call ::isolate_namespace. This method requires
|
201
202
|
# you to pass a module where all your controllers, helpers, and models should be nested to:
|
202
203
|
#
|
203
204
|
# module MyEngine
|
@@ -231,14 +232,14 @@ module Rails
|
|
231
232
|
# end
|
232
233
|
#
|
233
234
|
# If +MyEngine+ is isolated, the routes above will point to
|
234
|
-
#
|
235
|
+
# +MyEngine::ArticlesController+. You also don't need to use longer
|
235
236
|
# URL helpers like +my_engine_articles_path+. Instead, you should simply use
|
236
237
|
# +articles_path+, like you would do with your main application.
|
237
238
|
#
|
238
239
|
# To make this behavior consistent with other parts of the framework,
|
239
240
|
# isolated engines also have an effect on ActiveModel::Naming. In a
|
240
|
-
# normal Rails app, when you use a namespaced model such as
|
241
|
-
#
|
241
|
+
# normal \Rails app, when you use a namespaced model such as
|
242
|
+
# +Namespace::Article+, ActiveModel::Naming will generate
|
242
243
|
# names with the prefix "namespace". In an isolated engine, the prefix will
|
243
244
|
# be omitted in URL helpers and form fields, for convenience.
|
244
245
|
#
|
@@ -252,7 +253,7 @@ module Rails
|
|
252
253
|
# Additionally, an isolated engine will set its own name according to its
|
253
254
|
# namespace, so <tt>MyEngine::Engine.engine_name</tt> will return
|
254
255
|
# "my_engine". It will also set +MyEngine.table_name_prefix+ to "my_engine_",
|
255
|
-
# meaning for example that
|
256
|
+
# meaning for example that +MyEngine::Article+ will use the
|
256
257
|
# +my_engine_articles+ database table by default.
|
257
258
|
#
|
258
259
|
# == Using Engine's routes outside Engine
|
@@ -300,7 +301,7 @@ module Rails
|
|
300
301
|
#
|
301
302
|
# == Isolated engine's helpers
|
302
303
|
#
|
303
|
-
# Sometimes you may want to isolate engine, but use helpers that are defined for it.
|
304
|
+
# Sometimes you may want to isolate an engine, but use helpers that are defined for it.
|
304
305
|
# If you want to share just a few specific helpers you can add them to application's
|
305
306
|
# helpers in ApplicationController:
|
306
307
|
#
|
@@ -327,7 +328,7 @@ module Rails
|
|
327
328
|
# To use engine's migrations in application you can use the rake task below, which copies them to
|
328
329
|
# application's dir:
|
329
330
|
#
|
330
|
-
# rake ENGINE_NAME:install:migrations
|
331
|
+
# $ rake ENGINE_NAME:install:migrations
|
331
332
|
#
|
332
333
|
# Note that some of the migrations may be skipped if a migration with the same name already exists
|
333
334
|
# in application. In such a situation you must decide whether to leave that migration or rename the
|
@@ -395,6 +396,12 @@ module Rails
|
|
395
396
|
|
396
397
|
unless mod.respond_to?(:table_name_prefix)
|
397
398
|
define_method(:table_name_prefix) { "#{name}_" }
|
399
|
+
|
400
|
+
ActiveSupport.on_load(:active_record) do
|
401
|
+
mod.singleton_class.redefine_method(:table_name_prefix) do
|
402
|
+
"#{ActiveRecord::Base.table_name_prefix}#{name}_"
|
403
|
+
end
|
404
|
+
end
|
398
405
|
end
|
399
406
|
|
400
407
|
unless mod.respond_to?(:use_relative_model_naming?)
|
@@ -450,7 +457,7 @@ module Rails
|
|
450
457
|
self
|
451
458
|
end
|
452
459
|
|
453
|
-
# Load Rails runner and invoke the registered hooks.
|
460
|
+
# Load \Rails runner and invoke the registered hooks.
|
454
461
|
# Check Rails::Railtie.runner for more info.
|
455
462
|
def load_runner(app = self)
|
456
463
|
run_runner_blocks(app)
|
@@ -465,7 +472,7 @@ module Rails
|
|
465
472
|
self
|
466
473
|
end
|
467
474
|
|
468
|
-
# Load Rails generators and invoke the registered hooks.
|
475
|
+
# Load \Rails generators and invoke the registered hooks.
|
469
476
|
# Check Rails::Railtie.generators for more info.
|
470
477
|
def load_generators(app = self)
|
471
478
|
require "rails/generators"
|
@@ -494,8 +501,7 @@ module Rails
|
|
494
501
|
def helpers
|
495
502
|
@helpers ||= begin
|
496
503
|
helpers = Module.new
|
497
|
-
|
498
|
-
ActionController::Base.modules_for_helpers(all).each do |mod|
|
504
|
+
AbstractController::Helpers.helper_modules_from_paths(helpers_paths).each do |mod|
|
499
505
|
helpers.include(mod)
|
500
506
|
end
|
501
507
|
helpers
|
@@ -579,7 +585,7 @@ module Rails
|
|
579
585
|
end
|
580
586
|
|
581
587
|
initializer :set_eager_load_paths, before: :bootstrap_hook do
|
582
|
-
ActiveSupport::Dependencies._eager_load_paths.merge(config.
|
588
|
+
ActiveSupport::Dependencies._eager_load_paths.merge(config.all_eager_load_paths)
|
583
589
|
config.eager_load_paths.freeze
|
584
590
|
end
|
585
591
|
|
@@ -587,6 +593,7 @@ module Rails
|
|
587
593
|
routing_paths = paths["config/routes.rb"].existent
|
588
594
|
external_paths = self.paths["config/routes"].paths
|
589
595
|
routes.draw_paths.concat(external_paths)
|
596
|
+
app.routes.draw_paths.concat(external_paths)
|
590
597
|
|
591
598
|
if routes? || routing_paths.any?
|
592
599
|
app.routes_reloader.paths.unshift(*routing_paths)
|
@@ -609,6 +616,22 @@ module Rails
|
|
609
616
|
end
|
610
617
|
end
|
611
618
|
|
619
|
+
initializer :add_mailer_preview_paths do
|
620
|
+
previews = paths["test/mailers/previews"].existent
|
621
|
+
unless previews.empty?
|
622
|
+
ActiveSupport.on_load(:action_mailer) { self.preview_paths |= previews }
|
623
|
+
end
|
624
|
+
end
|
625
|
+
|
626
|
+
initializer :add_fixture_paths do
|
627
|
+
next if is_a?(Rails::Application)
|
628
|
+
|
629
|
+
fixtures = config.root.join("test", "fixtures")
|
630
|
+
if fixtures_in_root_and_not_in_vendor?(fixtures)
|
631
|
+
ActiveSupport.on_load(:active_record_fixtures) { self.fixture_paths |= ["#{fixtures}/"] }
|
632
|
+
end
|
633
|
+
end
|
634
|
+
|
612
635
|
initializer :prepend_helpers_path do |app|
|
613
636
|
if !isolated? || (app == self)
|
614
637
|
app.config.helpers_paths.unshift(*paths["app/helpers"].existent)
|
@@ -689,14 +712,14 @@ module Rails
|
|
689
712
|
end
|
690
713
|
|
691
714
|
def _all_autoload_once_paths
|
692
|
-
config.
|
715
|
+
config.all_autoload_once_paths.uniq
|
693
716
|
end
|
694
717
|
|
695
718
|
def _all_autoload_paths
|
696
719
|
@_all_autoload_paths ||= begin
|
697
|
-
autoload_paths = config.
|
698
|
-
autoload_paths += config.
|
699
|
-
autoload_paths -= config.
|
720
|
+
autoload_paths = config.all_autoload_paths
|
721
|
+
autoload_paths += config.all_eager_load_paths
|
722
|
+
autoload_paths -= config.all_autoload_once_paths
|
700
723
|
autoload_paths.uniq
|
701
724
|
end
|
702
725
|
end
|
@@ -712,6 +735,11 @@ module Rails
|
|
712
735
|
end
|
713
736
|
end
|
714
737
|
|
738
|
+
def fixtures_in_root_and_not_in_vendor?(fixtures)
|
739
|
+
fixtures.exist? && fixtures.to_s.start_with?(Rails.root.to_s) &&
|
740
|
+
!fixtures.to_s.start_with?(Rails.root.join("vendor").to_s)
|
741
|
+
end
|
742
|
+
|
715
743
|
def build_request(env)
|
716
744
|
env.merge!(env_config)
|
717
745
|
req = ActionDispatch::Request.new env
|
data/lib/rails/gem_version.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Rails
|
4
|
-
# Returns the currently loaded version of Rails as a
|
4
|
+
# Returns the currently loaded version of \Rails as a +Gem::Version+.
|
5
5
|
def self.gem_version
|
6
6
|
Gem::Version.new VERSION::STRING
|
7
7
|
end
|
8
8
|
|
9
9
|
module VERSION
|
10
10
|
MAJOR = 7
|
11
|
-
MINOR =
|
12
|
-
TINY =
|
13
|
-
PRE =
|
11
|
+
MINOR = 1
|
12
|
+
TINY = 3
|
13
|
+
PRE = "4"
|
14
14
|
|
15
15
|
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
|
16
16
|
end
|
@@ -12,13 +12,58 @@ module Rails
|
|
12
12
|
@indentation = 0
|
13
13
|
end
|
14
14
|
|
15
|
-
# Adds
|
15
|
+
# Adds a +gem+ declaration to the +Gemfile+ for the specified gem.
|
16
16
|
#
|
17
17
|
# gem "rspec", group: :test
|
18
18
|
# gem "technoweenie-restful-authentication", lib: "restful-authentication", source: "http://gems.github.com/"
|
19
19
|
# gem "rails", "3.0", git: "https://github.com/rails/rails"
|
20
20
|
# gem "RedCloth", ">= 4.1.0", "< 4.2.0"
|
21
21
|
# gem "rspec", comment: "Put this comment above the gem declaration"
|
22
|
+
#
|
23
|
+
# Note that this method only adds the gem to the +Gemfile+; it does not
|
24
|
+
# install the gem.
|
25
|
+
#
|
26
|
+
# ==== Options
|
27
|
+
#
|
28
|
+
# [+:version+]
|
29
|
+
# The version constraints for the gem, specified as a string or an
|
30
|
+
# array of strings:
|
31
|
+
#
|
32
|
+
# gem "my_gem", version: "~> 1.1"
|
33
|
+
# gem "my_gem", version: [">= 1.1", "< 2.0"]
|
34
|
+
#
|
35
|
+
# Alternatively, can be specified as one or more arguments following the
|
36
|
+
# gem name:
|
37
|
+
#
|
38
|
+
# gem "my_gem", ">= 1.1", "< 2.0"
|
39
|
+
#
|
40
|
+
# [+:comment+]
|
41
|
+
# Outputs a comment above the +gem+ declaration in the +Gemfile+.
|
42
|
+
#
|
43
|
+
# gem "my_gem", comment: "First line.\nSecond line."
|
44
|
+
#
|
45
|
+
# Outputs:
|
46
|
+
#
|
47
|
+
# # First line.
|
48
|
+
# # Second line.
|
49
|
+
# gem "my_gem"
|
50
|
+
#
|
51
|
+
# [+:group+]
|
52
|
+
# The gem group in the +Gemfile+ that the gem belongs to.
|
53
|
+
#
|
54
|
+
# [+:git+]
|
55
|
+
# The URL of the git repository for the gem.
|
56
|
+
#
|
57
|
+
# Any additional options passed to this method will be appended to the
|
58
|
+
# +gem+ declaration in the +Gemfile+. For example:
|
59
|
+
#
|
60
|
+
# gem "my_gem", comment: "Edge my_gem", git: "https://example.com/my_gem.git", branch: "master"
|
61
|
+
#
|
62
|
+
# Outputs:
|
63
|
+
#
|
64
|
+
# # Edge my_gem
|
65
|
+
# gem "my_gem", git: "https://example.com/my_gem.git", branch: "master"
|
66
|
+
#
|
22
67
|
def gem(*args)
|
23
68
|
options = args.extract_options!
|
24
69
|
name, *versions = args
|
@@ -117,18 +162,47 @@ module Rails
|
|
117
162
|
end
|
118
163
|
end
|
119
164
|
|
120
|
-
# Adds
|
165
|
+
# Adds configuration code to a \Rails runtime environment.
|
166
|
+
#
|
167
|
+
# By default, adds code inside the +Application+ class in
|
168
|
+
# +config/application.rb+ so that it applies to all environments.
|
169
|
+
#
|
170
|
+
# environment %(config.asset_host = "cdn.provider.com")
|
171
|
+
#
|
172
|
+
# Results in:
|
173
|
+
#
|
174
|
+
# # config/application.rb
|
175
|
+
# class Application < Rails::Application
|
176
|
+
# config.asset_host = "cdn.provider.com"
|
177
|
+
# # ...
|
178
|
+
# end
|
179
|
+
#
|
180
|
+
# If the +:env+ option is specified, the code will be added to the
|
181
|
+
# corresponding file in +config/environments+ instead.
|
182
|
+
#
|
183
|
+
# environment %(config.asset_host = "localhost:3000"), env: "development"
|
184
|
+
#
|
185
|
+
# Results in:
|
186
|
+
#
|
187
|
+
# # config/environments/development.rb
|
188
|
+
# Rails.application.configure do
|
189
|
+
# config.asset_host = "localhost:3000"
|
190
|
+
# # ...
|
191
|
+
# end
|
121
192
|
#
|
122
|
-
#
|
123
|
-
# file in
|
193
|
+
# +:env+ can also be an array. In which case, the code is added to each
|
194
|
+
# corresponding file in +config/environments+.
|
195
|
+
#
|
196
|
+
# The code can also be specified as the return value of the block:
|
124
197
|
#
|
125
198
|
# environment do
|
126
|
-
#
|
199
|
+
# %(config.asset_host = "cdn.provider.com")
|
127
200
|
# end
|
128
201
|
#
|
129
202
|
# environment(nil, env: "development") do
|
130
|
-
#
|
203
|
+
# %(config.asset_host = "localhost:3000")
|
131
204
|
# end
|
205
|
+
#
|
132
206
|
def environment(data = nil, options = {})
|
133
207
|
sentinel = "class Application < Rails::Application\n"
|
134
208
|
env_file_sentinel = "Rails.application.configure do\n"
|
@@ -146,11 +220,20 @@ module Rails
|
|
146
220
|
end
|
147
221
|
alias :application :environment
|
148
222
|
|
149
|
-
#
|
223
|
+
# Runs one or more git commands.
|
150
224
|
#
|
151
225
|
# git :init
|
226
|
+
# # => runs `git init`
|
227
|
+
#
|
152
228
|
# git add: "this.file that.rb"
|
153
|
-
# git add
|
229
|
+
# # => runs `git add this.file that.rb`
|
230
|
+
#
|
231
|
+
# git commit: "-m 'First commit'"
|
232
|
+
# # => runs `git commit -m 'First commit'`
|
233
|
+
#
|
234
|
+
# git add: "good.rb", rm: "bad.cxx"
|
235
|
+
# # => runs `git add good.rb; git rm bad.cxx`
|
236
|
+
#
|
154
237
|
def git(commands = {})
|
155
238
|
if commands.is_a?(Symbol)
|
156
239
|
run "git #{commands}"
|
@@ -161,80 +244,91 @@ module Rails
|
|
161
244
|
end
|
162
245
|
end
|
163
246
|
|
164
|
-
#
|
165
|
-
#
|
247
|
+
# Creates a file in +vendor/+. The contents can be specified as an
|
248
|
+
# argument or as the return value of the block.
|
249
|
+
#
|
250
|
+
# vendor "foreign.rb", <<~RUBY
|
251
|
+
# # Foreign code is fun
|
252
|
+
# RUBY
|
166
253
|
#
|
167
|
-
# vendor
|
168
|
-
#
|
169
|
-
# "salt = '#{sekrit_salt}'"
|
254
|
+
# vendor "foreign.rb" do
|
255
|
+
# "# Foreign code is fun"
|
170
256
|
# end
|
171
257
|
#
|
172
|
-
# vendor("foreign.rb", "# Foreign code is fun")
|
173
258
|
def vendor(filename, data = nil)
|
174
259
|
log :vendor, filename
|
175
260
|
data ||= yield if block_given?
|
176
261
|
create_file("vendor/#{filename}", optimize_indentation(data), verbose: false)
|
177
262
|
end
|
178
263
|
|
179
|
-
#
|
180
|
-
#
|
264
|
+
# Creates a file in +lib/+. The contents can be specified as an argument
|
265
|
+
# or as the return value of the block.
|
181
266
|
#
|
182
|
-
# lib
|
183
|
-
#
|
267
|
+
# lib "foreign.rb", <<~RUBY
|
268
|
+
# # Foreign code is fun
|
269
|
+
# RUBY
|
270
|
+
#
|
271
|
+
# lib "foreign.rb" do
|
272
|
+
# "# Foreign code is fun"
|
184
273
|
# end
|
185
274
|
#
|
186
|
-
# lib("foreign.rb", "# Foreign code is fun")
|
187
275
|
def lib(filename, data = nil)
|
188
276
|
log :lib, filename
|
189
277
|
data ||= yield if block_given?
|
190
278
|
create_file("lib/#{filename}", optimize_indentation(data), verbose: false)
|
191
279
|
end
|
192
280
|
|
193
|
-
#
|
281
|
+
# Creates a Rake tasks file in +lib/tasks/+. The code can be specified as
|
282
|
+
# an argument or as the return value of the block.
|
283
|
+
#
|
284
|
+
# rakefile "bootstrap.rake", <<~RUBY
|
285
|
+
# task :bootstrap do
|
286
|
+
# puts "Boots! Boots! Boots!"
|
287
|
+
# end
|
288
|
+
# RUBY
|
194
289
|
#
|
195
|
-
# rakefile
|
290
|
+
# rakefile "bootstrap.rake" do
|
196
291
|
# project = ask("What is the UNIX name of your project?")
|
197
292
|
#
|
198
|
-
#
|
293
|
+
# <<~RUBY
|
199
294
|
# namespace :#{project} do
|
200
295
|
# task :bootstrap do
|
201
|
-
# puts "
|
296
|
+
# puts "Boots! Boots! Boots!"
|
202
297
|
# end
|
203
298
|
# end
|
204
|
-
#
|
299
|
+
# RUBY
|
205
300
|
# end
|
206
301
|
#
|
207
|
-
# rakefile('seed.rake', 'puts "Planting seeds"')
|
208
302
|
def rakefile(filename, data = nil)
|
209
303
|
log :rakefile, filename
|
210
304
|
data ||= yield if block_given?
|
211
305
|
create_file("lib/tasks/#{filename}", optimize_indentation(data), verbose: false)
|
212
306
|
end
|
213
307
|
|
214
|
-
#
|
308
|
+
# Creates an initializer file in +config/initializers/+. The code can be
|
309
|
+
# specified as an argument or as the return value of the block.
|
215
310
|
#
|
216
|
-
# initializer
|
217
|
-
#
|
311
|
+
# initializer "api.rb", <<~RUBY
|
312
|
+
# API_KEY = "123456"
|
313
|
+
# RUBY
|
218
314
|
#
|
219
|
-
#
|
220
|
-
#
|
221
|
-
# end
|
222
|
-
#
|
223
|
-
# data
|
315
|
+
# initializer "api.rb" do
|
316
|
+
# %(API_KEY = "123456")
|
224
317
|
# end
|
225
318
|
#
|
226
|
-
# initializer("api.rb", "API_KEY = '123456'")
|
227
319
|
def initializer(filename, data = nil)
|
228
320
|
log :initializer, filename
|
229
321
|
data ||= yield if block_given?
|
230
322
|
create_file("config/initializers/#{filename}", optimize_indentation(data), verbose: false)
|
231
323
|
end
|
232
324
|
|
233
|
-
#
|
234
|
-
#
|
235
|
-
#
|
325
|
+
# Runs another generator.
|
326
|
+
#
|
327
|
+
# generate "scaffold", "Post title:string body:text"
|
328
|
+
# generate "scaffold", "Post", "title:string", "body:text"
|
236
329
|
#
|
237
|
-
#
|
330
|
+
# The first argument is the generator name, and the remaining arguments
|
331
|
+
# are joined together and passed to the generator.
|
238
332
|
def generate(what, *args)
|
239
333
|
log :generate, what
|
240
334
|
|
@@ -244,22 +338,56 @@ module Rails
|
|
244
338
|
rails_command "generate #{what} #{args.join(" ")}", options
|
245
339
|
end
|
246
340
|
|
247
|
-
# Runs the
|
341
|
+
# Runs the specified Rake task.
|
342
|
+
#
|
343
|
+
# rake "db:migrate"
|
344
|
+
# rake "db:migrate", env: "production"
|
345
|
+
# rake "db:migrate", abort_on_failure: true
|
346
|
+
# rake "stats", capture: true
|
347
|
+
# rake "gems:install", sudo: true
|
248
348
|
#
|
249
|
-
#
|
250
|
-
#
|
251
|
-
#
|
252
|
-
#
|
349
|
+
# ==== Options
|
350
|
+
#
|
351
|
+
# [+:env+]
|
352
|
+
# The \Rails environment in which to run the task. Defaults to
|
353
|
+
# <tt>ENV["RAILS_ENV"] || "development"</tt>.
|
354
|
+
#
|
355
|
+
# [+:abort_on_failure+]
|
356
|
+
# Whether to halt the generator if the task exits with a non-success
|
357
|
+
# exit status.
|
358
|
+
#
|
359
|
+
# [+:capture+]
|
360
|
+
# Whether to capture and return the output of the task.
|
361
|
+
#
|
362
|
+
# [+:sudo+]
|
363
|
+
# Whether to run the task using +sudo+.
|
253
364
|
def rake(command, options = {})
|
254
365
|
execute_command :rake, command, options
|
255
366
|
end
|
256
367
|
|
257
|
-
# Runs the
|
368
|
+
# Runs the specified \Rails command.
|
369
|
+
#
|
370
|
+
# rails_command "db:migrate"
|
371
|
+
# rails_command "db:migrate", env: "production"
|
372
|
+
# rails_command "db:migrate", abort_on_failure: true
|
373
|
+
# rails_command "stats", capture: true
|
374
|
+
# rails_command "gems:install", sudo: true
|
375
|
+
#
|
376
|
+
# ==== Options
|
377
|
+
#
|
378
|
+
# [+:env+]
|
379
|
+
# The \Rails environment in which to run the command. Defaults to
|
380
|
+
# <tt>ENV["RAILS_ENV"] || "development"</tt>.
|
258
381
|
#
|
259
|
-
#
|
260
|
-
#
|
261
|
-
#
|
262
|
-
#
|
382
|
+
# [+:abort_on_failure+]
|
383
|
+
# Whether to halt the generator if the command exits with a non-success
|
384
|
+
# exit status.
|
385
|
+
#
|
386
|
+
# [+:capture+]
|
387
|
+
# Whether to capture and return the output of the command.
|
388
|
+
#
|
389
|
+
# [+:sudo+]
|
390
|
+
# Whether to run the command using +sudo+.
|
263
391
|
def rails_command(command, options = {})
|
264
392
|
if options[:inline]
|
265
393
|
log :rails, command
|
@@ -274,7 +402,7 @@ module Rails
|
|
274
402
|
end
|
275
403
|
end
|
276
404
|
|
277
|
-
# Make an entry in Rails routing file <tt>config/routes.rb</tt>
|
405
|
+
# Make an entry in \Rails routing file <tt>config/routes.rb</tt>
|
278
406
|
#
|
279
407
|
# route "root 'welcome#index'"
|
280
408
|
# route "root 'admin#index'", namespace: :admin
|
@@ -340,16 +468,7 @@ module Rails
|
|
340
468
|
abort_on_failure: options[:abort_on_failure],
|
341
469
|
}
|
342
470
|
|
343
|
-
in_root { run("#{sudo}#{
|
344
|
-
end
|
345
|
-
|
346
|
-
# Add an extension to the given name based on the platform.
|
347
|
-
def extify(name) # :doc:
|
348
|
-
if Gem.win_platform?
|
349
|
-
"#{name}.bat"
|
350
|
-
else
|
351
|
-
name
|
352
|
-
end
|
471
|
+
in_root { run("#{sudo}#{Shellwords.escape Gem.ruby} bin/#{executor} #{command}", config) }
|
353
472
|
end
|
354
473
|
|
355
474
|
# Always returns value in double quotes.
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Rails
|
4
4
|
module Generators
|
5
|
-
# ActiveModel is a class to be implemented by each ORM to allow Rails to
|
5
|
+
# ActiveModel is a class to be implemented by each ORM to allow \Rails to
|
6
6
|
# generate customized controller code.
|
7
7
|
#
|
8
8
|
# The API has the same methods as ActiveRecord, but each method returns a
|
@@ -32,21 +32,27 @@ module Rails
|
|
32
32
|
@name = name
|
33
33
|
end
|
34
34
|
|
35
|
-
#
|
35
|
+
# Used for:
|
36
|
+
#
|
37
|
+
# * GET +index+
|
36
38
|
def self.all(klass)
|
37
39
|
"#{klass}.all"
|
38
40
|
end
|
39
41
|
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
42
|
+
# Used for:
|
43
|
+
#
|
44
|
+
# * GET +show+
|
45
|
+
# * GET +edit+
|
46
|
+
# * PATCH / PUT +update+
|
47
|
+
# * DELETE +destroy+
|
44
48
|
def self.find(klass, params = nil)
|
45
49
|
"#{klass}.find(#{params})"
|
46
50
|
end
|
47
51
|
|
48
|
-
#
|
49
|
-
#
|
52
|
+
# Used for:
|
53
|
+
#
|
54
|
+
# * GET +new+
|
55
|
+
# * POST +create+
|
50
56
|
def self.build(klass, params = nil)
|
51
57
|
if params
|
52
58
|
"#{klass}.new(#{params})"
|
@@ -55,25 +61,33 @@ module Rails
|
|
55
61
|
end
|
56
62
|
end
|
57
63
|
|
58
|
-
#
|
64
|
+
# Used for:
|
65
|
+
#
|
66
|
+
# * POST +create+
|
59
67
|
def save
|
60
68
|
"#{name}.save"
|
61
69
|
end
|
62
70
|
|
63
|
-
#
|
71
|
+
# Used for:
|
72
|
+
#
|
73
|
+
# * PATCH / PUT +update+
|
64
74
|
def update(params = nil)
|
65
75
|
"#{name}.update(#{params})"
|
66
76
|
end
|
67
77
|
|
68
|
-
#
|
69
|
-
#
|
78
|
+
# Used for:
|
79
|
+
#
|
80
|
+
# * POST +create+
|
81
|
+
# * PATCH / PUT +update+
|
70
82
|
def errors
|
71
83
|
"#{name}.errors"
|
72
84
|
end
|
73
85
|
|
74
|
-
#
|
86
|
+
# Used for:
|
87
|
+
#
|
88
|
+
# * DELETE +destroy+
|
75
89
|
def destroy
|
76
|
-
"#{name}.destroy"
|
90
|
+
"#{name}.destroy!"
|
77
91
|
end
|
78
92
|
end
|
79
93
|
end
|