lowload 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47cc7e9bc1bf7d856e12c1a91d6cd4ab388a973d73bb8fb7d2a8498ea3631cf4
4
- data.tar.gz: '04864e7a3f9ab0644ebf3356095369859eb025f19087892f3c86b5b54bba35ed'
3
+ metadata.gz: 6e6ef1c86c15e9d8f7318a024bfbfac163defc88e21b01269f8f1f32167b70ec
4
+ data.tar.gz: 0d30281fef9813da99ddd0326724af9399bb4c9a68aaf181469599bdf174eefb
5
5
  SHA512:
6
- metadata.gz: 81e0d64d2f3ab72619663d2f6649c8affe284fe106989aad6c98dd5d7d760b5407f28171af96447c241c55e86cd444fef9f7702b748a35bab1dfa77c408c2497
7
- data.tar.gz: fed385baed2a6d64c26051f34d42e24d022a78823cbd128790c4cfa90e82b32a07576edb475e3c89c2942dc9950b267d2311b8fa718b81247bd5e063dfda5e80
6
+ metadata.gz: 12ba3c16d52fdcc5f9a8edea188891456367f9e9d4c7fa73b223dff4130732944edae68339b30fc8361c787293ca6baed0ff7afb439c7b1936756867dcd62768
7
+ data.tar.gz: a1ad316c6b3581df9db76b0281c26da17342847473e819dca73ba8f63ff2a73a7c59edeec6cf8eca00b4b68e9f5606577b3b172ef90fe197325345d304c15c8e
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Lint/UnusedMethodArgument
4
+
3
5
  module LowLoad
4
6
  class Adapter
5
- EXTENSIONS = []
7
+ EXTENSIONS = [].freeze
6
8
 
7
- def metadata(file_path:)
8
- end
9
+ def mapload(file_path:) = nil
9
10
 
10
- def preload(file_path:)
11
- end
11
+ def preload(file_path:) = nil
12
12
 
13
- def evaluate(file_path:, top_level_binding: nil)
14
- end
13
+ def evaluate(file_path:, top_level_binding: nil) = nil
15
14
  end
16
15
  end
16
+
17
+ # rubocop:enable Lint/UnusedMethodArgument
@@ -6,22 +6,6 @@ require_relative 'adapter'
6
6
 
7
7
  module LowLoad
8
8
  class MarkdownAdapter < Adapter
9
- EXTENSIONS = ['md', 'rd', 'markdown', 'raindown']
10
-
11
- def metadata(file_path:)
12
- meta_lines = []
13
- yaml_lines = []
14
-
15
- File.foreach(file_path).with_index do |line, index|
16
- if line.strip == '---'
17
- meta_lines << index + 1
18
- break if meta_lines.count > 1
19
- else
20
- yaml_lines << line
21
- end
22
- end
23
-
24
- YAML.safe_load(yaml_lines.join, symbolize_names: true)
25
- end
9
+ EXTENSIONS = %w[md rd markdown raindown].freeze
26
10
  end
27
11
  end
@@ -10,13 +10,11 @@ end
10
10
 
11
11
  module LowLoad
12
12
  class RBXAdapter < Adapter
13
- EXTENSIONS = ['rbx']
13
+ EXTENSIONS = ['rbx'].freeze
14
14
 
15
15
  # Map all definitions and dependencies.
16
- def metadata(file_path:)
16
+ def mapload(file_path:)
17
17
  Lowkey.load(file_path)
18
-
19
- { file_path: }
20
18
  end
21
19
 
22
20
  # Then autoload all dependencies for those files.
@@ -35,7 +33,7 @@ module LowLoad
35
33
  eval(file_proxy.export, top_level_binding, file_proxy.file_path, 0) # rubocop:disable Security/Eval
36
34
 
37
35
  # 3. "Runtime" phase (before low nodes are rendered).
38
- # Templates only exist if antlers gem has been required by another gem (such as LowNode) and the template contains antlers syntax.
36
+ # Templates only exist if antlers gem has been required by another gem (like LowNode) and the template contains antlers syntax.
39
37
  templates.each do |namespace, method_template|
40
38
  klass = Object.const_get(namespace)
41
39
  method, template = method_template
@@ -6,13 +6,11 @@ require_relative '../loader'
6
6
 
7
7
  module LowLoad
8
8
  class RubyAdapter < Adapter
9
- EXTENSIONS = ['rb']
9
+ EXTENSIONS = ['rb'].freeze
10
10
 
11
11
  # Map all definitions and dependencies.
12
- def metadata(file_path:)
12
+ def mapload(file_path:)
13
13
  Lowkey.load(file_path)
14
-
15
- { file_path: }
16
14
  end
17
15
 
18
16
  # Then autoload all dependencies for those files.
