Class: Commons::Lang::ClassLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/commons/lang/class_loader.rb

Class Method Summary collapse

Class Method Details

.get_resource(name) ⇒ Object

Get the absolute path of the given resource name. Resource name is relative path (delimiter: ‘/’)on $LOAD_PATH.

return

the absolute path, or nil if the resource is not found.



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/commons/lang/class_loader.rb', line 60

def self.get_resource(name)
  if name == nil || name == ''
    return nil
  end
  
  file_separator = SystemUtils.file_separator
  name = name.replace_all(/\//, file_separator)
  matched_path = $LOAD_PATH.find {|path|
    FileTest.exist?(path + file_separator + name)
  }
  
  return matched_path == nil ? nil : matched_path + file_separator + name
end

.load(class_name) ⇒ Object

Load the class definition file (feature). Feature guess pattern:

`Commons::Lang::ClassLoader' -> `commons/lang/class_loader'
raise

LoadError if the class definition file is not found.



45
46
47
48
49
50
51
52
53
54
# File 'lib/commons/lang/class_loader.rb', line 45

def self.load(class_name)
  begin
    eval(class_name)
  rescue NameError
    require class_name \
        .replace_all(/([a-z0-9])([A-Z])/, '\\1_\\2') \
        .replace_all(/::/, '/') \
        .downcase
  end
end