module Alloader

Constants

VERSION

Public Class Methods

load_dir(dirpath) click to toggle source
# File lib/alloader.rb, line 7
def load_dir(dirpath)
  load_filepaths(filepaths_in_dir(dirpath))
end
require_dir(dirpath) click to toggle source
# File lib/alloader.rb, line 11
def require_dir(dirpath)
  require_filepaths(filepaths_in_dir(dirpath))
end

Private Class Methods

filepaths_in_dir(dirpath) click to toggle source
# File lib/alloader.rb, line 23
def filepaths_in_dir(dirpath)
  filelist = (Dir::entries(dirpath) - [".", ".."]).map { |file|
    File::expand_path(dirpath + "/" + file)
  }
  dirpaths = filter(method(:is_dir), filelist)
  filepaths_in_dirpaths = dirpaths.inject([]) { |acc, dirpath|
    acc + filepaths_in_dir(dirpath)
  }

  filelist - dirpaths + filepaths_in_dirpaths
end
filter(pred, lst) click to toggle source

# File lib/alloader.rb, line 53
def filter(pred, lst)
  lst.select { |itm| pred.(itm) }
end
is_dir(path) click to toggle source

# File lib/alloader.rb, line 19
def is_dir(path)
  FileTest::directory?(path)
end
load_filepaths(filepaths) click to toggle source
# File lib/alloader.rb, line 43
def load_filepaths(filepaths)
  result = {}
  filepaths.each do |filepath|
    result[filepath] = load filepath
  end
  result
end
require_filepaths(filepaths) click to toggle source
# File lib/alloader.rb, line 35
def require_filepaths(filepaths)
  result = {}
  filepaths.each do |filepath|
    result[filepath] = require filepath
  end
  result
end