pathtree 0.4.0 → 0.4.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: 2fa0b4b00d649556ade2438672e8f579096425641c87dc12904c0b1e83896f4c
4
- data.tar.gz: a20dc412a32816c46688ae0ee426f1ee19d954290d3def13f64d50099a737956
3
+ metadata.gz: 06e46ecc4b58e4553042302669756be661ac48184b80ed5dd54da22dc8697b5f
4
+ data.tar.gz: d73d5937c003469eede446f6e700657b594083a09b5d4f9d886df3ecc3369a48
5
5
  SHA512:
6
- metadata.gz: 19b2cf1822c9380fbd6161ee50b3fd57990811d93331ddd22530982907654b2e6dee118715da9ccd76c5921afd01249a7fa1357b30886cab3f4ce45430f2f53f
7
- data.tar.gz: 01bda1e63a6dcc19803a10857cb581d7457a87329e1c2592cfb355a6f5a4e235e301eea171f22a4fd613afcdaff69a6369433824c5e4595160ceee3660d6fd94
6
+ metadata.gz: 9b2c4e1e4f15378a564e3db49d93b77126d55900a913435b74e71206195153f723785369f800d107a3c3bb3d4966a0a44c47c9d5a18322a48886d9e8413a7294
7
+ data.tar.gz: d76946784f32750357ab5bbe6145f114b5207c6204fdd3f2663c2d7da5d322aa25d5e3047fc0a514d1749e33164f30323dd4564f3c2a3953366215ab3c31de8f
data/CHANGELOG.md CHANGED
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ### Fixed in 0.4.1
11
+
12
+ * It is now possible to define identically named paths in different hierarchies.
13
+ In 0.4.0, duplicate names caused an exception.
14
+
15
+ ```ruby
16
+ directory :aaa do
17
+ file :xxx
18
+
19
+ directory :bbb do
20
+ file :xxx # OK
21
+ end
22
+ end
23
+ ```
24
+
10
25
  ## 0.4.0 - 2022-05-14
11
26
 
12
27
  ### Changed in 0.4.0
data/lib/pathtree/dsl.rb CHANGED
@@ -16,10 +16,8 @@ module Pathtree
16
16
  # * Otherwise, +path+ itself is used.
17
17
  def file(name, path = nil)
18
18
  check_name(name)
19
- path = normalize(name: name, path: path)
20
- path = @root / path if @root
21
- @names << name
22
- define_singleton_method(name) { path }
19
+ path = normalize(path, name: name).then { nest(_1) }
20
+ sprout(name: name, path: path)
23
21
  end
24
22
 
25
23
  # Grows directory branch from the branch.
@@ -27,23 +25,16 @@ module Pathtree
27
25
  # This method has optional block, which represents nested file structure.
28
26
  def directory(name, path = nil, &block)
29
27
  check_name(name)
30
- path = normalize(name: name, path: path)
31
- path = @root / path if @root
32
- @names << name
33
-
34
- define_singleton_method(name) do
35
- path.tap do |p|
36
- Dsl.extend(p, root: path)
37
- p.instance_eval(&block) if block
38
- end
39
- end
28
+ path = normalize(path, name: name).then { nest(_1) }
29
+ .then { Dsl.extend(_1) }
30
+ .tap { _1.instance_eval(&block) if block }
31
+ sprout(name: name, path: path)
40
32
  end
41
33
 
42
34
  alias dir directory
43
35
 
44
- def self.extend(path, root: nil)
36
+ def self.extend(path)
45
37
  path.instance_variable_set(:@names, [])
46
- path.instance_variable_set(:@root, root)
47
38
  path.extend(Dsl)
48
39
  path
49
40
  end
@@ -54,16 +45,23 @@ module Pathtree
54
45
  raise MethodDuplicationError, name if respond_to?(name)
55
46
  end
56
47
 
57
- def normalize(name:, path: nil)
48
+ def normalize(path, name:)
58
49
  if path.nil?
59
50
  Pathname(name.to_s)
60
51
  elsif path.is_a?(String)
61
52
  Pathname(path)
62
53
  elsif path.respond_to?(:call)
63
- path.call(name).then { normalize(name: _1) }
54
+ path.call(name).to_s.then { Pathname(_1) }
64
55
  else
65
56
  path
66
57
  end
67
58
  end
59
+
60
+ def nest(path) = is_a?(Trunk) ? path : self / path
61
+
62
+ def sprout(name:, path:)
63
+ define_singleton_method(name) { path }
64
+ @names << name
65
+ end
68
66
  end
69
67
  end
@@ -10,7 +10,6 @@ module Pathtree
10
10
 
11
11
  def initialize
12
12
  @names = []
13
- @root = nil
14
13
  end
15
14
  end
16
15
  end
@@ -3,5 +3,5 @@
3
3
  require 'pathname'
4
4
 
5
5
  module Pathtree
6
- VERSION = '0.4.0'
6
+ VERSION = '0.4.1'
7
7
  end
data/lib/pathtree.rb CHANGED
@@ -25,7 +25,7 @@ module Pathtree
25
25
 
26
26
  def to_path(value)
27
27
  value = Pathname(value) if value.is_a?(String)
28
- Dsl.extend(value, root: value)
28
+ Dsl.extend(value)
29
29
  end
30
30
  end
31
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pathtree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - gemmaro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-14 00:00:00.000000000 Z
11
+ date: 2022-05-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Pathname DSL
14
14
  email: