Skip to content

Commit 9fbaa8a

Browse files
committed
Make the formatter mechanism support Ractor
Now the formatter configuration is per Ractor. DefaultFormatter is used if not set. DefaultFormatter#message_for is now a class method to allow sub-Ractors to call the method.
1 parent a76a917 commit 9fbaa8a

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

lib/error_highlight/formatter.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module ErrorHighlight
22
class DefaultFormatter
3-
def message_for(spot)
3+
def self.message_for(spot)
44
# currently only a one-line code snippet is supported
55
if spot[:first_lineno] == spot[:last_lineno]
66
indent = spot[:snippet][0...spot[:first_column]].gsub(/[^\t]/, " ")
@@ -14,12 +14,10 @@ def message_for(spot)
1414
end
1515

1616
def self.formatter
17-
@@formatter
17+
Ractor.current[:__error_highlight_formatter__] || DefaultFormatter
1818
end
1919

2020
def self.formatter=(formatter)
21-
@@formatter = formatter
21+
Ractor.current[:__error_highlight_formatter__] = formatter
2222
end
23-
24-
self.formatter = DefaultFormatter.new
2523
end

test/test_error_highlight.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
class ErrorHighlightTest < Test::Unit::TestCase
77
class DummyFormatter
8-
def message_for(corrections)
8+
def self.message_for(corrections)
99
""
1010
end
1111
end
1212

1313
def setup
1414
if defined?(DidYouMean)
1515
@did_you_mean_old_formatter = DidYouMean.formatter
16-
DidYouMean.formatter = DummyFormatter.new
16+
DidYouMean.formatter = DummyFormatter
1717
end
1818
end
1919

0 commit comments

Comments
 (0)