Exception: Alphred::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Alphred::Error
- Defined in:
- lib/alphred/error.rb
Constant Summary collapse
- ASSETS =
File.('../../../assets', __FILE__)
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
Class Method Summary collapse
Instance Method Summary collapse
- #backtrace_items ⇒ Object
-
#initialize(error) ⇒ Error
constructor
A new instance of Error.
- #to_items ⇒ Object
- #to_json(options = nil) ⇒ Object
Constructor Details
#initialize(error) ⇒ Error
Returns a new instance of Error.
18 19 20 |
# File 'lib/alphred/error.rb', line 18 def initialize(error) @error = error end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
16 17 18 |
# File 'lib/alphred/error.rb', line 16 def error @error end |
Class Method Details
.try ⇒ Object
10 11 12 13 14 |
# File 'lib/alphred/error.rb', line 10 def self.try yield rescue Exception => e print self.new(e).to_json end |
Instance Method Details
#backtrace_items ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/alphred/error.rb', line 34 def backtrace_items icon = File.join(ASSETS, 'more.png') base_dirs = $LOAD_PATH + [ENV['alfred_preferences']] to_delete = /^#{base_dirs.join(?|)}/ self.error.backtrace.map { |line| title = line.sub(to_delete, '...') Item.new( title: title, subtitle: line, arg: line, icon: icon, ) } end |
#to_items ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/alphred/error.rb', line 26 def to_items icon = File.join(ASSETS, 'close.png') items = [ Alphred::Item.new(title: "#{self.error.class}: #{self.error}", icon: icon) ] items.concat(self.backtrace_items) Items[*items] end |
#to_json(options = nil) ⇒ Object
22 23 24 |
# File 'lib/alphred/error.rb', line 22 def to_json(=nil) to_items.to_json() end |