1
1
require "uri"
2
2
3
3
module BetterErrors
4
- module Editor
4
+ class Editor
5
5
KNOWN_EDITORS = [
6
6
{ symbols : [ :atom ] , sniff : /atom/i , url : "atom://core/open/file?filename=%{file}&line=%{line}" } ,
7
7
{ symbols : [ :emacs , :emacsclient ] , sniff : /emacs/i , url : "emacs://open?url=file://%{file}&line=%{line}" } ,
@@ -14,40 +14,14 @@ module Editor
14
14
{ symbols : [ :vscodium , :codium ] , sniff : /codium/i , url : "vscodium://file/%{file}:%{line}" } ,
15
15
]
16
16
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
-
45
17
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
+ }
47
21
end
48
22
49
23
def self . for_proc ( url_proc )
50
- UsingProc . new ( url_proc )
24
+ new url_proc
51
25
end
52
26
53
27
def self . for_symbol ( symbol )
@@ -91,5 +65,17 @@ def self.editor_from_environment_formatting_string
91
65
92
66
for_formatting_string ( ENV [ 'BETTER_ERRORS_EDITOR_URL' ] )
93
67
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
94
80
end
95
81
end
0 commit comments