Module: VirtualBox::GlobLoader

Defined in:
lib/virtualbox/ext/glob_loader.rb

Overview

Eases the processes of loading specific files then globbing the rest from a specified directory.

Class Method Summary (collapse)

Class Method Details

+ (Object) glob_require(dir, initial_files = [])

Glob requires all ruby files in a directory, optionally loading select files initially (since others may depend on them).

Parameters:

  • dir (String)

    The directory to glob

  • initial_files (Array<String>) (defaults to: [])

    Initial files (relative to `dir`) to load



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/virtualbox/ext/glob_loader.rb', line 13

def self.glob_require(dir, initial_files=[])
  # Note: The paths below both are "downcased" because on Windows, some
  # expand to "c:\" and some expand to "C:\" and cause the same file to
  # be loaded twice. Uck.

  require_files = []
  initial_files.each do |file|
    require_files << File.expand_path(file, dir)
  end

  # Glob require the rest
  Dir[File.join(dir, "**", "*.rb")].each do |f|
    require_files << File.expand_path(f)
  end

  # Iterate over the files to require, manipulating them if necessary
  require_files.each do |file|
    file = file.downcase if Platform.windows?
    require file
  end
end