open_exception 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +18 -4
- data/VERSION +1 -1
- data/lib/open_exception/growl_support.rb +7 -9
- data/lib/open_exception/open_exception.rb +16 -8
- data/open_exception.gemspec +2 -2
- data/spec/open_exception_spec.rb +35 -10
- data/spec/spec_helper.rb +1 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -18,7 +18,21 @@ Out if the box, the gem supports three editors (with the following open commands
|
|
18
18
|
:textmate => '/usr/local/bin/mate -a -d -l {line} {file}',
|
19
19
|
:macvim => '/usr/local/bin/mvim +{line} {file}'
|
20
20
|
|
21
|
-
|
21
|
+
Any of these will open the file and set focus on the editor. `:emacs` is the default.
|
22
|
+
|
23
|
+
If you are using emacs, you can also open the backtrace along with the file using `:emacs_with_trace` as the `:open_with` argument. This uses:
|
24
|
+
/usr/bin/emacsclient -e '(open-trace-and-file "{tracefile}" "{file}" {line})'
|
25
|
+
as the open command. To use this, you will need to add the following function to your emacs init:
|
26
|
+
|
27
|
+
(defun open-trace-and-file (tracefile file linenum)
|
28
|
+
"Open visit TRACEFILE in one window (in compilation mode), and visit FILE at LINENUM in another"
|
29
|
+
(find-file-other-window tracefile)
|
30
|
+
(goto-line 2)
|
31
|
+
(compilation-mode)
|
32
|
+
(find-file-other-window file)
|
33
|
+
(goto-line linenum))
|
34
|
+
|
35
|
+
Note: for `emacsclient` to work, you will need to be running `emacsserver`. To start the server:
|
22
36
|
M-x server-start
|
23
37
|
or add the following to your init:
|
24
38
|
(server-start)
|
@@ -29,9 +43,9 @@ Configuration
|
|
29
43
|
To configure, pass a block to the configure method:
|
30
44
|
|
31
45
|
OpenException.configure do |oe|
|
32
|
-
# open_with can be one of the built in editors (:emacs, :macvim, :textmate)
|
33
|
-
# or a command to execute to open the file, where {file} and {
|
34
|
-
# with the file path
|
46
|
+
# open_with can be one of the built in editors (:emacs, :emacs_with_trace, :macvim, :textmate)
|
47
|
+
# or a command to execute to open the file, where {file}, {line}, and {tracefile} will be replaced
|
48
|
+
# with the file path, line number, and path to tmp file holding the backtrace, respectively. See 'Editors' above for an example.
|
35
49
|
# The default editor is :emacs.
|
36
50
|
|
37
51
|
oe.open_with = :emacs
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -8,24 +8,22 @@ module OpenException
|
|
8
8
|
end
|
9
9
|
|
10
10
|
protected
|
11
|
-
def open_file_with_growl
|
12
|
-
|
13
|
-
|
14
|
-
open_file_without_growl(file, line)
|
11
|
+
def open_file_with_growl
|
12
|
+
growl_notify if File.readable?(file_name)
|
13
|
+
open_file_without_growl
|
15
14
|
end
|
16
15
|
|
17
|
-
def growl_notify
|
16
|
+
def growl_notify
|
18
17
|
if Growl.installed?
|
19
18
|
Growl.notify do |n|
|
20
19
|
n.title = 'Open Exception'
|
21
|
-
n.message = growl_message
|
20
|
+
n.message = growl_message
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
|
-
def growl_message
|
27
|
-
msg = "Exception: #{exception.message} at #{exception.backtrace.first}\nOpening #{
|
28
|
-
msg << " in #{options[:open_with]}" if options[:open_with].is_a?(Symbol)
|
25
|
+
def growl_message
|
26
|
+
msg = "Exception: #{exception.message} at #{exception.backtrace.first}\nOpening #{file_name}:#{line_number}"
|
29
27
|
end
|
30
28
|
end
|
31
29
|
end
|
@@ -1,7 +1,10 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
1
3
|
module OpenException
|
2
4
|
|
3
5
|
EDITOR_COMMANDS = {
|
4
6
|
:emacs => '/usr/bin/emacsclient -n +{line} {file}',
|
7
|
+
:emacs_with_trace => '/usr/bin/emacsclient -e \'(open-trace-and-file "{tracefile}" "{file}" {line})\'',
|
5
8
|
:textmate => '/usr/local/bin/mate -a -d -l {line} {file}',
|
6
9
|
:macvim => '/usr/local/bin/mvim +{line} {file}'
|
7
10
|
}
|
@@ -40,19 +43,17 @@ module OpenException
|
|
40
43
|
end
|
41
44
|
|
42
45
|
def open
|
43
|
-
|
44
|
-
file_and_line = extract_file_and_line
|
45
|
-
open_file(*file_and_line) if file_and_line
|
46
|
-
end
|
46
|
+
extract_file_and_line && open_file unless exclude_exception?
|
47
47
|
end
|
48
48
|
|
49
49
|
protected
|
50
|
-
attr_reader :exception
|
50
|
+
attr_reader :exception, :file_name, :line_number
|
51
51
|
|
52
52
|
def extract_file_and_line
|
53
53
|
if exception.backtrace and
|
54
54
|
filter_backtrace(exception.backtrace) =~ /(.*?):(\d*)/
|
55
|
-
|
55
|
+
@file_name = $1
|
56
|
+
@line_number = $2
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
@@ -92,10 +93,17 @@ module OpenException
|
|
92
93
|
end
|
93
94
|
end
|
94
95
|
|
95
|
-
def open_file
|
96
|
+
def open_file
|
96
97
|
if File.readable?(file_name)
|
97
98
|
cmd = open_command.gsub('{file}', file_name).gsub('{line}', line_number)
|
98
|
-
|
99
|
+
if cmd =~ /\{tracefile\}/
|
100
|
+
Tempfile.open('open_exception-trace') do |f|
|
101
|
+
f << exception.message
|
102
|
+
f << "\n"
|
103
|
+
f << exception.backtrace.join("\n")
|
104
|
+
cmd.gsub!('{tracefile}', f.path)
|
105
|
+
end
|
106
|
+
end
|
99
107
|
system(cmd)
|
100
108
|
end
|
101
109
|
end
|
data/open_exception.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{open_exception}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tobias Crawley"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-05-15}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{tcrawley@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/open_exception_spec.rb
CHANGED
@@ -1,37 +1,45 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
describe "OpenException" do
|
4
5
|
describe "parsing an exception" do
|
5
6
|
it "should extract the file and line number" do
|
6
|
-
opener(stub_exception)
|
7
|
-
|
7
|
+
@opener = opener(stub_exception)
|
8
|
+
@opener.send(:extract_file_and_line)
|
9
|
+
@opener.send(:file_name).should == '/some/file.rb'
|
10
|
+
@opener.send(:line_number).should == '1'
|
8
11
|
end
|
9
12
|
|
10
13
|
it "should filter with a regex" do
|
11
14
|
@opener = opener(stub_exception,
|
12
15
|
:backtrace_line_filters => [/other_file/])
|
13
|
-
@opener.send(:extract_file_and_line)
|
16
|
+
@opener.send(:extract_file_and_line)
|
17
|
+
@opener.send(:file_name).should == "/some/other_file.rb"
|
18
|
+
@opener.send(:line_number).should == '22'
|
14
19
|
end
|
15
20
|
|
16
21
|
it "should filter with a lambda" do
|
17
22
|
@opener = opener(stub_exception,
|
18
23
|
:backtrace_line_filters => [lambda { |line| line =~ /other_file/ }])
|
19
|
-
@opener.send(:extract_file_and_line)
|
24
|
+
@opener.send(:extract_file_and_line)
|
25
|
+
@opener.send(:file_name).should == "/some/other_file.rb"
|
26
|
+
@opener.send(:line_number).should == '22'
|
20
27
|
end
|
21
28
|
|
22
29
|
it "should filter with an array of filters" do
|
23
30
|
@opener = opener(stub_exception,
|
24
31
|
:backtrace_line_filters => [/not gonna match/,
|
25
|
-
|
26
|
-
@opener.send(:extract_file_and_line)
|
32
|
+
/other_file/])
|
33
|
+
@opener.send(:extract_file_and_line)
|
34
|
+
@opener.send(:file_name).should == "/some/other_file.rb"
|
35
|
+
@opener.send(:line_number).should == '22'
|
27
36
|
end
|
28
37
|
end
|
29
38
|
|
30
39
|
describe "opening an exception" do
|
31
|
-
it "should
|
40
|
+
it "should try to open the file" do
|
32
41
|
@opener = opener(stub_exception)
|
33
|
-
@opener.should_receive(:open_file)
|
34
|
-
'1')
|
42
|
+
@opener.should_receive(:open_file)
|
35
43
|
@opener.open
|
36
44
|
end
|
37
45
|
|
@@ -72,12 +80,29 @@ describe "OpenException" do
|
|
72
80
|
it "should not try to open a file that does not exist" do
|
73
81
|
@opener = opener(nil)
|
74
82
|
@opener.should_not_receive(:system)
|
75
|
-
@opener.
|
83
|
+
@opener.file_name = '/a/nonexistent/file'
|
84
|
+
@opener.send(:open_file)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should write out the trace to a file if the open_command contains {tracefile}" do
|
88
|
+
File.stub!(:readable?).and_return(true)
|
89
|
+
@opener = opener(stub_exception)
|
90
|
+
@opener.stub!(:open_command).and_return('{tracefile}')
|
91
|
+
Tempfile.should_receive(:open)
|
92
|
+
@opener.file_name = '/a/file'
|
93
|
+
@opener.line_number = '2'
|
94
|
+
@opener.stub!(:system)
|
95
|
+
@opener.send(:open_file)
|
96
|
+
|
76
97
|
end
|
77
98
|
end
|
78
99
|
end
|
79
100
|
end
|
80
101
|
|
102
|
+
class OpenException::ExceptionOpener
|
103
|
+
attr_writer :file_name, :line_number
|
104
|
+
end
|
105
|
+
|
81
106
|
def opener(ex, options = { })
|
82
107
|
OpenException::ExceptionOpener.new(ex, options)
|
83
108
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
- 2
|
8
7
|
- 3
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Tobias Crawley
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-05-15 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|