railbow 0.1.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.
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defer prepend until CodeStatistics is available.
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
12
+
13
+ begin
14
+ require "rails/code_statistics"
15
+ klass = Rails::CodeStatistics
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
28
+
29
+ if klass
30
+ require_relative "../stats_formatter"
31
+ klass.prepend(Railbow::StatsFormatter)
32
+ end
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)
38
+ desc "Report code statistics (lines / LOC / classes / methods / M/C / LOC/M)"
39
+ task stats: :environment do
40
+ klass = if defined?(Rails::CodeStatistics)
41
+ Rails::CodeStatistics
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)] }
81
+ .select { |_, dir| File.directory?(dir) }
82
+
83
+ puts klass.new(*pairs)
84
+ end
85
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "unicode/display_width"
4
+
5
+ module Railbow
6
+ module TextUtils
7
+ def strip_ansi(str)
8
+ str.to_s.gsub(/\e\[[0-9;]*m/, "")
9
+ end
10
+
11
+ def display_width(str)
12
+ Unicode::DisplayWidth.of(str.to_s)
13
+ end
14
+
15
+ def truncate_str(str, max_width)
16
+ return str if display_width(strip_ansi(str)) <= max_width
17
+
18
+ plain = strip_ansi(str)
19
+ truncated = +""
20
+ width = 0
21
+ plain.each_char do |ch|
22
+ ch_width = display_width(ch)
23
+ break if width + ch_width > max_width - 3
24
+ truncated << ch
25
+ width += ch_width
26
+ end
27
+ "#{truncated}..."
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Railbow
4
+ VERSION = "0.1.0"
5
+ end
data/lib/railbow.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "railbow/version"
4
+ require_relative "railbow/params"
5
+ require_relative "railbow/config"
6
+
7
+ module Railbow
8
+ class Error < StandardError; end
9
+
10
+ # Returns true when Railbow formatting should be disabled.
11
+ # Checks for explicit opt-out, standard conventions, CI, and LLM agents.
12
+ def self.plain?
13
+ return true if Params.plain?
14
+ return true if ENV.key?("NO_COLOR")
15
+ return true if ENV.key?("CLAUDECODE")
16
+ return true if ENV.key?("CI")
17
+ !$stdout.tty?
18
+ end
19
+ end
20
+
21
+ # Load Railtie if Rails is available
22
+ require_relative "railbow/railtie" if defined?(Rails::Railtie)
data/sig/railbow.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Railbow
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railbow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eugene M
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: railties
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '7.2'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '8.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '7.2'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '8.2'
32
+ - !ruby/object:Gem::Dependency
33
+ name: activerecord
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '7.2'
39
+ - - "<"
40
+ - !ruby/object:Gem::Version
41
+ version: '8.2'
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '7.2'
49
+ - - "<"
50
+ - !ruby/object:Gem::Version
51
+ version: '8.2'
52
+ - !ruby/object:Gem::Dependency
53
+ name: unicode-display_width
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "~>"
57
+ - !ruby/object:Gem::Version
58
+ version: '3.0'
59
+ type: :runtime
60
+ prerelease: false
61
+ version_requirements: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - "~>"
64
+ - !ruby/object:Gem::Version
65
+ version: '3.0'
66
+ description: Railbow makes Rails database migrations beautiful with colorful output,
67
+ emojis, and readable millisecond timing
68
+ email:
69
+ - eugene@amberpixels.io
70
+ executables:
71
+ - railbow
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - CHANGELOG.md
76
+ - LICENSE.txt
77
+ - README.md
78
+ - exe/railbow
79
+ - lib/railbow.rb
80
+ - lib/railbow/about_formatter.rb
81
+ - lib/railbow/color_assigner.rb
82
+ - lib/railbow/config.rb
83
+ - lib/railbow/demo/fixtures.rb
84
+ - lib/railbow/demo/migrate_demo.rb
85
+ - lib/railbow/demo/routes_demo.rb
86
+ - lib/railbow/demo/runner.rb
87
+ - lib/railbow/demo/status_demo.rb
88
+ - lib/railbow/formatters/base.rb
89
+ - lib/railbow/git_utils.rb
90
+ - lib/railbow/init.rb
91
+ - lib/railbow/logo.rb
92
+ - lib/railbow/migration_formatter.rb
93
+ - lib/railbow/migration_parser.rb
94
+ - lib/railbow/name_collision_resolver.rb
95
+ - lib/railbow/name_formatter.rb
96
+ - lib/railbow/notes_formatter.rb
97
+ - lib/railbow/params.rb
98
+ - lib/railbow/railtie.rb
99
+ - lib/railbow/routes_formatter.rb
100
+ - lib/railbow/stats_formatter.rb
101
+ - lib/railbow/table.rb
102
+ - lib/railbow/table/column.rb
103
+ - lib/railbow/table/renderer.rb
104
+ - lib/railbow/table/theme.rb
105
+ - lib/railbow/tasks/init.rake
106
+ - lib/railbow/tasks/migrate_status.rake
107
+ - lib/railbow/tasks/stats.rake
108
+ - lib/railbow/text_utils.rb
109
+ - lib/railbow/version.rb
110
+ - sig/railbow.rbs
111
+ homepage: https://github.com/amberpixels/railbow
112
+ licenses:
113
+ - MIT
114
+ metadata:
115
+ homepage_uri: https://github.com/amberpixels/railbow
116
+ source_code_uri: https://github.com/amberpixels/railbow
117
+ changelog_uri: https://github.com/amberpixels/railbow/blob/main/CHANGELOG.md
118
+ bug_tracker_uri: https://github.com/amberpixels/railbow/issues
119
+ rubygems_mfa_required: 'true'
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: 3.1.0
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubygems_version: 4.0.15
135
+ specification_version: 4
136
+ summary: Enhance Rails migration output with modern, colorful, emoji-enhanced formatting
137
+ test_files: []