pathtree 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/lib/pathtree/version.rb +1 -1
- data/lib/pathtree.rb +26 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13b52803c5a409fd368d095edb856e29a3a54c6c7e177df66e4410473ee3f776
|
4
|
+
data.tar.gz: 4ee4258ce192ae3d6ff2f8b943f1d76bc886ce7a2fdbaf851aa549c74d6050ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f615213773979b011228246740045d274021ca3c453466403cb3c90a44795d0f589f2f4ac5fad0dc1938ee19fb72d089217739fea2061ee7b9d81dc583cc8a64
|
7
|
+
data.tar.gz: 476c327f6704ec2a80ef6abc2eb98f079b6f82aba2cf40f5299e7a7a37163e44dec6baa6046824dc71623f0dab9dd30f8a88b58f7817003e3ed4a9105bbc6c09
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## Unreleased
|
9
9
|
|
10
|
+
## 0.1.1 - 2021-11-20
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
* `dot` option for `Pathtree::Dsl#file` and `Pathtree::Dsl#directory`.
|
15
|
+
If `dot: true`, then path name is prefixed with dot (period) character
|
16
|
+
unless it start with dot already.
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
# old
|
20
|
+
file :rubocop_yml, '.rubocop_yml'
|
21
|
+
|
22
|
+
# new
|
23
|
+
file :rubocop_yml, dot: true # .rubocop.yml
|
24
|
+
```
|
25
|
+
|
26
|
+
* `Pathtree::Dsl#dir` alias for `Pathtree::Dsl#directory`.
|
27
|
+
|
10
28
|
## 0.1.0 - 2021-11-13
|
11
29
|
|
12
30
|
- Initial release
|
data/lib/pathtree/version.rb
CHANGED
data/lib/pathtree.rb
CHANGED
@@ -21,8 +21,19 @@ class Pathtree
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
module StringRefinements
|
25
|
+
refine String do
|
26
|
+
def prefix_dot
|
27
|
+
return self if start_with?('.')
|
28
|
+
|
29
|
+
".#{self}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
24
34
|
class Dsl
|
25
35
|
using SymbolRefinements
|
36
|
+
using StringRefinements
|
26
37
|
|
27
38
|
attr_reader :tree
|
28
39
|
|
@@ -40,26 +51,34 @@ class Pathtree
|
|
40
51
|
File.read(file_path).then { instance_eval(_1) }
|
41
52
|
end
|
42
53
|
|
43
|
-
def file(name, path = name.path(type: :file))
|
54
|
+
def file(name, path = name.path(type: :file), dot: false)
|
44
55
|
# NOTE: Temporal variable is needed
|
45
56
|
# since define_singleton_method's block is evaluated using instance_eval
|
46
57
|
# which is same as define_method.
|
47
58
|
working_directory = @working_directory
|
48
59
|
|
60
|
+
path = path.prefix_dot if dot
|
61
|
+
|
49
62
|
@tree.define_singleton_method(name) { working_directory / path }
|
50
63
|
end
|
51
64
|
|
52
|
-
def directory(name, path = name.path, &block)
|
65
|
+
def directory(name, path = name.path, dot: false, &block)
|
66
|
+
path = path.prefix_dot if dot
|
67
|
+
|
68
|
+
# NOTE: Temporal variable is needed
|
69
|
+
# since define_singleton_method's block is evaluated using instance_eval
|
70
|
+
# which is same as define_method.
|
53
71
|
working_directory = @working_directory / path
|
54
72
|
|
55
73
|
@tree.define_singleton_method(name) do
|
56
|
-
Dsl.new(working_directory: working_directory)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end.tree
|
74
|
+
Dsl.new(working_directory: working_directory).tap do |d|
|
75
|
+
d.tree.instance_variable_set('@path', working_directory)
|
76
|
+
d.instance_eval(&block) if block_given?
|
77
|
+
end.tree
|
61
78
|
end
|
62
79
|
end
|
80
|
+
|
81
|
+
alias dir directory
|
63
82
|
end
|
64
83
|
|
65
84
|
module KernelRefinements
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gemmaro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pathname
|