railbow 0.6.2 → 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.
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
- # Returns true when Railbow formatting should be disabled.
11
- # Checks for explicit opt-out, standard conventions, CI, and LLM agents.
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.6.2
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