lowload 0.6.0 → 0.6.1

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: e0a6b7db4c15bb23eea273eb0a2d63bfed6d182b03a9964eb4c8adabc947fe93
4
+ data.tar.gz: 4ae8e96140a5f5560204aa7aac365167dd500068e7cef9415ef4b919b8271239
5
5
  SHA512:
6
- metadata.gz: 81e0d64d2f3ab72619663d2f6649c8affe284fe106989aad6c98dd5d7d760b5407f28171af96447c241c55e86cd444fef9f7702b748a35bab1dfa77c408c2497
7
- data.tar.gz: fed385baed2a6d64c26051f34d42e24d022a78823cbd128790c4cfa90e82b32a07576edb475e3c89c2942dc9950b267d2311b8fa718b81247bd5e063dfda5e80
6
+ metadata.gz: 1aee43560dc727fd1093d933805dee8f6fb8f9d466a60c594cd4c6635f007f77830c143d05827efe412b48430705636d556ee8ab554d8973e73e19f04a944df4
7
+ data.tar.gz: 88c59f0e36586302d1457b00926afe013fbdef453815a38b56ef1cf0b15c74edd38d081e6d263403d5f062d0a9b47b44af635da504bebf63709f040f6f0d9570
@@ -4,13 +4,12 @@ module LowLoad
4
4
  class Adapter
5
5
  EXTENSIONS = []
6
6
 
7
- def metadata(file_path:)
8
- end
7
+ def metadata(file_path:) = nil
9
8
 
10
- def preload(file_path:)
11
- end
9
+ def preload(file_path:) = nil
12
10
 
13
- def evaluate(file_path:, top_level_binding: nil)
14
- end
11
+ def evaluate(file_path:, top_level_binding: nil) = nil
12
+
13
+ def url_path(file_path:) = nil
15
14
  end
16
15
  end
@@ -9,19 +9,36 @@ module LowLoad
9
9
  EXTENSIONS = ['md', 'rd', 'markdown', 'raindown']
10
10
 
11
11
  def metadata(file_path:)
12
- meta_lines = []
12
+ line_numbers = []
13
13
  yaml_lines = []
14
14
 
15
15
  File.foreach(file_path).with_index do |line, index|
16
16
  if line.strip == '---'
17
- meta_lines << index + 1
18
- break if meta_lines.count > 1
19
- else
17
+ line_numbers << index + 1
18
+ break if line_numbers.count > 1
19
+ elsif line_numbers.count > 0
20
20
  yaml_lines << line
21
21
  end
22
22
  end
23
23
 
24
+ # TODO: Test that this returns an empty hash when no yaml lines found.
24
25
  YAML.safe_load(yaml_lines.join, symbolize_names: true)
25
26
  end
27
+
28
+ def url_path(file_path:)
29
+ # Remove "_number-" and segments beginning with "_".
30
+ url_path = file_path.split('/').map do |segment|
31
+ next segment.sub(/^_\d\W/, '') if segment.sub(/^_\d\W/, '') != segment
32
+ next nil if segment.sub(/^_/, '') != segment
33
+
34
+ segment
35
+ end.compact.join('/')
36
+
37
+ EXTENSIONS.each do |extension|
38
+ url_path.delete_suffix!(".#{extension}")
39
+ end
40
+
41
+ url_path
42
+ end
26
43
  end
27
44
  end
data/lib/metadata.rb CHANGED
@@ -10,41 +10,35 @@ module LowLoad
10
10
  *::LowLoad::RubyAdapter::EXTENSIONS,
11
11
  ]
12
12
 
13
- attr_accessor :file_paths, :file_types, :tags
13
+ attr_accessor :loaded_paths, :missed_paths, :file_types, :url_paths, :tags
14
14
 
15
15
  def initialize
16
- @file_paths = []
17
-
18
- @file_types = EXTENSIONS.each_with_object({}) do |extension, hash|
19
- hash[extension] = []
20
- end
16
+ @loaded_paths = []
17
+ @missed_paths = []
21
18
 
19
+ @file_types = EXTENSIONS.each_with_object({}) { |extension, hash| hash[extension] = [] }
20
+ @url_paths = {}
22
21
  @tags = {}
23
22
  end
24
-
23
+
25
24
  def process(file_path_adapters:)
26
25
  file_path_adapters.each do |file_path, adapter|
27
26
  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
- })
27
+ append(file_path:, adapter:, metadata:)
33
28
  else
34
- metadata = { file_loaded: false }
29
+ @missed_paths << file_path
35
30
  end
36
-
37
- append(metadata:)
38
31
  end
39
32
  end
40
33
 
41
- def append(metadata:)
42
- @file_paths << metadata[:file_path]
43
- @file_types[metadata[:file_type]] = metadata[:file_path]
34
+ def append(file_path:, adapter:, metadata:)
35
+ @loaded_paths << file_path
36
+ @file_types[File.extname(file_path).delete_prefix('.')] << file_path
37
+ @url_paths[adapter.url_path(file_path:)] = file_path
44
38
 
45
39
  metadata[:tags]&.each do |tag|
46
40
  @tags[tag] ||= []
47
- @tags[tag] = metadata[:file_path]
41
+ @tags[tag] = file_path
48
42
  end
49
43
  end
50
44
  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.1'
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi