hiiro 0.1.209 → 0.1.210
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 +4 -4
- data/lib/hiiro/paths.rb +12 -0
- data/lib/hiiro/queue.rb +3 -15
- data/lib/hiiro/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8bb0410e3c7b02885dd6c0e2ad692834b52c19a41d6e6935d4cc3a15574e4460
|
|
4
|
+
data.tar.gz: ec424dbbde43665abeefd6164007334dc8808a1b3fd358af0dc668fc23ee6b2a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2bf821ac1bec7d9eacb5018b5f744f2359b63406ce9307fb3c56b430382a300cf812a35a0616a62f3aaf488827f5d12a105bef6714da43fdf9c9e55bccfade50
|
|
7
|
+
data.tar.gz: 03baa5ce95977737c09ea7a98baecfb9bdd099c3caa5251cec2188a896cb80abb2e44b431a1cd15e024ddf736fe240f698d44e40c8f1b14730282bfbd44e9b3c
|
data/lib/hiiro/paths.rb
CHANGED
|
@@ -25,6 +25,18 @@ class Hiiro
|
|
|
25
25
|
.map { |link| Symlink.new(link, hiiro) }
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
# Returns [full_path, unique_name] — appends -2, -3, etc. if a file
|
|
29
|
+
# with the same base_name already exists in dir.
|
|
30
|
+
def self.unique_path(dir, base_name, ext: '.md')
|
|
31
|
+
name = base_name
|
|
32
|
+
counter = 1
|
|
33
|
+
while File.exist?(File.join(dir, "#{name}#{ext}"))
|
|
34
|
+
counter += 1
|
|
35
|
+
name = "#{base_name}-#{counter}"
|
|
36
|
+
end
|
|
37
|
+
[File.join(dir, "#{name}#{ext}"), name]
|
|
38
|
+
end
|
|
39
|
+
|
|
28
40
|
class Symlink < SimpleDelegator
|
|
29
41
|
attr_reader :hiiro
|
|
30
42
|
|
data/lib/hiiro/queue.rb
CHANGED
|
@@ -289,18 +289,6 @@ class Hiiro
|
|
|
289
289
|
text.downcase.gsub(/[^a-z0-9]+/, '-').gsub(/^-|-$/, '')[0, 60]
|
|
290
290
|
end
|
|
291
291
|
|
|
292
|
-
# Returns [dest_path, unique_name] — appends -2, -3, etc. if a file
|
|
293
|
-
# with the same base_name already exists in dest_dir.
|
|
294
|
-
def unique_dest_path(dest_dir, base_name)
|
|
295
|
-
name = base_name
|
|
296
|
-
counter = 1
|
|
297
|
-
while File.exist?(File.join(dest_dir, "#{name}.md"))
|
|
298
|
-
counter += 1
|
|
299
|
-
name = "#{base_name}-#{counter}"
|
|
300
|
-
end
|
|
301
|
-
[File.join(dest_dir, "#{name}.md"), name]
|
|
302
|
-
end
|
|
303
|
-
|
|
304
292
|
def add_with_frontmatter(content, task_info: nil)
|
|
305
293
|
queue_dirs # ensure dirs exist
|
|
306
294
|
|
|
@@ -323,7 +311,7 @@ class Hiiro
|
|
|
323
311
|
name += '-' + task_info[:task_name] if task_info&.key?(:task_name)
|
|
324
312
|
end
|
|
325
313
|
|
|
326
|
-
path, name =
|
|
314
|
+
path, name = Hiiro::Paths.unique_path(queue_dirs[:pending], name)
|
|
327
315
|
File.write(path, content + "\n")
|
|
328
316
|
{ name: name, path: path }
|
|
329
317
|
end
|
|
@@ -584,7 +572,7 @@ class Hiiro
|
|
|
584
572
|
next
|
|
585
573
|
end
|
|
586
574
|
|
|
587
|
-
dst, dest_name =
|
|
575
|
+
dst, dest_name = Hiiro::Paths.unique_path(q.queue_dirs[:pending], name)
|
|
588
576
|
if dest_name != name
|
|
589
577
|
FileUtils.mv(src, File.join(q.queue_dirs[:wip], "#{dest_name}.md"))
|
|
590
578
|
src = File.join(q.queue_dirs[:wip], "#{dest_name}.md")
|
|
@@ -640,7 +628,7 @@ class Hiiro
|
|
|
640
628
|
|
|
641
629
|
dirs = q.queue_dirs
|
|
642
630
|
src_dir = dirs[found[:status].to_sym]
|
|
643
|
-
dst, dest_name =
|
|
631
|
+
dst, dest_name = Hiiro::Paths.unique_path(dirs[:pending], name)
|
|
644
632
|
FileUtils.mv(File.join(src_dir, "#{name}.md"), dst)
|
|
645
633
|
meta_path = File.join(src_dir, "#{name}.meta")
|
|
646
634
|
FileUtils.rm_f(meta_path) if File.exist?(meta_path)
|
data/lib/hiiro/version.rb
CHANGED