railties 5.2.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +293 -89
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +39 -33
- data/README.rdoc +3 -3
- data/lib/minitest/rails_plugin.rb +24 -13
- data/lib/rails/all.rb +4 -0
- data/lib/rails/api/generator.rb +2 -1
- data/lib/rails/api/task.rb +17 -0
- data/lib/rails/app_loader.rb +2 -2
- data/lib/rails/app_updater.rb +4 -1
- data/lib/rails/application/bootstrap.rb +9 -17
- data/lib/rails/application/configuration.rb +177 -27
- data/lib/rails/application/default_middleware_stack.rb +7 -3
- data/lib/rails/application/dummy_erb_compiler.rb +18 -0
- data/lib/rails/application/finisher.rb +69 -2
- data/lib/rails/application/routes_reloader.rb +9 -19
- data/lib/rails/application.rb +96 -66
- data/lib/rails/application_controller.rb +0 -1
- data/lib/rails/autoloaders.rb +48 -0
- data/lib/rails/backtrace_cleaner.rb +14 -21
- data/lib/rails/code_statistics.rb +8 -6
- data/lib/rails/code_statistics_calculator.rb +6 -6
- data/lib/rails/command/actions.rb +10 -0
- data/lib/rails/command/base.rb +17 -5
- data/lib/rails/command/behavior.rb +8 -49
- data/lib/rails/command/environment_argument.rb +9 -16
- data/lib/rails/command/spellchecker.rb +57 -0
- data/lib/rails/command.rb +18 -11
- data/lib/rails/commands/console/console_command.rb +6 -0
- data/lib/rails/commands/credentials/USAGE +33 -0
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
- data/lib/rails/commands/credentials/credentials_command.rb +78 -21
- data/lib/rails/commands/db/system/change/change_command.rb +25 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +66 -51
- data/lib/rails/commands/dev/dev_command.rb +19 -0
- data/lib/rails/commands/encrypted/USAGE +28 -0
- data/lib/rails/commands/encrypted/encrypted_command.rb +5 -4
- data/lib/rails/commands/generate/generate_command.rb +1 -1
- data/lib/rails/commands/help/help_command.rb +1 -1
- data/lib/rails/commands/initializers/initializers_command.rb +23 -0
- data/lib/rails/commands/new/new_command.rb +2 -2
- data/lib/rails/commands/notes/notes_command.rb +29 -0
- data/lib/rails/commands/plugin/plugin_command.rb +1 -1
- data/lib/rails/commands/rake/rake_command.rb +9 -8
- data/lib/rails/commands/routes/routes_command.rb +37 -0
- data/lib/rails/commands/runner/runner_command.rb +13 -9
- data/lib/rails/commands/secrets/USAGE +6 -0
- data/lib/rails/commands/secrets/secrets_command.rb +3 -3
- data/lib/rails/commands/server/server_command.rb +92 -56
- data/lib/rails/commands/test/test_command.rb +2 -2
- data/lib/rails/configuration.rb +48 -19
- data/lib/rails/engine/configuration.rb +6 -2
- data/lib/rails/engine/updater.rb +1 -1
- data/lib/rails/engine.rb +63 -35
- data/lib/rails/gem_version.rb +2 -2
- data/lib/rails/generators/actions/create_migration.rb +5 -1
- data/lib/rails/generators/actions.rb +89 -56
- data/lib/rails/generators/app_base.rb +80 -108
- data/lib/rails/generators/app_name.rb +50 -0
- data/lib/rails/generators/base.rb +19 -12
- data/lib/rails/generators/database.rb +57 -0
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -2
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +0 -1
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +7 -4
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +1 -1
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +9 -1
- data/lib/rails/generators/erb.rb +0 -1
- data/lib/rails/generators/generated_attribute.rb +50 -31
- data/lib/rails/generators/migration.rb +3 -3
- data/lib/rails/generators/model_helpers.rb +33 -2
- data/lib/rails/generators/named_base.rb +3 -7
- data/lib/rails/generators/rails/app/USAGE +2 -1
- data/lib/rails/generators/rails/app/app_generator.rb +127 -84
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +18 -21
- data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -3
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +6 -0
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +5 -0
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +23 -0
- data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb.tt +5 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +6 -5
- data/lib/rails/generators/rails/app/templates/bin/rails.tt +5 -2
- data/lib/rails/generators/rails/app/templates/bin/rake.tt +5 -2
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +9 -9
- data/lib/rails/generators/rails/app/templates/bin/spring.tt +9 -0
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +11 -3
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +16 -7
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +4 -5
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +12 -11
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +13 -12
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +13 -12
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +12 -11
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +16 -15
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +11 -10
- data/lib/rails/generators/rails/app/templates/config/environment.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +22 -5
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +43 -17
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +26 -7
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +4 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +7 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +63 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +13 -4
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +6 -6
- data/lib/rails/generators/rails/app/templates/config.ru.tt +2 -1
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/gitattributes.tt +14 -0
- data/lib/rails/generators/rails/app/templates/gitignore.tt +10 -7
- data/lib/rails/generators/rails/app/templates/package.json.tt +8 -2
- data/lib/rails/generators/rails/app/templates/public/robots.txt +1 -1
- data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -1
- data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +9 -2
- data/lib/rails/generators/rails/assets/USAGE +3 -7
- data/lib/rails/generators/rails/assets/assets_generator.rb +0 -1
- data/lib/rails/generators/rails/benchmark/USAGE +19 -0
- data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +29 -0
- data/lib/rails/generators/rails/benchmark/templates/benchmark.rb.tt +15 -0
- data/lib/rails/generators/rails/controller/USAGE +2 -2
- data/lib/rails/generators/rails/controller/controller_generator.rb +10 -39
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +6 -7
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +65 -0
- data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +10 -7
- data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +1 -0
- data/lib/rails/generators/rails/generator/USAGE +2 -2
- data/lib/rails/generators/rails/generator/generator_generator.rb +0 -1
- data/lib/rails/generators/rails/generator/templates/USAGE.tt +1 -1
- data/lib/rails/generators/rails/helper/USAGE +2 -3
- data/lib/rails/generators/rails/helper/helper_generator.rb +5 -0
- data/lib/rails/generators/rails/integration_test/USAGE +2 -2
- data/lib/rails/generators/rails/migration/USAGE +4 -4
- data/lib/rails/generators/rails/model/USAGE +15 -16
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +32 -56
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +18 -18
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +3 -10
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -18
- data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +1 -2
- data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +3 -3
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +14 -11
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb.tt +1 -0
- data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb.tt +4 -4
- data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +0 -4
- data/lib/rails/generators/rails/resource/USAGE +4 -4
- data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +2 -27
- data/lib/rails/generators/rails/scaffold/USAGE +5 -5
- data/lib/rails/generators/rails/scaffold_controller/USAGE +2 -2
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +19 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +2 -2
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +2 -2
- data/lib/rails/generators/rails/system_test/USAGE +2 -2
- data/lib/rails/generators/rails/task/USAGE +3 -3
- data/lib/rails/generators/resource_helpers.rb +1 -6
- data/lib/rails/generators/test_case.rb +1 -1
- data/lib/rails/generators/test_unit/controller/controller_generator.rb +2 -0
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt +3 -3
- data/lib/rails/generators/test_unit/generator/generator_generator.rb +0 -1
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +2 -2
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +5 -0
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/job/job_generator.rb +5 -0
- data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +1 -1
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +3 -3
- data/lib/rails/generators/test_unit/model/templates/unit_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +12 -3
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +10 -2
- data/lib/rails/generators/test_unit/system/system_generator.rb +5 -0
- data/lib/rails/generators/testing/assertions.rb +2 -2
- data/lib/rails/generators/testing/behaviour.rb +4 -2
- data/lib/rails/generators.rb +38 -24
- data/lib/rails/info.rb +4 -4
- data/lib/rails/info_controller.rb +2 -3
- data/lib/rails/mailers_controller.rb +10 -4
- data/lib/rails/paths.rb +26 -10
- data/lib/rails/rack/logger.rb +5 -6
- data/lib/rails/railtie/configurable.rb +0 -1
- data/lib/rails/railtie/configuration.rb +3 -3
- data/lib/rails/railtie.rb +33 -13
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/secrets.rb +0 -1
- data/lib/rails/source_annotation_extractor.rb +124 -117
- data/lib/rails/tasks/engine.rake +1 -4
- data/lib/rails/tasks/framework.rake +13 -3
- data/lib/rails/tasks/log.rake +0 -1
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/statistics.rake +5 -1
- data/lib/rails/tasks/yarn.rake +14 -1
- data/lib/rails/tasks/zeitwerk.rake +69 -0
- data/lib/rails/tasks.rb +1 -4
- data/lib/rails/templates/rails/mailers/email.html.erb +11 -7
- data/lib/rails/templates/rails/welcome/index.html.erb +3 -3
- data/lib/rails/test_help.rb +11 -9
- data/lib/rails/test_unit/reporter.rb +3 -2
- data/lib/rails/test_unit/runner.rb +25 -8
- data/lib/rails/test_unit/testing.rake +7 -1
- data/lib/rails.rb +10 -8
- metadata +45 -39
- data/lib/rails/generators/js/assets/assets_generator.rb +0 -15
- data/lib/rails/generators/js/assets/templates/javascript.js +0 -2
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +0 -22
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js.tt +0 -13
- data/lib/rails/generators/rails/app/templates/bin/bundle.tt +0 -2
- data/lib/rails/generators/rails/app/templates/bin/update.tt +0 -34
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +0 -50
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +0 -86
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt +0 -35
- data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
- data/lib/rails/generators/rails/plugin/templates/rails/application.rb.tt +0 -23
- data/lib/rails/tasks/annotations.rake +0 -22
- data/lib/rails/tasks/dev.rake +0 -10
- data/lib/rails/tasks/initializers.rake +0 -8
- data/lib/rails/tasks/routes.rake +0 -31
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_support/core_ext/hash/except"
|
3
4
|
require "rails/generators/rails/app/app_generator"
|
4
5
|
require "date"
|
5
6
|
|
@@ -24,10 +25,14 @@ module Rails
|
|
24
25
|
directory "app"
|
25
26
|
empty_directory_with_keep_file "app/assets/images/#{namespaced_name}"
|
26
27
|
end
|
28
|
+
|
29
|
+
remove_dir "app/mailers" if options[:skip_action_mailer]
|
30
|
+
remove_dir "app/jobs" if options[:skip_active_job]
|
27
31
|
elsif full?
|
28
32
|
empty_directory_with_keep_file "app/models"
|
29
33
|
empty_directory_with_keep_file "app/controllers"
|
30
|
-
empty_directory_with_keep_file "app/mailers"
|
34
|
+
empty_directory_with_keep_file "app/mailers" unless options[:skip_action_mailer]
|
35
|
+
empty_directory_with_keep_file "app/jobs" unless options[:skip_active_job]
|
31
36
|
|
32
37
|
unless api?
|
33
38
|
empty_directory_with_keep_file "app/assets/images/#{namespaced_name}"
|
@@ -57,6 +62,12 @@ module Rails
|
|
57
62
|
template "gitignore", ".gitignore"
|
58
63
|
end
|
59
64
|
|
65
|
+
def version_control
|
66
|
+
if !options[:skip_git] && !options[:pretend]
|
67
|
+
run "git init", capture: options[:quiet], abort_on_failure: false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
60
71
|
def lib
|
61
72
|
template "lib/%namespaced_name%.rb"
|
62
73
|
template "lib/tasks/%namespaced_name%_tasks.rake"
|
@@ -86,18 +97,16 @@ task default: :test
|
|
86
97
|
end
|
87
98
|
end
|
88
99
|
|
89
|
-
|
90
|
-
:skip_active_record, :skip_active_storage, :skip_action_mailer, :skip_javascript, :skip_action_cable, :skip_sprockets, :database,
|
91
|
-
:javascript, :skip_yarn, :api, :quiet, :pretend, :skip
|
92
|
-
]
|
100
|
+
DUMMY_IGNORE_OPTIONS = %i[dev edge master template]
|
93
101
|
|
94
102
|
def generate_test_dummy(force = false)
|
95
|
-
opts =
|
103
|
+
opts = options.transform_keys(&:to_sym).except(*DUMMY_IGNORE_OPTIONS)
|
96
104
|
opts[:force] = force
|
97
105
|
opts[:skip_bundle] = true
|
98
106
|
opts[:skip_listen] = true
|
99
107
|
opts[:skip_git] = true
|
100
108
|
opts[:skip_turbolinks] = true
|
109
|
+
opts[:skip_webpack_install] = true
|
101
110
|
opts[:dummy_app] = true
|
102
111
|
|
103
112
|
invoke Rails::Generators::AppGenerator,
|
@@ -106,20 +115,25 @@ task default: :test
|
|
106
115
|
|
107
116
|
def test_dummy_config
|
108
117
|
template "rails/boot.rb", "#{dummy_path}/config/boot.rb", force: true
|
109
|
-
|
118
|
+
|
119
|
+
insert_into_file "#{dummy_path}/config/application.rb", <<~RUBY, after: /^Bundler\.require.+\n/
|
120
|
+
require #{namespaced_name.inspect}
|
121
|
+
RUBY
|
122
|
+
|
110
123
|
if mountable?
|
111
124
|
template "rails/routes.rb", "#{dummy_path}/config/routes.rb", force: true
|
112
125
|
end
|
113
126
|
end
|
114
127
|
|
115
128
|
def test_dummy_assets
|
116
|
-
template "rails/javascripts.js", "#{dummy_path}/app/
|
129
|
+
template "rails/javascripts.js", "#{dummy_path}/app/javascript/packs/application.js", force: true
|
117
130
|
template "rails/stylesheets.css", "#{dummy_path}/app/assets/stylesheets/application.css", force: true
|
118
131
|
template "rails/dummy_manifest.js", "#{dummy_path}/app/assets/config/manifest.js", force: true
|
119
132
|
end
|
120
133
|
|
121
134
|
def test_dummy_clean
|
122
135
|
inside dummy_path do
|
136
|
+
remove_file ".ruby-version"
|
123
137
|
remove_file "db/seeds.rb"
|
124
138
|
remove_file "Gemfile"
|
125
139
|
remove_file "lib/tasks"
|
@@ -143,17 +157,6 @@ task default: :test
|
|
143
157
|
end
|
144
158
|
end
|
145
159
|
|
146
|
-
def javascripts
|
147
|
-
return if options.skip_javascript?
|
148
|
-
|
149
|
-
if mountable?
|
150
|
-
template "rails/javascripts.js",
|
151
|
-
"app/assets/javascripts/#{namespaced_name}/application.js"
|
152
|
-
elsif full?
|
153
|
-
empty_directory_with_keep_file "app/assets/javascripts/#{namespaced_name}"
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
160
|
def bin(force = false)
|
158
161
|
bin_file = engine? ? "bin/rails.tt" : "bin/test.tt"
|
159
162
|
template bin_file, force: force do |content|
|
@@ -186,7 +189,7 @@ task default: :test
|
|
186
189
|
desc: "Generate a rails engine with bundled Rails application for testing"
|
187
190
|
|
188
191
|
class_option :mountable, type: :boolean, default: false,
|
189
|
-
desc: "Generate mountable isolated
|
192
|
+
desc: "Generate mountable isolated engine"
|
190
193
|
|
191
194
|
class_option :skip_gemspec, type: :boolean, default: false,
|
192
195
|
desc: "Skip gemspec file"
|
@@ -213,6 +216,7 @@ task default: :test
|
|
213
216
|
build(:license)
|
214
217
|
build(:gitignore) unless options[:skip_git]
|
215
218
|
build(:gemfile) unless options[:skip_gemfile]
|
219
|
+
build(:version_control)
|
216
220
|
end
|
217
221
|
|
218
222
|
def create_app_files
|
@@ -235,10 +239,6 @@ task default: :test
|
|
235
239
|
build(:stylesheets) unless api?
|
236
240
|
end
|
237
241
|
|
238
|
-
def create_javascript_files
|
239
|
-
build(:javascripts) unless api?
|
240
|
-
end
|
241
|
-
|
242
242
|
def create_bin_files
|
243
243
|
build(:bin)
|
244
244
|
end
|
@@ -262,16 +262,6 @@ task default: :test
|
|
262
262
|
|
263
263
|
public_task :apply_rails_template
|
264
264
|
|
265
|
-
def run_after_bundle_callbacks
|
266
|
-
unless @after_bundle_callbacks.empty?
|
267
|
-
ActiveSupport::Deprecation.warn("`after_bundle` is deprecated and will be removed in the next version of Rails. ")
|
268
|
-
end
|
269
|
-
|
270
|
-
@after_bundle_callbacks.each do |callback|
|
271
|
-
callback.call
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
265
|
def name
|
276
266
|
@name ||= begin
|
277
267
|
# same as ActiveSupport::Inflector#underscore except not replacing '-'
|
@@ -293,14 +283,12 @@ task default: :test
|
|
293
283
|
end
|
294
284
|
|
295
285
|
private
|
296
|
-
|
297
286
|
def create_dummy_app(path = nil)
|
298
287
|
dummy_path(path) if path
|
299
288
|
|
300
289
|
say_status :vendor_app, dummy_path
|
301
290
|
mute do
|
302
291
|
build(:generate_test_dummy)
|
303
|
-
store_application_definition!
|
304
292
|
build(:test_dummy_config)
|
305
293
|
build(:test_dummy_assets)
|
306
294
|
build(:test_dummy_clean)
|
@@ -348,9 +336,9 @@ task default: :test
|
|
348
336
|
def wrap_in_modules(unwrapped_code)
|
349
337
|
unwrapped_code = "#{unwrapped_code}".strip.gsub(/\s$\n/, "")
|
350
338
|
modules.reverse.inject(unwrapped_code) do |content, mod|
|
351
|
-
str = "module #{mod}\n"
|
352
|
-
str
|
353
|
-
str
|
339
|
+
str = +"module #{mod}\n"
|
340
|
+
str << content.lines.map { |line| " #{line}" }.join
|
341
|
+
str << (content.present? ? "\nend" : "end")
|
354
342
|
end
|
355
343
|
end
|
356
344
|
|
@@ -385,11 +373,11 @@ task default: :test
|
|
385
373
|
end
|
386
374
|
|
387
375
|
def valid_const?
|
388
|
-
if
|
376
|
+
if /-\d/.match?(original_name)
|
389
377
|
raise Error, "Invalid plugin name #{original_name}. Please give a name which does not contain a namespace starting with numeric characters."
|
390
|
-
elsif
|
378
|
+
elsif /[^\w-]+/.match?(original_name)
|
391
379
|
raise Error, "Invalid plugin name #{original_name}. Please give a name which uses only alphabetic, numeric, \"_\" or \"-\" characters."
|
392
|
-
elsif
|
380
|
+
elsif /^\d/.match?(camelized)
|
393
381
|
raise Error, "Invalid plugin name #{original_name}. Please give a name which does not start with numbers."
|
394
382
|
elsif RESERVED_NAMES.include?(name)
|
395
383
|
raise Error, "Invalid plugin name #{original_name}. Please give a " \
|
@@ -400,25 +388,13 @@ task default: :test
|
|
400
388
|
end
|
401
389
|
end
|
402
390
|
|
403
|
-
def application_definition
|
404
|
-
@application_definition ||= begin
|
405
|
-
|
406
|
-
dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root)
|
407
|
-
unless options[:pretend] || !File.exist?(dummy_application_path)
|
408
|
-
contents = File.read(dummy_application_path)
|
409
|
-
contents[(contents.index(/module ([\w]+)\n(.*)class Application/m))..-1]
|
410
|
-
end
|
411
|
-
end
|
412
|
-
end
|
413
|
-
alias :store_application_definition! :application_definition
|
414
|
-
|
415
391
|
def get_builder_class
|
416
392
|
defined?(::PluginBuilder) ? ::PluginBuilder : Rails::PluginBuilder
|
417
393
|
end
|
418
394
|
|
419
395
|
def rakefile_test_tasks
|
420
396
|
<<-RUBY
|
421
|
-
require
|
397
|
+
require "rake/testtask"
|
422
398
|
|
423
399
|
Rake::TestTask.new(:test) do |t|
|
424
400
|
t.libs << 'test'
|
@@ -447,7 +423,7 @@ end
|
|
447
423
|
|
448
424
|
def relative_path
|
449
425
|
return unless inside_application?
|
450
|
-
app_path.
|
426
|
+
app_path.delete_prefix("#{rails_app_path}/")
|
451
427
|
end
|
452
428
|
end
|
453
429
|
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
|
1
|
+
require_relative "lib/<%= namespaced_name %>/version"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = <%= name.inspect %>
|
5
|
+
spec.version = <%= camelized_modules %>::VERSION
|
6
|
+
spec.authors = [<%= author.inspect %>]
|
7
|
+
spec.email = [<%= email.inspect %>]
|
8
|
+
spec.homepage = "TODO"
|
9
|
+
spec.summary = "TODO: Summary of <%= camelized_modules %>."
|
10
|
+
spec.description = "TODO: Description of <%= camelized_modules %>."
|
11
|
+
spec.license = "MIT"
|
5
12
|
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
s.version = <%= camelized_modules %>::VERSION
|
10
|
-
s.authors = ["<%= author %>"]
|
11
|
-
s.email = ["<%= email %>"]
|
12
|
-
s.homepage = "TODO"
|
13
|
-
s.summary = "TODO: Summary of <%= camelized_modules %>."
|
14
|
-
s.description = "TODO: Description of <%= camelized_modules %>."
|
15
|
-
s.license = "MIT"
|
13
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
14
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
15
|
+
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
16
|
|
17
|
-
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
19
|
+
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
18
20
|
|
19
|
-
|
20
|
-
<% unless options[:skip_active_record] -%>
|
21
|
+
spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
|
21
22
|
|
22
|
-
|
23
|
-
<% end -%>
|
23
|
+
<%= '# ' if options.dev? || options.edge? || options.master? -%>spec.add_dependency "rails", "<%= Array(rails_version_specifier).join('", "') %>"
|
24
24
|
end
|
@@ -2,23 +2,16 @@ source 'https://rubygems.org'
|
|
2
2
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
3
3
|
|
4
4
|
<% if options[:skip_gemspec] -%>
|
5
|
-
<%= '# ' if options.dev? || options.edge? -%>gem 'rails', '<%= Array(rails_version_specifier).join("', '") %>'
|
5
|
+
<%= '# ' if options.dev? || options.edge? || options.master? -%>gem 'rails', '<%= Array(rails_version_specifier).join("', '") %>'
|
6
6
|
<% else -%>
|
7
|
-
#
|
8
|
-
# Bundler will treat runtime dependencies like base dependencies, and
|
9
|
-
# development dependencies will be added by default to the :development group.
|
7
|
+
# Specify your gem's dependencies in <%= name %>.gemspec.
|
10
8
|
gemspec
|
11
9
|
<% end -%>
|
10
|
+
<% unless options[:skip_active_record] -%>
|
12
11
|
|
13
|
-
<% if options[:skip_gemspec] -%>
|
14
12
|
group :development do
|
15
13
|
gem '<%= gem_for_database[0] %>'
|
16
14
|
end
|
17
|
-
<% else -%>
|
18
|
-
# Declare any dependencies that are still in development here instead of in
|
19
|
-
# your gemspec. These might include edge Rails or gems from your path or
|
20
|
-
# Git. Remember to move these dependencies to your gemspec before releasing
|
21
|
-
# your gem to rubygems.org.
|
22
15
|
<% end -%>
|
23
16
|
|
24
17
|
<% if options.dev? || options.edge? -%>
|
@@ -1,28 +1,14 @@
|
|
1
|
-
|
2
|
-
require 'bundler/setup'
|
3
|
-
rescue LoadError
|
4
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
-
end
|
6
|
-
|
7
|
-
require 'rdoc/task'
|
8
|
-
|
9
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir = 'rdoc'
|
11
|
-
rdoc.title = '<%= camelized_modules %>'
|
12
|
-
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.md')
|
14
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
-
end
|
1
|
+
require "bundler/setup"
|
16
2
|
<% if engine? && !options[:skip_active_record] && with_dummy_app? -%>
|
17
3
|
|
18
4
|
APP_RAKEFILE = File.expand_path("<%= dummy_path -%>/Rakefile", __dir__)
|
19
|
-
load
|
5
|
+
load "rails/tasks/engine.rake"
|
20
6
|
<% end -%>
|
21
7
|
<% if engine? -%>
|
22
8
|
|
23
|
-
load
|
9
|
+
load "rails/tasks/statistics.rake"
|
24
10
|
<% end -%>
|
25
11
|
<% unless options[:skip_gemspec] -%>
|
26
12
|
|
27
|
-
require
|
13
|
+
require "bundler/gem_tasks"
|
28
14
|
<% end -%>
|
@@ -9,10 +9,10 @@ APP_PATH = File.expand_path('../<%= dummy_path -%>/config/application', __dir__)
|
|
9
9
|
|
10
10
|
# Set up gems listed in the Gemfile.
|
11
11
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
12
|
-
require
|
12
|
+
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
13
13
|
|
14
14
|
<% if include_all_railties? -%>
|
15
|
-
require
|
15
|
+
require "rails/all"
|
16
16
|
<% else -%>
|
17
17
|
require "rails"
|
18
18
|
# Pick the frameworks you want:
|
@@ -27,4 +27,4 @@ require "action_view/railtie"
|
|
27
27
|
<%= comment_if :skip_sprockets %>require "sprockets/railtie"
|
28
28
|
<%= comment_if :skip_test %>require "rails/test_unit/railtie"
|
29
29
|
<% end -%>
|
30
|
-
require
|
30
|
+
require "rails/engine/commands"
|
@@ -1,18 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
/.bundle/
|
2
|
+
/doc/
|
3
|
+
/log/*.log
|
4
|
+
/pkg/
|
5
|
+
/tmp/
|
4
6
|
<% if with_dummy_app? -%>
|
5
7
|
<% if sqlite3? -%>
|
6
|
-
|
7
|
-
|
8
|
+
/<%= dummy_path %>/db/*.sqlite3
|
9
|
+
/<%= dummy_path %>/db/*.sqlite3-*
|
8
10
|
<% end -%>
|
9
|
-
|
10
|
-
<% unless options[:
|
11
|
-
|
12
|
-
|
11
|
+
/<%= dummy_path %>/log/*.log
|
12
|
+
<% unless options[:skip_javascript] -%>
|
13
|
+
/<%= dummy_path %>/node_modules/
|
14
|
+
/<%= dummy_path %>/yarn-error.log
|
13
15
|
<% end -%>
|
14
16
|
<% unless skip_active_storage? -%>
|
15
|
-
|
17
|
+
/<%= dummy_path %>/storage/
|
16
18
|
<% end -%>
|
17
|
-
|
19
|
+
/<%= dummy_path %>/tmp/
|
18
20
|
<% end -%>
|
21
|
+
.byebug_history
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Set up gems listed in the Gemfile.
|
2
2
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
|
3
3
|
|
4
|
-
require
|
4
|
+
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
5
5
|
$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
|
-
class <%= camelized_modules
|
4
|
-
test "
|
5
|
-
|
3
|
+
class <%= camelized_modules %>Test < ActiveSupport::TestCase
|
4
|
+
test "it has a version number" do
|
5
|
+
assert <%= camelized_modules %>::VERSION
|
6
6
|
end
|
7
7
|
end
|
@@ -10,10 +10,6 @@ ActiveRecord::Migrator.migrations_paths << File.expand_path('../db/migrate', __d
|
|
10
10
|
<% end -%>
|
11
11
|
require "rails/test_help"
|
12
12
|
|
13
|
-
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
14
|
-
# to be shown.
|
15
|
-
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
16
|
-
|
17
13
|
<% unless engine? -%>
|
18
14
|
require "rails/test_unit/reporter"
|
19
15
|
Rails::TestUnitReporter.executable = 'bin/test'
|
@@ -1,5 +1,5 @@
|
|
1
1
|
Description:
|
2
|
-
|
2
|
+
Generates a new resource including an empty model and controller suitable
|
3
3
|
for a RESTful, resource-oriented application. Pass the singular model name,
|
4
4
|
either CamelCased or under_scored, as the first argument, and an optional
|
5
5
|
list of attribute pairs.
|
@@ -18,6 +18,6 @@ Description:
|
|
18
18
|
views or add any methods to the generated controller.
|
19
19
|
|
20
20
|
Examples:
|
21
|
-
`rails generate resource post` # no attributes
|
22
|
-
`rails generate resource post title:string body:text published:boolean`
|
23
|
-
`rails generate resource purchase order_id:integer amount:decimal`
|
21
|
+
`bin/rails generate resource post` # no attributes
|
22
|
+
`bin/rails generate resource post title:string body:text published:boolean`
|
23
|
+
`bin/rails generate resource purchase order_id:integer amount:decimal`
|
@@ -5,7 +5,7 @@ module Rails
|
|
5
5
|
class ResourceRouteGenerator < NamedBase # :nodoc:
|
6
6
|
# Properly nests namespaces passed into a generator
|
7
7
|
#
|
8
|
-
# $ rails generate resource admin/users/products
|
8
|
+
# $ bin/rails generate resource admin/users/products
|
9
9
|
#
|
10
10
|
# should give you
|
11
11
|
#
|
@@ -16,32 +16,7 @@ module Rails
|
|
16
16
|
# end
|
17
17
|
def add_resource_route
|
18
18
|
return if options[:actions].present?
|
19
|
-
|
20
|
-
depth = 0
|
21
|
-
lines = []
|
22
|
-
|
23
|
-
# Create 'namespace' ladder
|
24
|
-
# namespace :foo do
|
25
|
-
# namespace :bar do
|
26
|
-
regular_class_path.each do |ns|
|
27
|
-
lines << indent("namespace :#{ns} do\n", depth * 2)
|
28
|
-
depth += 1
|
29
|
-
end
|
30
|
-
|
31
|
-
# inserts the primary resource
|
32
|
-
# Create route
|
33
|
-
# resources 'products'
|
34
|
-
lines << indent(%{resources :#{file_name.pluralize}\n}, depth * 2)
|
35
|
-
|
36
|
-
# Create `end` ladder
|
37
|
-
# end
|
38
|
-
# end
|
39
|
-
until depth.zero?
|
40
|
-
depth -= 1
|
41
|
-
lines << indent("end\n", depth * 2)
|
42
|
-
end
|
43
|
-
|
44
|
-
route lines.join
|
19
|
+
route "resources :#{file_name.pluralize}", namespace: regular_class_path
|
45
20
|
end
|
46
21
|
end
|
47
22
|
end
|
@@ -32,10 +32,10 @@ Description:
|
|
32
32
|
in config/routes.rb.
|
33
33
|
|
34
34
|
If you want to remove all the generated files, run
|
35
|
-
'rails destroy scaffold ModelName'.
|
35
|
+
'bin/rails destroy scaffold ModelName'.
|
36
36
|
|
37
37
|
Examples:
|
38
|
-
`rails generate scaffold post`
|
39
|
-
`rails generate scaffold post title:string body:text published:boolean`
|
40
|
-
`rails generate scaffold purchase amount:decimal tracking_id:integer:uniq`
|
41
|
-
`rails generate scaffold user email:uniq password:digest`
|
38
|
+
`bin/rails generate scaffold post`
|
39
|
+
`bin/rails generate scaffold post title:string body:text published:boolean`
|
40
|
+
`bin/rails generate scaffold purchase amount:decimal tracking_id:integer:uniq`
|
41
|
+
`bin/rails generate scaffold user email:uniq password:digest`
|
@@ -1,5 +1,5 @@
|
|
1
1
|
Description:
|
2
|
-
|
2
|
+
Generates a scaffolded controller, its seven RESTful actions and related
|
3
3
|
views. Pass the model name, either CamelCased or under_scored. The
|
4
4
|
controller name is retrieved as a pluralized version of the model name.
|
5
5
|
|
@@ -10,7 +10,7 @@ Description:
|
|
10
10
|
template engine and test framework generators.
|
11
11
|
|
12
12
|
Example:
|
13
|
-
`rails generate scaffold_controller CreditCard`
|
13
|
+
`bin/rails generate scaffold_controller CreditCard`
|
14
14
|
|
15
15
|
Credit card controller with URLs like /credit_cards.
|
16
16
|
Controller: app/controllers/credit_cards_controller.rb
|
@@ -15,6 +15,8 @@ module Rails
|
|
15
15
|
class_option :api, type: :boolean,
|
16
16
|
desc: "Generates API controller"
|
17
17
|
|
18
|
+
class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
|
19
|
+
|
18
20
|
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
19
21
|
|
20
22
|
def create_controller_files
|
@@ -26,12 +28,29 @@ module Rails
|
|
26
28
|
invoke template_engine unless options.api?
|
27
29
|
end
|
28
30
|
|
31
|
+
hook_for :resource_route, required: true do |route|
|
32
|
+
invoke route unless options.skip_routes?
|
33
|
+
end
|
34
|
+
|
29
35
|
hook_for :test_framework, as: :scaffold
|
30
36
|
|
31
37
|
# Invoke the helper using the controller name (pluralized)
|
32
38
|
hook_for :helper, as: :scaffold do |invoked|
|
33
39
|
invoke invoked, [ controller_name ]
|
34
40
|
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def permitted_params
|
44
|
+
attachments, others = attributes_names.partition { |name| attachments?(name) }
|
45
|
+
params = others.map { |name| ":#{name}" }
|
46
|
+
params += attachments.map { |name| "#{name}: []" }
|
47
|
+
params.join(", ")
|
48
|
+
end
|
49
|
+
|
50
|
+
def attachments?(name)
|
51
|
+
attribute = attributes.find { |attr| attr.name == name }
|
52
|
+
attribute&.attachments?
|
53
|
+
end
|
35
54
|
end
|
36
55
|
end
|
37
56
|
end
|
@@ -49,12 +49,12 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
49
49
|
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
50
50
|
end
|
51
51
|
|
52
|
-
# Only allow a
|
52
|
+
# Only allow a list of trusted parameters through.
|
53
53
|
def <%= "#{singular_table_name}_params" %>
|
54
54
|
<%- if attributes_names.empty? -%>
|
55
55
|
params.fetch(:<%= singular_table_name %>, {})
|
56
56
|
<%- else -%>
|
57
|
-
params.require(:<%= singular_table_name %>).permit(<%=
|
57
|
+
params.require(:<%= singular_table_name %>).permit(<%= permitted_params %>)
|
58
58
|
<%- end -%>
|
59
59
|
end
|
60
60
|
end
|
@@ -56,12 +56,12 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
56
56
|
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
57
57
|
end
|
58
58
|
|
59
|
-
# Only allow a
|
59
|
+
# Only allow a list of trusted parameters through.
|
60
60
|
def <%= "#{singular_table_name}_params" %>
|
61
61
|
<%- if attributes_names.empty? -%>
|
62
62
|
params.fetch(:<%= singular_table_name %>, {})
|
63
63
|
<%- else -%>
|
64
|
-
params.require(:<%= singular_table_name %>).permit(<%=
|
64
|
+
params.require(:<%= singular_table_name %>).permit(<%= permitted_params %>)
|
65
65
|
<%- end -%>
|
66
66
|
end
|
67
67
|
end
|