data/lib/lowload.rb CHANGED
@@ -11,22 +11,32 @@ module LowLoad
11
11
  class UnsupportedTemplate < StandardError; end
12
12
 
13
13
  class << self
14
- ADAPTERS = [MarkdownAdapter.new, RBXAdapter.new, RubyAdapter.new]
14
+ ADAPTERS = [MarkdownAdapter.new, RBXAdapter.new, RubyAdapter.new].freeze
15
15
 
16
- def dirload(path, pwd = Dir.pwd)
16
+ def dirload(path, pwd = Dir.pwd) # rubocop:disable Metrics/AbcSize
17
17
  absolute_path = File.expand_path(path, pwd)
18
18
  file_paths = Dir["#{absolute_path}/**/*"].filter { !File.directory?(it) }
19
19
 
20
- file_path_adapters = file_paths.each_with_object({}) do |file_path, hash|
21
- hash[file_path] = find_adapter(file_path:)
20
+ loaded_paths = {}
21
+ missed_paths = []
22
+ file_types = {}
23
+
24
+ file_paths.each do |file_path|
25
+ if (adapter = find_adapter(file_path:))
26
+ loaded_paths[file_path] = adapter
27
+ else
28
+ missed_paths << adapter
29
+ end
30
+
31
+ file_types[extension(file_path:)] ||= []
32
+ file_types[extension(file_path:)] << file_path
22
33
  end
23
34
 
24
- metadata = Metadata.new
25
- metadata.process(file_path_adapters:)
26
- step(:preload, file_path_adapters:)
27
- step(:evaluate, file_path_adapters:)
35
+ step(:mapload, loaded_paths:)
36
+ step(:preload, loaded_paths:)
37
+ step(:evaluate, loaded_paths:)
28
38
 
29
- metadata
39
+ Metadata.new(loaded_paths:, missed_paths:, file_types:)
30
40
  end
31
41
 
32
42
  def lowload(file_path)
@@ -37,15 +47,20 @@ module LowLoad
37
47
  adapter.evaluate(file_path:)
38
48
  end
39
49
 
40
- def step(step, file_path_adapters:)
41
- file_path_adapters.each do |file_path, adapter|
50
+ private
51
+
52
+ def step(step, loaded_paths:)
53
+ loaded_paths.each do |file_path, adapter|
42
54
  adapter&.send(step, file_path:)
43
55
  end
44
56
  end
45
57
 
46
58
  def find_adapter(file_path:)
47
- extension = File.extname(file_path).delete_prefix('.')
48
- ADAPTERS.find { |adapter| adapter.class::EXTENSIONS.include?(extension) }
59
+ ADAPTERS.find { |adapter| adapter.class::EXTENSIONS.include?(extension(file_path:)) }
60
+ end
61
+
62
+ def extension(file_path:)
63
+ File.extname(file_path).delete_prefix('.')
49
64
  end
50
65
  end
51
66
  end
data/lib/metadata.rb CHANGED
@@ -7,45 +7,15 @@ module LowLoad
7
7
  EXTENSIONS = [
8
8
  *::LowLoad::MarkdownAdapter::EXTENSIONS,
9
9
  *::LowLoad::RBXAdapter::EXTENSIONS,
10
- *::LowLoad::RubyAdapter::EXTENSIONS,
11
- ]
10
+ *::LowLoad::RubyAdapter::EXTENSIONS
11
+ ].freeze
12
12
 
13
- attr_accessor :file_paths, :file_types, :tags
13
+ attr_accessor :loaded_paths, :missed_paths, :file_types
14
14
 
15
- def initialize
16
- @file_paths = []
17
-
18
- @file_types = EXTENSIONS.each_with_object({}) do |extension, hash|
19
- hash[extension] = []
20
- end
21
-
22
- @tags = {}
23
- end
24
-
25
- def process(file_path_adapters:)
26
- file_path_adapters.each do |file_path, adapter|
27
- if (metadata = adapter&.metadata(file_path:))
28
- metadata.merge!({
29
- file_path:,
30
- file_type: File.extname(file_path).delete_prefix('.'),
31
- file_loaded: true,
32
- })
33
- else
34
- metadata = { file_loaded: false }
35
- end
36
-
37
- append(metadata:)
38
- end
39
- end
40
-
41
- def append(metadata:)
42
- @file_paths << metadata[:file_path]
43
- @file_types[metadata[:file_type]] = metadata[:file_path]
44
-
45
- metadata[:tags]&.each do |tag|
46
- @tags[tag] ||= []
47
- @tags[tag] = metadata[:file_path]
48
- end
15
+ def initialize(loaded_paths:, missed_paths:, file_types:)
16
+ @loaded_paths = loaded_paths
17
+ @missed_paths = missed_paths
18
+ @file_types = file_types
49
19
  end
50
20
  end
51
21
  end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LowLoad
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lowload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi