Glob loader to make glob loading easier

This commit is contained in:
Mitchell Hashimoto 2010-04-25 00:51:45 -07:00
parent ffded418f7
commit 1429723277
2 changed files with 31 additions and 12 deletions

View File

@ -1,19 +1,16 @@
libdir = File.dirname(__FILE__) libdir = File.join(File.dirname(__FILE__), "vagrant")
PROJECT_ROOT = File.join(libdir, '..') unless defined?(PROJECT_ROOT) PROJECT_ROOT = File.join(libdir, '..', "..") unless defined?(PROJECT_ROOT)
# The libs which must be loaded prior to the rest # First, load the various libs which Vagrant requires
%w{tempfile open-uri json pathname logger uri net/http virtualbox net/ssh archive/tar/minitar %w{tempfile open-uri json pathname logger uri net/http virtualbox net/ssh archive/tar/minitar
net/scp fileutils mario}.each do |lib| net/scp fileutils mario}.each do |lib|
require lib require lib
end end
# The vagrant specific files which must be loaded prior to the rest # Then load the glob loader, which will handle loading everything else
%w{vagrant/util vagrant/util/stacked_proc_runner vagrant/util/progress_meter vagrant/actions/base vagrant/downloaders/base vagrant/actions/collection require File.expand_path("util/glob_loader", libdir)
vagrant/actions/runner vagrant/config vagrant/provisioners/base vagrant/provisioners/chef vagrant/commands/base vagrant/commands/box}.each do |f|
require File.expand_path(f, libdir)
end
# Glob require the rest # Load them up
Dir[File.join(libdir, "vagrant", "**", "*.rb")].each do |f| Vagrant::GlobLoader.glob_require(libdir, %w{util util/stacked_proc_runner util/progress_meter
require File.expand_path(f) actions/base downloaders/base actions/collection actions/runner config
end provisioners/base provisioners/chef systems/base commands/base commands/box})

View File

@ -0,0 +1,22 @@
module Vagrant
# Eases the processes of loading specific files then globbing
# the rest from a specified directory.
module GlobLoader
# Glob requires all ruby files in a directory, optionally loading select
# files initially (since others may depend on them).
#
# @param [String] dir The directory to glob
# @param [Array<String>] initial_files Initial files (relative to `dir`)
# to load
def self.glob_require(dir, initial_files=[])
initial_files.each do |file|
require File.expand_path(file, dir)
end
# Glob require the rest
Dir[File.join(dir, "**", "*.rb")].each do |f|
require File.expand_path(f)
end
end
end
end