Module: Timetrap::Helpers::AutoLoad

Included in:
CLI, Timer
Defined in:
lib/timetrap/helpers.rb

Instance Method Summary collapse

Instance Method Details

#auto_load(name, type) ⇒ Object



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

#load_auto_sheet(auto_sheet) ⇒ Object



8
9
10
# File 'lib/timetrap/helpers.rb', line 8

def load_auto_sheet(auto_sheet)
  auto_load(auto_sheet, 'auto_sheet')
end

#load_formatter(formatter) ⇒ Object



4
5
6
# File 'lib/timetrap/helpers.rb', line 4

def load_formatter(formatter)
  auto_load(formatter, 'formatter')
end