Module: LowLoad

Defined in:
lib/loader.rb,
lib/lowload.rb,
lib/version.rb,
lib/metadata.rb,
lib/adapters/adapter.rb,
lib/adapters/rbx_adapter.rb,
lib/adapters/ruby_adapter.rb,
lib/adapters/markdown_adapter.rb

Defined Under Namespace

Classes: Adapter, Loader, MarkdownAdapter, Metadata, RBXAdapter, RubyAdapter, UnsupportedFileType, UnsupportedTemplate

Constant Summary collapse

ADAPTERS =
[MarkdownAdapter.new, RBXAdapter.new, RubyAdapter.new]
VERSION =
'0.6.0'

Class Method Summary collapse

Class Method Details

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



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

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

  file_path_adapters = file_paths.each_with_object({}) do |file_path, hash|
    hash[file_path] = find_adapter(file_path:)
  end

   = Metadata.new
  .process(file_path_adapters:)
  step(:preload, file_path_adapters:)
  step(:evaluate, file_path_adapters:)

  
end

.find_adapter(file_path:) ⇒ Object



46
47
48
49
# File 'lib/lowload.rb', line 46

def find_adapter(file_path:)
  extension = File.extname(file_path).delete_prefix('.')
  ADAPTERS.find { |adapter| adapter.class::EXTENSIONS.include?(extension) }
end

.lowload(file_path) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/lowload.rb', line 32

def lowload(file_path)
  adapter = find_adapter(file_path:)

  raise(UnsupportedFileType, "Could not load #{file_path}") if adapter.nil?

  adapter.evaluate(file_path:)
end

.step(step, file_path_adapters:) ⇒ Object



40
41
42
43
44
# File 'lib/lowload.rb', line 40

def step(step, file_path_adapters:)
  file_path_adapters.each do |file_path, adapter|
    adapter&.send(step, file_path:)
  end
end