pathtree 0.1.1 → 0.2.0
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/CHANGELOG.md +28 -1
- data/lib/pathtree/version.rb +4 -2
- data/lib/pathtree.rb +11 -21
- 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: 5618618520c5b3e5d9c7d1094ac3ca0e42805d016d5152d3ee42a0b06e912a36
|
4
|
+
data.tar.gz: 4d1e1bf3729a4393d9d0bd6a9d9dff8a2e9e6490e40a696b7c7ed13f63bcec84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c1491f67f13883d135417a51986777577ca70119796d8db898dd548b19a8c1f6c1e47d866066210564ad6d586c61ce598ffa5e9ef8b734e0ff628d3ff3aaef8
|
7
|
+
data.tar.gz: f553ba89a367f84541ddcfba1dcfbbf13b398fefbc9d652f1de83895af66c2b4b8321144a5b23309c89f11a7aec2dd9c62639937857f2f22e3e308b2c6d1e4f3
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## Unreleased
|
9
9
|
|
10
|
+
## 0.2.0 - 2021-11-20
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
|
14
|
+
* `Pathtree` inherits `Pathname`
|
15
|
+
|
16
|
+
`paths.rb`:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
dir :aaa
|
20
|
+
```
|
21
|
+
|
22
|
+
`main.rb`:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# old (not works for now, see removed section)
|
26
|
+
Pathtree::Dsl.read('paths.rb').aaa.then { path(_1) } # $PWD/aaa
|
27
|
+
|
28
|
+
# new
|
29
|
+
Pathtree::Dsl.read('paths.rb').aaa # $PWD/aaa
|
30
|
+
```
|
31
|
+
|
32
|
+
### Removed
|
33
|
+
|
34
|
+
* `KernelRefinements` since `Pathtree` directory object is now `Pathtree` itself
|
35
|
+
* Instance reader attribute `@tree` of `Pathtree::Dsl`
|
36
|
+
|
10
37
|
## 0.1.1 - 2021-11-20
|
11
38
|
|
12
39
|
### Added
|
@@ -27,4 +54,4 @@ file :rubocop_yml, dot: true # .rubocop.yml
|
|
27
54
|
|
28
55
|
## 0.1.0 - 2021-11-13
|
29
56
|
|
30
|
-
|
57
|
+
* Initial release
|
data/lib/pathtree/version.rb
CHANGED
data/lib/pathtree.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'pathname'
|
4
4
|
require_relative 'pathtree/version'
|
5
5
|
|
6
|
-
class Pathtree
|
6
|
+
class Pathtree < Pathname
|
7
7
|
module SymbolRefinements
|
8
8
|
refine Symbol do
|
9
9
|
# +type+ option can be one of the following:
|
@@ -35,20 +35,19 @@ class Pathtree
|
|
35
35
|
using SymbolRefinements
|
36
36
|
using StringRefinements
|
37
37
|
|
38
|
-
attr_reader :tree
|
39
|
-
|
40
38
|
def self.read(file_path, working_directory: Pathname.pwd)
|
41
|
-
new(working_directory: working_directory)
|
39
|
+
new(working_directory: working_directory)
|
40
|
+
.tap { _1.read(file_path) }
|
41
|
+
.instance_variable_get(:@working_directory)
|
42
42
|
end
|
43
43
|
|
44
44
|
# See also Pathtree::Dsl.read.
|
45
45
|
def initialize(working_directory: Pathname.pwd)
|
46
|
-
@
|
47
|
-
@working_directory = Pathname(working_directory)
|
46
|
+
@working_directory = Pathtree.new(working_directory)
|
48
47
|
end
|
49
48
|
|
50
49
|
def read(file_path)
|
51
|
-
File.read(file_path)
|
50
|
+
instance_eval File.read(file_path)
|
52
51
|
end
|
53
52
|
|
54
53
|
def file(name, path = name.path(type: :file), dot: false)
|
@@ -59,7 +58,7 @@ class Pathtree
|
|
59
58
|
|
60
59
|
path = path.prefix_dot if dot
|
61
60
|
|
62
|
-
@
|
61
|
+
@working_directory.define_singleton_method(name) { working_directory / path }
|
63
62
|
end
|
64
63
|
|
65
64
|
def directory(name, path = name.path, dot: false, &block)
|
@@ -70,22 +69,13 @@ class Pathtree
|
|
70
69
|
# which is same as define_method.
|
71
70
|
working_directory = @working_directory / path
|
72
71
|
|
73
|
-
@
|
74
|
-
Dsl.new(working_directory: working_directory)
|
75
|
-
|
76
|
-
|
77
|
-
end.tree
|
72
|
+
@working_directory.define_singleton_method(name) do
|
73
|
+
Dsl.new(working_directory: working_directory)
|
74
|
+
.tap { _1.instance_eval(&block) if block_given? }
|
75
|
+
.instance_variable_get(:@working_directory)
|
78
76
|
end
|
79
77
|
end
|
80
78
|
|
81
79
|
alias dir directory
|
82
80
|
end
|
83
|
-
|
84
|
-
module KernelRefinements
|
85
|
-
refine Kernel do
|
86
|
-
def path(tree)
|
87
|
-
tree.instance_variable_get('@path')
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
81
|
end
|