railbow 0.6.0 → 0.7.0
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 +78 -0
- data/README.md +40 -16
- data/lib/railbow/about_formatter.rb +57 -21
- data/lib/railbow/calendar.rb +2 -4
- data/lib/railbow/clock.rb +72 -0
- data/lib/railbow/color_assigner.rb +6 -12
- data/lib/railbow/config.rb +1 -1
- data/lib/railbow/demo/fixtures.rb +4 -4
- data/lib/railbow/demo/status_demo.rb +5 -11
- data/lib/railbow/formatters/base.rb +34 -26
- data/lib/railbow/init.rb +6 -2
- data/lib/railbow/migration_formatter.rb +41 -25
- data/lib/railbow/migration_parser.rb +12 -19
- data/lib/railbow/multi_db.rb +15 -1
- data/lib/railbow/name_collision_resolver.rb +14 -27
- data/lib/railbow/name_formatter.rb +15 -16
- data/lib/railbow/notes_formatter.rb +42 -19
- data/lib/railbow/params.rb +33 -27
- data/lib/railbow/railtie.rb +8 -6
- data/lib/railbow/routes_formatter.rb +18 -6
- data/lib/railbow/stats_formatter.rb +139 -69
- data/lib/railbow/status/ghosts.rb +5 -6
- data/lib/railbow/status/git_data.rb +11 -18
- data/lib/railbow/status/help.rb +8 -2
- data/lib/railbow/status/printer.rb +20 -34
- data/lib/railbow/status/section.rb +29 -44
- data/lib/railbow/table/renderer.rb +32 -36
- data/lib/railbow/tasks/migrate_status.rake +33 -17
- data/lib/railbow/tasks/stats.rake +11 -75
- data/lib/railbow/version.rb +1 -1
- data/lib/railbow.rb +28 -4
- metadata +2 -2
|
@@ -1,85 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
# CodeStatistics is autoloaded by Rails when the `stats` task runs,
|
|
5
|
-
# but is not available at rake-file load time.
|
|
6
|
-
#
|
|
7
|
-
# Rails 8.1 namespaced the class to Rails::CodeStatistics, removed
|
|
8
|
-
# the bare `require "code_statistics"` shim, and dropped the built-in
|
|
9
|
-
# `stats` rake task. We handle both old and new layouts.
|
|
10
|
-
Rails.application.config.after_initialize do
|
|
11
|
-
klass = nil
|
|
3
|
+
require_relative "../stats_formatter"
|
|
12
4
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
rescue LoadError
|
|
17
|
-
# fall through
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
unless klass
|
|
21
|
-
begin
|
|
22
|
-
require "code_statistics"
|
|
23
|
-
klass = CodeStatistics
|
|
24
|
-
rescue LoadError
|
|
25
|
-
# code_statistics not available (e.g., production without railties dev deps)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
5
|
+
# Rails 7.2 runs `rails stats` as a rake task that never boots the app, so the
|
|
6
|
+
# railtie initializer does not fire there: install from here as well.
|
|
7
|
+
Railbow::StatsFormatter.install!
|
|
28
8
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# Rails 8.1 removed the built-in `stats` task. Re-define it so that
|
|
36
|
-
# `rails stats` / `rake stats` keeps working with Railbow formatting.
|
|
37
|
-
unless Rake::Task.task_defined?(:stats)
|
|
9
|
+
# Rails 8.1 dropped the `stats` rake task for the `rails stats` command; this
|
|
10
|
+
# keeps `rake stats` working. Gated on the version, not task_defined?: railtie
|
|
11
|
+
# tasks load before Rails' own, so on older Rails both would run.
|
|
12
|
+
if Rails.gem_version >= Gem::Version.new("8.1")
|
|
38
13
|
desc "Report code statistics (lines / LOC / classes / methods / M/C / LOC/M)"
|
|
39
14
|
task stats: :environment do
|
|
40
|
-
|
|
41
|
-
Rails
|
|
42
|
-
elsif defined?(CodeStatistics)
|
|
43
|
-
CodeStatistics
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
unless klass
|
|
47
|
-
abort "CodeStatistics is not available. Make sure railties is loaded."
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
stat_directories = [
|
|
51
|
-
["Controllers", "app/controllers"],
|
|
52
|
-
["Helpers", "app/helpers"],
|
|
53
|
-
["Jobs", "app/jobs"],
|
|
54
|
-
["Models", "app/models"],
|
|
55
|
-
["Mailers", "app/mailers"],
|
|
56
|
-
["Channels", "app/channels"],
|
|
57
|
-
["JavaScripts", "app/javascript"],
|
|
58
|
-
["Libraries", "lib"],
|
|
59
|
-
["APIs", "app/apis"],
|
|
60
|
-
["Controller tests", "test/controllers"],
|
|
61
|
-
["Helper tests", "test/helpers"],
|
|
62
|
-
["Job tests", "test/jobs"],
|
|
63
|
-
["Model tests", "test/models"],
|
|
64
|
-
["Mailer tests", "test/mailers"],
|
|
65
|
-
["Channel tests", "test/channels"],
|
|
66
|
-
["Integration tests", "test/integration"],
|
|
67
|
-
["System tests", "test/system"],
|
|
68
|
-
["Controller specs", "spec/controllers"],
|
|
69
|
-
["Helper specs", "spec/helpers"],
|
|
70
|
-
["Job specs", "spec/jobs"],
|
|
71
|
-
["Model specs", "spec/models"],
|
|
72
|
-
["Mailer specs", "spec/mailers"],
|
|
73
|
-
["Channel specs", "spec/channels"],
|
|
74
|
-
["Request specs", "spec/requests"],
|
|
75
|
-
["System specs", "spec/system"]
|
|
76
|
-
]
|
|
77
|
-
|
|
78
|
-
root = Rails.root.to_s
|
|
79
|
-
pairs = stat_directories
|
|
80
|
-
.map { |name, dir| [name, File.join(root, dir)] }
|
|
15
|
+
stat_directories = Rails::CodeStatistics.directories
|
|
16
|
+
.map { |name, dir| [name, Rails.root.join(dir)] }
|
|
81
17
|
.select { |_, dir| File.directory?(dir) }
|
|
82
18
|
|
|
83
|
-
|
|
19
|
+
Rails::CodeStatistics.new(*stat_directories).to_s
|
|
84
20
|
end
|
|
85
21
|
end
|
data/lib/railbow/version.rb
CHANGED
data/lib/railbow.rb
CHANGED
|
@@ -7,10 +7,10 @@ require_relative "railbow/config"
|
|
|
7
7
|
module Railbow
|
|
8
8
|
class Error < StandardError; end
|
|
9
9
|
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
# RBW_PLAIN always wins; RBW_FORCE beats every auto-detection below it.
|
|
10
|
+
# True when railbow should leave the stock Rails output alone. RBW_PLAIN
|
|
11
|
+
# always wins; RBW_FORCE beats every auto-detection below it.
|
|
13
12
|
def self.plain?
|
|
13
|
+
return true if failure
|
|
14
14
|
return true if Params.plain?
|
|
15
15
|
return false if Params.force?
|
|
16
16
|
return true if ENV.key?("NO_COLOR")
|
|
@@ -18,7 +18,31 @@ module Railbow
|
|
|
18
18
|
return true if ENV.key?("CI")
|
|
19
19
|
!$stdout.tty?
|
|
20
20
|
end
|
|
21
|
+
|
|
22
|
+
class << self
|
|
23
|
+
# The first error railbow's own rendering raised in this process. Once set,
|
|
24
|
+
# railbow stays plain so a broken formatter cannot fail twice.
|
|
25
|
+
attr_accessor :failure
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# A railbow bug must never break the Rails command it decorates: an error
|
|
29
|
+
# falls back to the stock output and switches railbow off for the process.
|
|
30
|
+
# Errors Rails raises inside the fallback still propagate.
|
|
31
|
+
def self.guard(fallback)
|
|
32
|
+
yield
|
|
33
|
+
rescue => e
|
|
34
|
+
record_failure(e)
|
|
35
|
+
fallback.call
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.record_failure(error)
|
|
39
|
+
return if failure
|
|
40
|
+
|
|
41
|
+
self.failure = error
|
|
42
|
+
frame = error.backtrace_locations&.find { |l| l.path.to_s.include?("/railbow/") }
|
|
43
|
+
where = frame ? " at #{frame.path[%r{lib/railbow/.*}] || frame.path}:#{frame.lineno}" : ""
|
|
44
|
+
warn "railbow: #{error.class}: #{error.message}#{where}; showing the default Rails output instead"
|
|
45
|
+
end
|
|
21
46
|
end
|
|
22
47
|
|
|
23
|
-
# Load Railtie if Rails is available
|
|
24
48
|
require_relative "railbow/railtie" if defined?(Rails::Railtie)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: railbow
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eugene M
|
|
@@ -79,6 +79,7 @@ files:
|
|
|
79
79
|
- lib/railbow.rb
|
|
80
80
|
- lib/railbow/about_formatter.rb
|
|
81
81
|
- lib/railbow/calendar.rb
|
|
82
|
+
- lib/railbow/clock.rb
|
|
82
83
|
- lib/railbow/color_assigner.rb
|
|
83
84
|
- lib/railbow/config.rb
|
|
84
85
|
- lib/railbow/demo/fixtures.rb
|
|
@@ -119,7 +120,6 @@ homepage: https://github.com/amberpixels/railbow
|
|
|
119
120
|
licenses:
|
|
120
121
|
- MIT
|
|
121
122
|
metadata:
|
|
122
|
-
homepage_uri: https://github.com/amberpixels/railbow
|
|
123
123
|
source_code_uri: https://github.com/amberpixels/railbow
|
|
124
124
|
changelog_uri: https://github.com/amberpixels/railbow/blob/main/CHANGELOG.md
|
|
125
125
|
bug_tracker_uri: https://github.com/amberpixels/railbow/issues
|