12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/timetrap/helpers.rb', line 12
def auto_load(name, type)
err_msg = "Can't load #{name.inspect} #{type}."
begin
paths = (
Array(Config["#{type}_search_paths"]) +
[ File.join( File.dirname(__FILE__), type.pluralize) ]
)
if paths.detect do |path|
begin
fp = File.join(path, name)
require File.join(path, name)
true
rescue LoadError
nil
end
end
else
raise LoadError, "Couldn't find #{name}.rb in #{paths.inspect}"
end
namespace = Timetrap.const_get(type.pluralize.camelize)
namespace.const_get(name.camelize)
rescue LoadError, NameError => e
err = e.class.new("#{err_msg} (#{e.message})")
err.set_backtrace(e.backtrace)
raise err
end
end
|