Module: LowLoad

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

Overview

rubocop:disable Lint/UnusedMethodArgument

Defined Under Namespace

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

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

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

rubocop:disable Metrics/AbcSize



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lowload.rb', line 16

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

  loaded_paths = {}
  missed_paths = []
  file_types = {}

  file_paths.each do |file_path|
    if (adapter = find_adapter(file_path:))
      loaded_paths[file_path] = adapter
    else
      missed_paths << adapter
    end

    file_types[extension(file_path:)] ||= []
    file_types[extension(file_path:)] << file_path
  end

  step(:mapload, loaded_paths:)
  step(:preload, loaded_paths:)
  step(:evaluate, loaded_paths:)

  Metadata.new(loaded_paths:, missed_paths:, file_types:)
end

.lowload(file_path) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/lowload.rb', line 42

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

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

  adapter.evaluate(file_path:)
end