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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 682986f0fe061c64a51e17710cc46a49e7227980af6765715a0db8e896cee7d2
4
- data.tar.gz: 2bc5edffca82cb8f46e1cec99c5d0d3fefd49f5a6ec9ab7f46a8c810224acdbf
3
+ metadata.gz: 8bb0410e3c7b02885dd6c0e2ad692834b52c19a41d6e6935d4cc3a15574e4460
4
+ data.tar.gz: ec424dbbde43665abeefd6164007334dc8808a1b3fd358af0dc668fc23ee6b2a
5
5
  SHA512:
6
- metadata.gz: 8444324b5e67717a8533e1135bb54612b6ae85e0ae4e616692a6c87e715c22a6a92de79534468eb87de0c386b75fe202ad2b4f6df67c25662b7fac3229d207c3
7
- data.tar.gz: 584c422ce992a137eea834db02bba83450ee8b90bb32d511057fdc55714c9a56a7edc67d6112318803e3d656cd25405306eb6a2190536fef22f795897036f074
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 = unique_dest_path(queue_dirs[:pending], 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 = q.unique_dest_path(q.queue_dirs[:pending], 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 = q.unique_dest_path(dirs[:pending], 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
@@ -1,3 +1,3 @@
1
1
  class Hiiro
2
- VERSION = "0.1.209"
2
+ VERSION = "0.1.210"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiiro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.209
4
+ version: 0.1.210
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Toyota