Module: MissingHandler

Included in:
Object
Defined in:
lib/droiuby/support/autoload.rb

Instance Method Summary collapse

Instance Method Details

#const_missing(name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/droiuby/support/autoload.rb', line 4

def const_missing(name)
  @looked_for ||= {}
  str_name = name.to_s
  raise "Class not found: #{name}" if @looked_for[str_name] == :missing


  name_parts = name.to_s.split('::').collect { |n| n.underscore }


  $autoload_path.each do |path|
    path_array = unless path.nil?
      [path] + name_parts
    else
      name_parts
    end
    require_path = File.join(*path_array)

    begin
      puts "require #{require_path}"
      require require_path
      klass = const_get(name)
      return klass if klass
    rescue LoadError=>e
    end

  end

  @looked_for[str_name] = :missing

  raise "Class not found: #{name}"
end