Class: Shelltoad::Error
- Inherits:
-
Object
show all
- Defined in:
- lib/shelltoad/error.rb
Constant Summary
collapse
- CACHE =
Runtime cache for http queries
{}
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes, full = false) ⇒ Error
66
67
68
69
|
# File 'lib/shelltoad/error.rb', line 66
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
138
139
140
141
142
143
144
|
# File 'lib/shelltoad/error.rb', line 138
def method_missing(meth, *args, &blk)
if attr = @attributes[meth]
attr
else
super(meth, *args, &blk)
end
end
|
Class Method Details
.all(options = {}) ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/shelltoad/error.rb', line 15
def self.all(options = {})
options[:project_id] ||= Configuration.project_id if Configuration.project_id
CACHE[options] ||= (
(Hoptoad::Error.find(:all, options) || []).map! do |attributes|
self.new(attributes)
end
)
end
|
.magic_find(id) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/shelltoad/error.rb', line 24
def self.magic_find(id)
if !id || id.to_s.empty?
Error.all.each do |error|
output error.to_s
end
output "\n"
id = Readline.readline("Input error id: ", true)
end
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
40
41
42
43
44
45
46
47
|
# File 'lib/shelltoad/error.rb', line 40
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
|
.output(*args) ⇒ Object
54
55
56
|
# File 'lib/shelltoad/error.rb', line 54
def self.output(*args)
Shelltoad.output(*args)
end
|
.simple_finder(id) ⇒ Object
49
50
51
52
|
# File 'lib/shelltoad/error.rb', line 49
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
119
120
121
|
# File 'lib/shelltoad/error.rb', line 119
def [](key)
@attributes[key] || self.data[key]
end
|
#commit! ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/shelltoad/error.rb', line 87
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
71
72
73
|
# File 'lib/shelltoad/error.rb', line 71
def data
@data ||= Hoptoad::Error.find(self.id)
end
|
#id ⇒ Object
111
112
113
|
# File 'lib/shelltoad/error.rb', line 111
def id
@attributes[:id]
end
|
#lines ⇒ Object
75
76
77
|
# File 'lib/shelltoad/error.rb', line 75
def lines
self.data[:backtrace][:line]
end
|
#resolve! ⇒ Object
100
101
102
103
104
|
# File 'lib/shelltoad/error.rb', line 100
def resolve!
return true if self.resolved?
Hoptoad::Error.put(path("xml"), :body => {:group => {:resolved => 1}})
true
end
|
#resolved? ⇒ Boolean
115
116
117
|
# File 'lib/shelltoad/error.rb', line 115
def resolved?
@attributes[:resolved]
end
|
#to_s ⇒ Object
107
108
109
|
# File 'lib/shelltoad/error.rb', line 107
def to_s
"[##{self.id}] #{self.rails_env.first} #{self.error_message} #{self.file}:#{self.line_number}"
end
|
#url(format = nil) ⇒ Object
123
124
125
|
# File 'lib/shelltoad/error.rb', line 123
def url(format = nil)
URI.parse(self.class.base_url.to_s + path(format))
end
|
#view ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/shelltoad/error.rb', line 79
def view
<<-EOI
#{self.url.to_s}
#{self.error_message}
#{self.lines.join("\n")}
EOI
end
|