Class/Module Index [+]

Quicksearch

Polyglot

Public Class Methods

find(file, *options, &block) click to toggle source
# File lib/polyglot.rb, line 14
def self.find(file, *options, &block)
  extensions = @registrations.keys*","
  is_absolute = file[0] == File::SEPARATOR || file[0] == File::ALT_SEPARATOR || file =~ /\A[A-Z]:\\/
  (is_absolute ? [""] : $:).each{|lib|
    base = is_absolute ? "" : lib+File::SEPARATOR
    # In Windows, repeated SEPARATOR chars have a special meaning, avoid adding them
    matches = Dir[base+file+".{"+extensions+"}"]
    # Revisit: Should we do more do if more than one candidate found?
    $stderr.puts "Polyglot: found more than one candidate for #{file}: #{matches*", "}" if matches.size > 1
    if path = matches[0]
      return [ path, @registrations[path.gsub(/.*\./,'')]]
    end
  }
  return nil
end
load(*a, &b) click to toggle source
# File lib/polyglot.rb, line 30
def self.load(*a, &b)
  file = a[0].to_str
  return if @loaded[file] # Check for $: changes or file time changes and reload?
  begin
    source_file, loader = Polyglot.find(file, *a[1..-1], &b)
    if (loader)
      loader.load(source_file)
      @loaded[file] = true
    else
      msg = "Failed to load #{file} using extensions #{(@registrations.keys+["rb"]).sort*", "}"
      if defined?(MissingSourceFile)
        raise MissingSourceFile.new(msg, file)
      else
        raise LoadError.new(msg)
      end
    end
  end
end
register(extension, klass) click to toggle source
# File lib/polyglot.rb, line 7
def self.register(extension, klass)
  extension = [extension] unless Enumerable === extension
  extension.each{|e|
    @registrations[e] = klass
  }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.