11require "uri"
22
33module BetterErrors
4- module Editor
4+ class Editor
55 KNOWN_EDITORS = [
66 { symbols : [ :atom ] , sniff : /atom/i , url : "atom://core/open/file?filename=%{file}&line=%{line}" } ,
77 { symbols : [ :emacs , :emacsclient ] , sniff : /emacs/i , url : "emacs://open?url=file://%{file}&line=%{line}" } ,
@@ -14,40 +14,14 @@ module Editor
1414 { symbols : [ :vscodium , :codium ] , sniff : /codium/i , url : "vscodium://file/%{file}:%{line}" } ,
1515 ]
1616
17- class UsingFormattingString
18- def initialize ( url_formatting_string )
19- @url_formatting_string = url_formatting_string
20- end
21-
22- def url ( file , line )
23- url_formatting_string % { file : URI . encode_www_form_component ( file ) , file_unencoded : file , line : line }
24- end
25-
26- private
27-
28- attr_reader :url_formatting_string
29- end
30-
31- class UsingProc
32- def initialize ( url_proc )
33- @url_proc = url_proc
34- end
35-
36- def url ( file , line )
37- url_proc . call ( file , line )
38- end
39-
40- private
41-
42- attr_reader :url_proc
43- end
44-
4517 def self . for_formatting_string ( formatting_string )
46- UsingFormattingString . new ( formatting_string )
18+ new proc { |file , line |
19+ formatting_string % { file : URI . encode_www_form_component ( file ) , file_unencoded : file , line : line }
20+ }
4721 end
4822
4923 def self . for_proc ( url_proc )
50- UsingProc . new ( url_proc )
24+ new url_proc
5125 end
5226
5327 def self . for_symbol ( symbol )
@@ -91,5 +65,17 @@ def self.editor_from_environment_formatting_string
9165
9266 for_formatting_string ( ENV [ 'BETTER_ERRORS_EDITOR_URL' ] )
9367 end
68+
69+ def initialize ( url_proc )
70+ @url_proc = url_proc
71+ end
72+
73+ def url ( file , line )
74+ url_proc . call ( file , line )
75+ end
76+
77+ private
78+
79+ attr_reader :url_proc
9480 end
9581end
0 commit comments