Class: Shelltoad::Error
- Inherits:
-
Object
show all
- Defined in:
- lib/shelltoad/error.rb
Constant Summary
collapse
- URL =
URI.parse("#{Configuration.secure? ? "https" : "http"}://#{Configuration.account}.hoptoadapp.com:80")
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes, full = false) ⇒ Error
47
48
49
50
|
# File 'lib/shelltoad/error.rb', line 47
def initialize(attributes, full = false)
@attributes = attributes
@data = attributes if full
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
103
104
105
106
107
108
109
|
# File 'lib/shelltoad/error.rb', line 103
def method_missing(meth, *args, &blk)
if attr = @attributes[meth]
attr
else
super(meth, *args, &blk)
end
end
|
Class Method Details
.all(options = {}) ⇒ Object
14
15
16
17
18
19
|
# File 'lib/shelltoad/error.rb', line 14
def self.all(options = {})
options[:project_id] ||= Configuration.project_id if Configuration.project_id
(Hoptoad::Error.find(:all, options) || []).map! do |attributes|
self.new(attributes)
end
end
|
.magic_find(id) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/shelltoad/error.rb', line 21
def self.magic_find(id)
error = id.to_s.size > 5 ? simple_finder(id) : magic_finder(id)
if block_given?
return yield(error)
end
error
end
|
.magic_finder(id) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/shelltoad/error.rb', line 29
def self.magic_finder(id)
1.upto(3) do |page|
self.all(:show_resolved => true, :page => page).each do |error|
return self.new(error) if error.id.to_s =~ /#{id}$/
end
end
raise ErrorNotFound, "Error with id like *#{id} not found among last 90 errors.\n Try input full id."
end
|
.simple_finder(id) ⇒ Object
38
39
40
41
|
# File 'lib/shelltoad/error.rb', line 38
def self.simple_finder(id)
attributes = Hoptoad::Error.find(id) || raise(ErrorNotFound, "Error with id #{id} not found under this account.")
self.new(attributes, true)
end
|
Instance Method Details
#[](key) ⇒ Object
99
100
101
|
# File 'lib/shelltoad/error.rb', line 99
def [](key)
@attributes[key] || self.data[key]
end
|
#commit! ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/shelltoad/error.rb', line 67
def commit!
message = <<-EOI.gsub(/`/, "'")
#{url.to_s}
#{self.error_message}
EOI
output = `git commit -m "#{message}"`
if $?.success?
resolve!
end
output
end
|
#data ⇒ Object
52
53
54
|
# File 'lib/shelltoad/error.rb', line 52
def data
@data ||= Hoptoad::Error.find(self.id)
end
|
#id ⇒ Object
91
92
93
|
# File 'lib/shelltoad/error.rb', line 91
def id
@attributes[:id]
end
|
#lines ⇒ Object
56
57
58
|
# File 'lib/shelltoad/error.rb', line 56
def lines
self.data[:backtrace][:line]
end
|
#resolve! ⇒ Object
80
81
82
83
84
|
# File 'lib/shelltoad/error.rb', line 80
def resolve!
return true if self.resolved?
Hoptoad::Error.put(path("xml"), :body => {:group => {:resolved => 1}})
true
end
|
#resolved? ⇒ Boolean
95
96
97
|
# File 'lib/shelltoad/error.rb', line 95
def resolved?
@attributes[:resolved]
end
|
#to_s ⇒ Object
87
88
89
|
# File 'lib/shelltoad/error.rb', line 87
def to_s
"[##{self.id}] #{self.rails_env.first} #{self.error_message} #{self.file}:#{self.line_number}"
end
|
#view ⇒ Object
60
61
62
63
64
65
|
# File 'lib/shelltoad/error.rb', line 60
def view
<<-EOI
#{self.error_message}
#{self.lines.join("\n")}
EOI
end
|