Module: LowLoad

Defined in:
lib/loader.rb,
lib/lowload.rb,
lib/version.rb

Defined Under Namespace

Classes: Loader

Constant Summary collapse

VERSION =
'0.4.0'

Class Method Summary collapse

Class Method Details

.dirload(path, pwd = Dir.pwd) ⇒ Object

Files are mapped, autoloaded, then loaded into Ruby in 3 separate stages.



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

def dirload(path, pwd = Dir.pwd)
  absolute_path = File.expand_path(path, pwd)
  file_paths = Dir["#{absolute_path}/**/*"]

  # Map all definitions and dependencies first.
  file_paths.each do |file_path|
    Lowkey.load(file_path)
  end

  # Then autoload all dependencies for those files.
  file_paths.each do |file_path| # rubocop:disable Style/CombinableLoops
    Loader.add_autoloads(file_proxy: Lowkey[file_path])
  end

  # Now we can load the files into Ruby.
  file_paths.each do |file_path| # rubocop:disable Style/CombinableLoops
    lowload(file_path)
  end
end

.lowload(file_path) ⇒ Object

Dependencies must first be loaded by dirload() or required by the file.



36
37
38
39
40
41
42
43
# File 'lib/lowload.rb', line 36

def lowload(file_path)
  case File.extname(file_path).delete_prefix('.')
  when 'rb'
    load(file_path)
  when 'rbx'
    load_rbx(file_path)
  end
end