Exception: Library::LoadError

Inherits:
LoadError
  • Object
show all
Defined in:
lib/library/errors.rb

Overview

Library LoadError is a subclass of Ruby’s standard LoadError class.

Instance Method Summary collapse

Constructor Details

#initialize(failed_path, library_name = nil) ⇒ LoadError

Setup new LoadError instance.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/library/errors.rb', line 10

def initialize(failed_path, library_name=nil)
  super()

  @failed_path  = failed_path
  @library_name = library_name

  if library_name
    @message = "#{@library_name}:#{@failed_path}"
  else
    @message = failed_path
  end

  clean_backtrace
end

Instance Method Details

#clean_backtraceObject

Take an error and remove any mention of ‘library’ from it’s backtrace. Will leaving the backtrace untouched if $DEBUG is set to true.



36
37
38
39
40
41
# File 'lib/library/errors.rb', line 36

def clean_backtrace
  return if ENV['debug'] || $DEBUG
  bt = backtrace
  bt = bt.reject{ |e| $RUBY_IGNORE_CALLERS.any?{ |re| re =~ e } } if bt
  set_backtrace(bt)
end

#to_sObject

Error message string.



28
29
30
# File 'lib/library/errors.rb', line 28

def to_s
  "LoadError: cannot load such file -- #{@message}"
end