railties 7.2.3 → 8.0.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +111 -324
- data/README.rdoc +1 -1
- data/lib/minitest/rails_plugin.rb +2 -2
- data/lib/rails/application/bootstrap.rb +3 -1
- data/lib/rails/application/configuration.rb +22 -7
- data/lib/rails/application/default_middleware_stack.rb +4 -0
- data/lib/rails/application/finisher.rb +2 -2
- data/lib/rails/application/routes_reloader.rb +11 -1
- data/lib/rails/application.rb +14 -12
- data/lib/rails/backtrace_cleaner.rb +1 -1
- data/lib/rails/code_statistics.rb +128 -86
- data/lib/rails/code_statistics_calculator.rb +78 -76
- data/lib/rails/command/helpers/editor.rb +1 -1
- data/lib/rails/commands/app/update_command.rb +1 -9
- data/lib/rails/commands/console/irb_console.rb +6 -3
- data/lib/rails/commands/credentials/USAGE +4 -4
- data/lib/rails/commands/credentials/credentials_command.rb +5 -1
- data/lib/rails/commands/dev/dev_command.rb +1 -1
- data/lib/rails/commands/devcontainer/devcontainer_command.rb +1 -1
- data/lib/rails/commands/stats/stats_command.rb +19 -0
- data/lib/rails/commands/test/test_command.rb +2 -0
- data/lib/rails/dev_caching.rb +2 -2
- data/lib/rails/engine/configuration.rb +3 -1
- data/lib/rails/engine/lazy_route_set.rb +109 -0
- data/lib/rails/engine.rb +8 -3
- data/lib/rails/gem_version.rb +4 -4
- data/lib/rails/generators/actions.rb +5 -9
- data/lib/rails/generators/app_base.rb +49 -31
- data/lib/rails/generators/database.rb +101 -67
- data/lib/rails/generators/erb/authentication/authentication_generator.rb +15 -0
- data/lib/rails/generators/erb/authentication/templates/views/passwords/edit.html.erb +9 -0
- data/lib/rails/generators/erb/authentication/templates/views/passwords/new.html.erb +8 -0
- data/lib/rails/generators/erb/authentication/templates/views/sessions/new.html.erb +11 -0
- data/lib/rails/generators/generated_attribute.rb +16 -11
- data/lib/rails/generators/rails/app/app_generator.rb +19 -28
- data/lib/rails/generators/rails/app/templates/Dockerfile.tt +12 -3
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +23 -8
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css.tt +6 -11
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +10 -3
- data/lib/rails/generators/rails/app/templates/bin/dev.tt +1 -0
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +5 -7
- data/lib/rails/generators/rails/app/templates/bin/thrust.tt +4 -0
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +23 -0
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +23 -0
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +40 -0
- data/lib/rails/generators/rails/app/templates/config/databases/trilogy.yml.tt +23 -0
- data/lib/rails/generators/rails/app/templates/config/deploy.yml.tt +124 -0
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +12 -23
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +31 -51
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +5 -19
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +0 -7
- data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_8_0.rb.tt +25 -0
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +11 -2
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +3 -3
- data/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +4 -3
- data/lib/rails/generators/rails/app/templates/dockerignore.tt +1 -2
- data/lib/rails/generators/rails/app/templates/github/ci.yml.tt +1 -3
- data/lib/rails/generators/rails/app/templates/gitignore.tt +1 -2
- data/lib/rails/generators/rails/app/templates/kamal-secrets.tt +17 -0
- data/lib/rails/generators/rails/app/templates/public/400.html +114 -0
- data/lib/rails/generators/rails/app/templates/public/404.html +113 -66
- data/lib/rails/generators/rails/app/templates/public/406-unsupported-browser.html +113 -65
- data/lib/rails/generators/rails/app/templates/public/422.html +113 -66
- data/lib/rails/generators/rails/app/templates/public/500.html +113 -65
- data/lib/rails/generators/rails/app/templates/public/icon.png +0 -0
- data/lib/rails/generators/rails/app/templates/public/icon.svg +2 -2
- data/lib/rails/generators/rails/authentication/USAGE +6 -0
- data/lib/rails/generators/rails/authentication/authentication_generator.rb +54 -0
- data/lib/rails/generators/rails/authentication/templates/controllers/concerns/authentication.rb +55 -0
- data/lib/rails/generators/rails/authentication/templates/controllers/passwords_controller.rb +33 -0
- data/lib/rails/generators/rails/authentication/templates/controllers/sessions_controller.rb +21 -0
- data/lib/rails/generators/rails/authentication/templates/mailers/passwords_mailer.rb +6 -0
- data/lib/rails/generators/rails/authentication/templates/models/current.rb +4 -0
- data/lib/rails/generators/rails/authentication/templates/models/session.rb +3 -0
- data/lib/rails/generators/rails/authentication/templates/models/user.rb +6 -0
- data/lib/rails/generators/rails/authentication/templates/test/mailers/previews/passwords_mailer_preview.rb +7 -0
- data/lib/rails/generators/rails/authentication/templates/views/passwords_mailer/reset.html.erb +4 -0
- data/lib/rails/generators/rails/authentication/templates/views/passwords_mailer/reset.text.erb +2 -0
- data/lib/rails/generators/rails/credentials/templates/credentials.yml.tt +4 -0
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +1 -1
- data/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb +4 -2
- data/lib/rails/generators/rails/devcontainer/templates/devcontainer/devcontainer.json.tt +1 -1
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +7 -9
- data/lib/rails/generators/rails/plugin/templates/github/ci.yml.tt +2 -3
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +4 -4
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +5 -5
- data/lib/rails/generators/rails/script/USAGE +18 -0
- data/lib/rails/generators/rails/script/script_generator.rb +18 -0
- data/lib/rails/generators/rails/script/templates/script.rb.tt +3 -0
- data/lib/rails/generators.rb +6 -5
- data/lib/rails/info_controller.rb +10 -4
- data/lib/rails/rack/silence_request.rb +33 -0
- data/lib/rails/rack.rb +1 -0
- data/lib/rails/source_annotation_extractor.rb +31 -14
- data/lib/rails/tasks/statistics.rake +13 -28
- data/lib/rails/templates/rails/info/notes.html.erb +65 -0
- data/lib/rails/test_unit/runner.rb +3 -7
- data/lib/rails/test_unit/test_parser.rb +15 -18
- metadata +45 -50
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -2
- data/lib/rails/generators/rails/app/templates/app/channels/application_cable/channel.rb.tt +0 -4
- data/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb.tt +0 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_2.rb.tt +0 -70
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +0 -13
- data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +0 -13
- data/lib/rails/generators/rails/plugin/templates/rails/dummy_manifest.js.tt +0 -10
- data/lib/rails/generators/rails/plugin/templates/rails/engine_manifest.js.tt +0 -6
- data/lib/rails/generators/rails/plugin/templates/rails/javascripts.js.tt +0 -17
|
@@ -143,6 +143,7 @@ module Rails
|
|
|
143
143
|
app.routes.prepend do
|
|
144
144
|
get "/rails/info/properties" => "rails/info#properties", internal: true
|
|
145
145
|
get "/rails/info/routes" => "rails/info#routes", internal: true
|
|
146
|
+
get "/rails/info/notes" => "rails/info#notes", internal: true
|
|
146
147
|
get "/rails/info" => "rails/info#index", internal: true
|
|
147
148
|
end
|
|
148
149
|
|
|
@@ -159,7 +160,6 @@ module Rails
|
|
|
159
160
|
initializer :set_routes_reloader_hook do |app|
|
|
160
161
|
reloader = routes_reloader
|
|
161
162
|
reloader.eager_load = app.config.eager_load
|
|
162
|
-
reloader.execute
|
|
163
163
|
reloaders << reloader
|
|
164
164
|
|
|
165
165
|
app.reloader.to_run do
|
|
@@ -177,7 +177,7 @@ module Rails
|
|
|
177
177
|
ActiveSupport.run_load_hooks(:after_routes_loaded, self)
|
|
178
178
|
end
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
reloader.execute_unless_loaded if !app.routes.is_a?(Engine::LazyRouteSet) || app.config.eager_load
|
|
181
181
|
end
|
|
182
182
|
|
|
183
183
|
# Set clearing dependencies after the finisher hook to ensure paths
|
|
@@ -7,7 +7,7 @@ module Rails
|
|
|
7
7
|
class RoutesReloader
|
|
8
8
|
include ActiveSupport::Callbacks
|
|
9
9
|
|
|
10
|
-
attr_reader :route_sets, :paths, :external_routes
|
|
10
|
+
attr_reader :route_sets, :paths, :external_routes, :loaded
|
|
11
11
|
attr_accessor :eager_load
|
|
12
12
|
attr_writer :run_after_load_paths # :nodoc:
|
|
13
13
|
delegate :execute_if_updated, :execute, :updated?, to: :updater
|
|
@@ -17,9 +17,11 @@ module Rails
|
|
|
17
17
|
@route_sets = []
|
|
18
18
|
@external_routes = []
|
|
19
19
|
@eager_load = false
|
|
20
|
+
@loaded = false
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
def reload!
|
|
24
|
+
@loaded = true
|
|
23
25
|
clear!
|
|
24
26
|
load_paths
|
|
25
27
|
finalize!
|
|
@@ -28,6 +30,14 @@ module Rails
|
|
|
28
30
|
revert
|
|
29
31
|
end
|
|
30
32
|
|
|
33
|
+
def execute_unless_loaded
|
|
34
|
+
unless @loaded
|
|
35
|
+
execute
|
|
36
|
+
ActiveSupport.run_load_hooks(:after_routes_loaded, Rails.application)
|
|
37
|
+
true
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
31
41
|
private
|
|
32
42
|
def updater
|
|
33
43
|
@updater ||= begin
|
data/lib/rails/application.rb
CHANGED
|
@@ -9,6 +9,7 @@ require "active_support/deprecation"
|
|
|
9
9
|
require "active_support/encrypted_configuration"
|
|
10
10
|
require "active_support/hash_with_indifferent_access"
|
|
11
11
|
require "active_support/configuration_file"
|
|
12
|
+
require "active_support/parameter_filter"
|
|
12
13
|
require "rails/engine"
|
|
13
14
|
require "rails/autoloaders"
|
|
14
15
|
|
|
@@ -160,6 +161,10 @@ module Rails
|
|
|
160
161
|
routes_reloader.reload!
|
|
161
162
|
end
|
|
162
163
|
|
|
164
|
+
def reload_routes_unless_loaded # :nodoc:
|
|
165
|
+
initialized? && routes_reloader.execute_unless_loaded
|
|
166
|
+
end
|
|
167
|
+
|
|
163
168
|
# Returns a key generator (ActiveSupport::CachingKeyGenerator) for a
|
|
164
169
|
# specified +secret_key_base+. The return value is memoized, so additional
|
|
165
170
|
# calls with the same +secret_key_base+ will return the same key generator
|
|
@@ -454,21 +459,18 @@ module Rails
|
|
|
454
459
|
# is used to create all ActiveSupport::MessageVerifier and ActiveSupport::MessageEncryptor instances,
|
|
455
460
|
# including the ones that sign and encrypt cookies.
|
|
456
461
|
#
|
|
457
|
-
#
|
|
458
|
-
#
|
|
459
|
-
# to store it is in the encrypted credentials file.
|
|
462
|
+
# In development and test, this is randomly generated and stored in a
|
|
463
|
+
# temporary file in <tt>tmp/local_secret.txt</tt>.
|
|
460
464
|
#
|
|
461
|
-
#
|
|
462
|
-
#
|
|
463
|
-
#
|
|
464
|
-
#
|
|
465
|
-
# Generating a random secret_key_base and storing it in
|
|
466
|
-
# <tt>tmp/local_secret.txt</tt> can also be triggered by setting
|
|
467
|
-
# <tt>ENV["SECRET_KEY_BASE_DUMMY"]</tt>. This is useful when precompiling
|
|
468
|
-
# assets for production as part of a build step that otherwise does not
|
|
469
|
-
# need access to the production secrets.
|
|
465
|
+
# You can also set <tt>ENV["SECRET_KEY_BASE_DUMMY"]</tt> to trigger the use of a randomly generated
|
|
466
|
+
# secret_key_base that's stored in a temporary file. This is useful when precompiling assets for
|
|
467
|
+
# production as part of a build step that otherwise does not need access to the production secrets.
|
|
470
468
|
#
|
|
471
469
|
# Dockerfile example: <tt>RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile</tt>.
|
|
470
|
+
#
|
|
471
|
+
# In all other environments, we look for it first in <tt>ENV["SECRET_KEY_BASE"]</tt>,
|
|
472
|
+
# then +credentials.secret_key_base+. For most applications, the correct place to store it is in the
|
|
473
|
+
# encrypted credentials file.
|
|
472
474
|
def secret_key_base
|
|
473
475
|
config.secret_key_base
|
|
474
476
|
end
|
|
@@ -5,7 +5,7 @@ require "active_support/core_ext/string/access"
|
|
|
5
5
|
|
|
6
6
|
module Rails
|
|
7
7
|
class BacktraceCleaner < ActiveSupport::BacktraceCleaner # :nodoc:
|
|
8
|
-
APP_DIRS_PATTERN = /\A(?:\.\/)?(?:app|config|lib|test|\(\w
|
|
8
|
+
APP_DIRS_PATTERN = /\A(?:\.\/)?(?:app|config|lib|test|\(\w*\))/
|
|
9
9
|
RENDER_TEMPLATE_PATTERN = /:in [`'].*_\w+_{2,3}\d+_\d+'/
|
|
10
10
|
|
|
11
11
|
def initialize
|
|
@@ -3,115 +3,157 @@
|
|
|
3
3
|
require "rails/code_statistics_calculator"
|
|
4
4
|
require "active_support/core_ext/enumerable"
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
6
|
+
module Rails
|
|
7
|
+
class CodeStatistics
|
|
8
|
+
DIRECTORIES = [
|
|
9
|
+
%w(Controllers app/controllers),
|
|
10
|
+
%w(Helpers app/helpers),
|
|
11
|
+
%w(Jobs app/jobs),
|
|
12
|
+
%w(Models app/models),
|
|
13
|
+
%w(Mailers app/mailers),
|
|
14
|
+
%w(Mailboxes app/mailboxes),
|
|
15
|
+
%w(Channels app/channels),
|
|
16
|
+
%w(Views app/views),
|
|
17
|
+
%w(JavaScripts app/assets/javascripts),
|
|
18
|
+
%w(Stylesheets app/assets/stylesheets),
|
|
19
|
+
%w(JavaScript app/javascript),
|
|
20
|
+
%w(Libraries lib/),
|
|
21
|
+
%w(APIs app/apis),
|
|
22
|
+
%w(Controller\ tests test/controllers),
|
|
23
|
+
%w(Helper\ tests test/helpers),
|
|
24
|
+
%w(Job\ tests test/jobs),
|
|
25
|
+
%w(Model\ tests test/models),
|
|
26
|
+
%w(Mailer\ tests test/mailers),
|
|
27
|
+
%w(Mailbox\ tests test/mailboxes),
|
|
28
|
+
%w(Channel\ tests test/channels),
|
|
29
|
+
%w(Integration\ tests test/integration),
|
|
30
|
+
%w(System\ tests test/system),
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
TEST_TYPES = ["Controller tests",
|
|
34
|
+
"Helper tests",
|
|
35
|
+
"Model tests",
|
|
36
|
+
"Mailer tests",
|
|
37
|
+
"Mailbox tests",
|
|
38
|
+
"Channel tests",
|
|
39
|
+
"Job tests",
|
|
40
|
+
"Integration tests",
|
|
41
|
+
"System tests"]
|
|
42
|
+
|
|
43
|
+
HEADERS = { lines: " Lines", code_lines: " LOC", classes: "Classes", methods: "Methods" }
|
|
44
|
+
|
|
45
|
+
class_attribute :directories, default: DIRECTORIES
|
|
46
|
+
class_attribute :test_types, default: TEST_TYPES
|
|
47
|
+
|
|
48
|
+
# Add directories to the output of the `bin/rails stats` command.
|
|
49
|
+
#
|
|
50
|
+
# Rails::CodeStatistics.register_directory("My Directory", "path/to/dir")
|
|
51
|
+
#
|
|
52
|
+
# For directories that contain test code, set the `test_directory` argument to true.
|
|
53
|
+
#
|
|
54
|
+
# Rails::CodeStatistics.register_directory("Model specs", "spec/models", test_directory: true)
|
|
55
|
+
def self.register_directory(label, path, test_directory: false)
|
|
56
|
+
self.directories << [label, path]
|
|
57
|
+
self.test_types << label if test_directory
|
|
58
|
+
end
|
|
24
59
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
60
|
+
def initialize(*pairs)
|
|
61
|
+
@pairs = pairs
|
|
62
|
+
@statistics = calculate_statistics
|
|
63
|
+
@total = calculate_total if pairs.length > 1
|
|
64
|
+
end
|
|
29
65
|
|
|
30
|
-
|
|
31
|
-
|
|
66
|
+
def to_s
|
|
67
|
+
print_header
|
|
68
|
+
@pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) }
|
|
32
69
|
print_splitter
|
|
33
|
-
end
|
|
34
70
|
|
|
35
|
-
|
|
36
|
-
|
|
71
|
+
if @total
|
|
72
|
+
print_line("Total", @total)
|
|
73
|
+
print_splitter
|
|
74
|
+
end
|
|
37
75
|
|
|
38
|
-
|
|
39
|
-
def calculate_statistics
|
|
40
|
-
Hash[@pairs.map { |pair| [pair.first, calculate_directory_statistics(pair.last)] }]
|
|
76
|
+
print_code_test_stats
|
|
41
77
|
end
|
|
42
78
|
|
|
43
|
-
|
|
44
|
-
|
|
79
|
+
private
|
|
80
|
+
def calculate_statistics
|
|
81
|
+
Hash[@pairs.map { |pair| [pair.first, calculate_directory_statistics(pair.last)] }]
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def calculate_directory_statistics(directory, pattern = /^(?!\.).*?\.(rb|js|ts|css|scss|coffee|rake|erb)$/)
|
|
85
|
+
stats = Rails::CodeStatisticsCalculator.new
|
|
45
86
|
|
|
46
|
-
|
|
47
|
-
|
|
87
|
+
Dir.foreach(directory) do |file_name|
|
|
88
|
+
path = "#{directory}/#{file_name}"
|
|
48
89
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
90
|
+
if File.directory?(path) && !file_name.start_with?(".")
|
|
91
|
+
stats.add(calculate_directory_statistics(path, pattern))
|
|
92
|
+
elsif file_name&.match?(pattern)
|
|
93
|
+
stats.add_by_file_path(path)
|
|
94
|
+
end
|
|
53
95
|
end
|
|
54
|
-
end
|
|
55
96
|
|
|
56
|
-
|
|
57
|
-
|
|
97
|
+
stats
|
|
98
|
+
end
|
|
58
99
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
100
|
+
def calculate_total
|
|
101
|
+
@statistics.each_with_object(Rails::CodeStatisticsCalculator.new) do |pair, total|
|
|
102
|
+
total.add(pair.last)
|
|
103
|
+
end
|
|
62
104
|
end
|
|
63
|
-
end
|
|
64
105
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
106
|
+
def calculate_code
|
|
107
|
+
code_loc = 0
|
|
108
|
+
@statistics.each { |k, v| code_loc += v.code_lines unless test_types.include? k }
|
|
109
|
+
code_loc
|
|
110
|
+
end
|
|
70
111
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
112
|
+
def calculate_tests
|
|
113
|
+
test_loc = 0
|
|
114
|
+
@statistics.each { |k, v| test_loc += v.code_lines if test_types.include? k }
|
|
115
|
+
test_loc
|
|
116
|
+
end
|
|
76
117
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
118
|
+
def width_for(label)
|
|
119
|
+
[@statistics.values.sum { |s| s.public_send(label) }.to_s.size, HEADERS[label].length].max
|
|
120
|
+
end
|
|
80
121
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
122
|
+
def print_header
|
|
123
|
+
print_splitter
|
|
124
|
+
print "| Name "
|
|
125
|
+
HEADERS.each do |k, v|
|
|
126
|
+
print " | #{v.rjust(width_for(k))}"
|
|
127
|
+
end
|
|
128
|
+
puts " | M/C | LOC/M |"
|
|
129
|
+
print_splitter
|
|
86
130
|
end
|
|
87
|
-
puts " | M/C | LOC/M |"
|
|
88
|
-
print_splitter
|
|
89
|
-
end
|
|
90
131
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
132
|
+
def print_splitter
|
|
133
|
+
print "+----------------------"
|
|
134
|
+
HEADERS.each_key do |k|
|
|
135
|
+
print "+#{'-' * (width_for(k) + 2)}"
|
|
136
|
+
end
|
|
137
|
+
puts "+-----+-------+"
|
|
95
138
|
end
|
|
96
|
-
puts "+-----+-------+"
|
|
97
|
-
end
|
|
98
139
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
140
|
+
def print_line(name, statistics)
|
|
141
|
+
m_over_c = (statistics.methods / statistics.classes) rescue 0
|
|
142
|
+
loc_over_m = (statistics.code_lines / statistics.methods) - 2 rescue 0
|
|
102
143
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
144
|
+
print "| #{name.ljust(20)} "
|
|
145
|
+
HEADERS.each_key do |k|
|
|
146
|
+
print "| #{statistics.send(k).to_s.rjust(width_for(k))} "
|
|
147
|
+
end
|
|
148
|
+
puts "| #{m_over_c.to_s.rjust(3)} | #{loc_over_m.to_s.rjust(5)} |"
|
|
106
149
|
end
|
|
107
|
-
puts "| #{m_over_c.to_s.rjust(3)} | #{loc_over_m.to_s.rjust(5)} |"
|
|
108
|
-
end
|
|
109
150
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
151
|
+
def print_code_test_stats
|
|
152
|
+
code = calculate_code
|
|
153
|
+
tests = calculate_tests
|
|
113
154
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
155
|
+
puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.1f", tests.to_f / code)}"
|
|
156
|
+
puts ""
|
|
157
|
+
end
|
|
158
|
+
end
|
|
117
159
|
end
|
|
@@ -1,97 +1,99 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
module Rails
|
|
4
|
+
class CodeStatisticsCalculator # :nodoc:
|
|
5
|
+
attr_reader :lines, :code_lines, :classes, :methods
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
7
|
+
PATTERNS = {
|
|
8
|
+
rb: {
|
|
9
|
+
line_comment: /^\s*#/,
|
|
10
|
+
begin_block_comment: /^=begin/,
|
|
11
|
+
end_block_comment: /^=end/,
|
|
12
|
+
class: /^\s*class\s+[_A-Z]/,
|
|
13
|
+
method: /^\s*def\s+[_a-z]/,
|
|
14
|
+
},
|
|
15
|
+
erb: {
|
|
16
|
+
line_comment: %r{((^\s*<%#.*%>)|(<!--.*-->))},
|
|
17
|
+
},
|
|
18
|
+
css: {
|
|
19
|
+
line_comment: %r{^\s*/\*.*\*/},
|
|
20
|
+
},
|
|
21
|
+
scss: {
|
|
22
|
+
line_comment: %r{((^\s*/\*.*\*/)|(^\s*//))},
|
|
23
|
+
},
|
|
24
|
+
js: {
|
|
25
|
+
line_comment: %r{^\s*//},
|
|
26
|
+
begin_block_comment: %r{^\s*/\*},
|
|
27
|
+
end_block_comment: %r{\*/},
|
|
28
|
+
method: /function(\s+[_a-zA-Z][\da-zA-Z]*)?\s*\(/,
|
|
29
|
+
},
|
|
30
|
+
coffee: {
|
|
31
|
+
line_comment: /^\s*#/,
|
|
32
|
+
begin_block_comment: /^\s*###/,
|
|
33
|
+
end_block_comment: /^\s*###/,
|
|
34
|
+
class: /^\s*class\s+[_A-Z]/,
|
|
35
|
+
method: /[-=]>/,
|
|
36
|
+
}
|
|
35
37
|
}
|
|
36
|
-
}
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
PATTERNS[:minitest] = PATTERNS[:rb].merge method: /^\s*(def|test)\s+['"_a-z]/
|
|
40
|
+
PATTERNS[:rake] = PATTERNS[:rb]
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
def initialize(lines = 0, code_lines = 0, classes = 0, methods = 0)
|
|
43
|
+
@lines = lines
|
|
44
|
+
@code_lines = code_lines
|
|
45
|
+
@classes = classes
|
|
46
|
+
@methods = methods
|
|
47
|
+
end
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
def add(code_statistics_calculator)
|
|
50
|
+
@lines += code_statistics_calculator.lines
|
|
51
|
+
@code_lines += code_statistics_calculator.code_lines
|
|
52
|
+
@classes += code_statistics_calculator.classes
|
|
53
|
+
@methods += code_statistics_calculator.methods
|
|
54
|
+
end
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
def add_by_file_path(file_path)
|
|
57
|
+
File.open(file_path) do |f|
|
|
58
|
+
add_by_io(f, file_type(file_path))
|
|
59
|
+
end
|
|
58
60
|
end
|
|
59
|
-
end
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
def add_by_io(io, file_type)
|
|
63
|
+
patterns = PATTERNS[file_type] || {}
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
comment_started = false
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
while line = io.gets
|
|
68
|
+
@lines += 1
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
next
|
|
74
|
-
else
|
|
75
|
-
if patterns[:begin_block_comment] && patterns[:begin_block_comment].match?(line)
|
|
76
|
-
comment_started = true
|
|
70
|
+
if comment_started
|
|
71
|
+
if patterns[:end_block_comment] && patterns[:end_block_comment].match?(line)
|
|
72
|
+
comment_started = false
|
|
73
|
+
end
|
|
77
74
|
next
|
|
75
|
+
else
|
|
76
|
+
if patterns[:begin_block_comment] && patterns[:begin_block_comment].match?(line)
|
|
77
|
+
comment_started = true
|
|
78
|
+
next
|
|
79
|
+
end
|
|
78
80
|
end
|
|
79
|
-
end
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
@classes += 1 if patterns[:class] && patterns[:class].match?(line)
|
|
83
|
+
@methods += 1 if patterns[:method] && patterns[:method].match?(line)
|
|
84
|
+
if !line.match?(/^\s*$/) && (patterns[:line_comment].nil? || !line.match?(patterns[:line_comment]))
|
|
85
|
+
@code_lines += 1
|
|
86
|
+
end
|
|
85
87
|
end
|
|
86
88
|
end
|
|
87
|
-
end
|
|
88
89
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
private
|
|
91
|
+
def file_type(file_path)
|
|
92
|
+
if file_path.end_with? "_test.rb"
|
|
93
|
+
:minitest
|
|
94
|
+
else
|
|
95
|
+
File.extname(file_path).delete_prefix(".").downcase.to_sym
|
|
96
|
+
end
|
|
95
97
|
end
|
|
96
|
-
|
|
98
|
+
end
|
|
97
99
|
end
|
|
@@ -16,7 +16,7 @@ module Rails
|
|
|
16
16
|
if editor.to_s.empty?
|
|
17
17
|
say "No $VISUAL or $EDITOR to open file in. Assign one like this:"
|
|
18
18
|
say ""
|
|
19
|
-
say %(VISUAL="
|
|
19
|
+
say %(VISUAL="code --wait" #{executable(current_subcommand)})
|
|
20
20
|
say ""
|
|
21
21
|
say "For editors that fork and exit immediately, it's important to pass a wait flag;"
|
|
22
22
|
say "otherwise, the file will be saved immediately with no chance to edit."
|
|
@@ -73,21 +73,13 @@ module Rails
|
|
|
73
73
|
skip_rubocop: skip_gem?("rubocop"),
|
|
74
74
|
skip_test: !defined?(Rails::TestUnitRailtie),
|
|
75
75
|
skip_system_test: Rails.application.config.generators.system_tests.nil?,
|
|
76
|
-
asset_pipeline: asset_pipeline,
|
|
77
76
|
skip_asset_pipeline: asset_pipeline.nil?,
|
|
78
77
|
skip_bootsnap: !defined?(Bootsnap),
|
|
79
78
|
}.merge(options)
|
|
80
79
|
end
|
|
81
80
|
|
|
82
81
|
def asset_pipeline
|
|
83
|
-
|
|
84
|
-
when defined?(Sprockets::Railtie)
|
|
85
|
-
"sprockets"
|
|
86
|
-
when defined?(Propshaft::Railtie)
|
|
87
|
-
"propshaft"
|
|
88
|
-
else
|
|
89
|
-
nil
|
|
90
|
-
end
|
|
82
|
+
"propshaft" if defined?(Propshaft::Railtie)
|
|
91
83
|
end
|
|
92
84
|
|
|
93
85
|
def skip_gem?(gem_name)
|
|
@@ -51,10 +51,13 @@ module Rails
|
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
class
|
|
54
|
+
class Reloader < IRB::Command::Base
|
|
55
|
+
include ConsoleMethods
|
|
56
|
+
|
|
57
|
+
category "Rails console"
|
|
55
58
|
description "Reloads the Rails application."
|
|
56
59
|
|
|
57
|
-
def execute
|
|
60
|
+
def execute(*)
|
|
58
61
|
puts "Reloading..."
|
|
59
62
|
Rails.application.reloader.reload!
|
|
60
63
|
end
|
|
@@ -64,7 +67,7 @@ module Rails
|
|
|
64
67
|
IRB::HelperMethod.register(:controller, ControllerInstance)
|
|
65
68
|
IRB::HelperMethod.register(:new_session, NewSession)
|
|
66
69
|
IRB::HelperMethod.register(:app, AppInstance)
|
|
67
|
-
IRB::
|
|
70
|
+
IRB::Command.register(:reload!, Reloader)
|
|
68
71
|
|
|
69
72
|
class IRBConsole
|
|
70
73
|
def initialize(app)
|
|
@@ -38,8 +38,8 @@ Set up Git to Diff Credentials:
|
|
|
38
38
|
Running the command enrolls the project such that all credentials files use the
|
|
39
39
|
"rails_credentials" diff driver in .gitattributes.
|
|
40
40
|
|
|
41
|
-
Additionally since Git requires the driver itself to be set up in a config file
|
|
42
|
-
that isn't tracked Rails automatically ensures it's configured when running
|
|
41
|
+
Additionally, since Git requires the driver itself to be set up in a config file
|
|
42
|
+
that isn't tracked, Rails automatically ensures it's configured when running
|
|
43
43
|
`<%= executable(:edit) %>`.
|
|
44
44
|
|
|
45
45
|
Otherwise each co-worker would have to run enable manually, including on each new
|
|
@@ -48,8 +48,8 @@ Set up Git to Diff Credentials:
|
|
|
48
48
|
To disenroll from this feature, run `<%= executable(:diff) %> --disenroll`.
|
|
49
49
|
|
|
50
50
|
Editing Credentials:
|
|
51
|
-
|
|
52
|
-
contents to edit the encrypted credentials.
|
|
51
|
+
`<%= executable(:edit) %>` will open a temporary file in `$VISUAL` or `$EDITOR`
|
|
52
|
+
with the decrypted contents to edit the encrypted credentials.
|
|
53
53
|
|
|
54
54
|
When the temporary file is next saved the contents are encrypted and written to
|
|
55
55
|
`config/credentials.yml.enc` while the file itself is destroyed to prevent credentials
|
|
@@ -128,7 +128,11 @@ module Rails
|
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
def extract_environment_from_path(path)
|
|
131
|
-
available_environments.find { |env| path.end_with?("#{env}.yml.enc") }
|
|
131
|
+
available_environments.find { |env| path.end_with?("#{env}.yml.enc") } || extract_custom_environment(path)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def extract_custom_environment(path)
|
|
135
|
+
path =~ %r{config/credentials/(.+)\.yml\.enc} && $1
|
|
132
136
|
end
|
|
133
137
|
end
|
|
134
138
|
end
|
|
@@ -5,7 +5,7 @@ require "rails/dev_caching"
|
|
|
5
5
|
module Rails
|
|
6
6
|
module Command
|
|
7
7
|
class DevCommand < Base # :nodoc:
|
|
8
|
-
desc "cache", "Toggle development mode caching on/off"
|
|
8
|
+
desc "cache", "Toggle Action Controller development mode caching on/off"
|
|
9
9
|
def cache
|
|
10
10
|
Rails::DevCaching.enable_by_file
|
|
11
11
|
end
|
|
@@ -24,7 +24,7 @@ module Rails
|
|
|
24
24
|
app_name: Rails.application.railtie_name.chomp("_application"),
|
|
25
25
|
database: !!defined?(ActiveRecord) && database,
|
|
26
26
|
active_storage: !!defined?(ActiveStorage),
|
|
27
|
-
redis: !!(defined?(ActionCable) || defined?(ActiveJob)),
|
|
27
|
+
redis: !!((defined?(ActionCable) && !defined?(SolidCable)) || (defined?(ActiveJob) && !defined?(SolidQueue))),
|
|
28
28
|
system_test: File.exist?("test/application_system_test_case.rb"),
|
|
29
29
|
node: File.exist?(".node-version"),
|
|
30
30
|
}
|