pathtree 0.1.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +66 -2
- data/README.md +34 -5
- data/lib/pathtree/dsl.rb +69 -0
- data/lib/pathtree/trunk.rb +16 -0
- data/lib/pathtree/version.rb +4 -2
- data/lib/pathtree.rb +19 -79
- metadata +10 -119
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fa0b4b00d649556ade2438672e8f579096425641c87dc12904c0b1e83896f4c
|
4
|
+
data.tar.gz: a20dc412a32816c46688ae0ee426f1ee19d954290d3def13f64d50099a737956
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19b2cf1822c9380fbd6161ee50b3fd57990811d93331ddd22530982907654b2e6dee118715da9ccd76c5921afd01249a7fa1357b30886cab3f4ce45430f2f53f
|
7
|
+
data.tar.gz: 01bda1e63a6dcc19803a10857cb581d7457a87329e1c2592cfb355a6f5a4e235e301eea171f22a4fd613afcdaff69a6369433824c5e4595160ceee3660d6fd94
|
data/CHANGELOG.md
CHANGED
@@ -7,9 +7,73 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## Unreleased
|
9
9
|
|
10
|
+
## 0.4.0 - 2022-05-14
|
11
|
+
|
12
|
+
### Changed in 0.4.0
|
13
|
+
|
14
|
+
* Moved `Pathtree::Dsl.read` and `Pathtree::Dsl.load` to `Pathtree.read` and `Pathree.load`.
|
15
|
+
* If root path is not given, `Pathtree::Trunk` is used, rather than `Pathname.pwd`.
|
16
|
+
|
17
|
+
### Removed in 0.4.0
|
18
|
+
|
19
|
+
* Refinements for `String`, `Pathname`, and `Object`
|
20
|
+
|
21
|
+
## 0.3.0 - 2021-12-12
|
22
|
+
|
23
|
+
### Added in 0.3.0
|
24
|
+
|
25
|
+
* GitLab CI which checks tests with Minitest and lint rules with RuboCop
|
26
|
+
* Enable to pass `Proc` object to `path` argument
|
27
|
+
of `Pathtree::Dsl#file` and `Pathtree::Dsl#directory`.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
file :main_idr, -> { _1.capitalize } # Main.idr
|
31
|
+
```
|
32
|
+
|
33
|
+
* `Pathtree::StringRefinements#split_extension`
|
34
|
+
* `Pathtree::ObjectRefinements#file_path` and `Pathtree::ObjectRefinements#directory_path`
|
35
|
+
|
36
|
+
### Removed in 0.3.0
|
37
|
+
|
38
|
+
* `Pathtree::SymbolRefinements`
|
39
|
+
* Move to `Pathtree::StringRefinements#split_extension`
|
40
|
+
* `dot` option for `Pathtree::Dsl#file` and `Pathtree::Dsl#directory`
|
41
|
+
* Use `Proc` for path instead
|
42
|
+
|
43
|
+
### Changed in 0.3.0
|
44
|
+
|
45
|
+
* Visibility of `Pathtree::Dsl#read` to private
|
46
|
+
|
47
|
+
## 0.2.0 - 2021-11-20
|
48
|
+
|
49
|
+
### Changed in 0.2.0
|
50
|
+
|
51
|
+
* `Pathtree` inherits `Pathname`
|
52
|
+
|
53
|
+
`paths.rb`:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
dir :aaa
|
57
|
+
```
|
58
|
+
|
59
|
+
`main.rb`:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# old (not works for now, see removed section)
|
63
|
+
Pathtree::Dsl.read('paths.rb').aaa.then { path(_1) } # $PWD/aaa
|
64
|
+
|
65
|
+
# new
|
66
|
+
Pathtree::Dsl.read('paths.rb').aaa # $PWD/aaa
|
67
|
+
```
|
68
|
+
|
69
|
+
### Removed in 0.2.0
|
70
|
+
|
71
|
+
* `KernelRefinements` since `Pathtree` directory object is now `Pathtree` itself
|
72
|
+
* Instance reader attribute `@tree` of `Pathtree::Dsl`
|
73
|
+
|
10
74
|
## 0.1.1 - 2021-11-20
|
11
75
|
|
12
|
-
### Added
|
76
|
+
### Added in 0.1.1
|
13
77
|
|
14
78
|
* `dot` option for `Pathtree::Dsl#file` and `Pathtree::Dsl#directory`.
|
15
79
|
If `dot: true`, then path name is prefixed with dot (period) character
|
@@ -27,4 +91,4 @@ file :rubocop_yml, dot: true # .rubocop.yml
|
|
27
91
|
|
28
92
|
## 0.1.0 - 2021-11-13
|
29
93
|
|
30
|
-
|
94
|
+
* Initial release
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Pathtree
|
2
2
|
|
3
|
-
|
3
|
+
Pathname DSL
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -24,13 +24,40 @@ gem install pathtree
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
|
27
|
+
`path.rb`:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
file :aaa
|
31
|
+
|
32
|
+
directory :public do
|
33
|
+
file :bbb
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
`Rakefile`:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'pathtree'
|
41
|
+
|
42
|
+
P = Pathtree.read('path.rb')
|
43
|
+
|
44
|
+
file P.public.bbb => P.aaa do |t|
|
45
|
+
cp t.source, t.name
|
46
|
+
do
|
47
|
+
```
|
28
48
|
|
29
49
|
## Development
|
30
50
|
|
31
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
52
|
+
Then, run `rake test` to run the tests.
|
53
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
32
54
|
|
33
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
55
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
56
|
+
To release a new version, update the version number in `version.rb`,
|
57
|
+
and then run `bundle exec rake release`,
|
58
|
+
which will create a git tag for the version,
|
59
|
+
push git commits and the created tag,
|
60
|
+
and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
34
61
|
|
35
62
|
## Contributing
|
36
63
|
|
@@ -38,4 +65,6 @@ Bug reports and pull requests are welcome on GitLab at <https://gitlab.com/gemma
|
|
38
65
|
|
39
66
|
## License
|
40
67
|
|
41
|
-
The gem is available as open source under the terms of the [MIT License]
|
68
|
+
The gem is available as open source under the terms of the [MIT License][mit].
|
69
|
+
|
70
|
+
[mit]: https://opensource.org/licenses/MIT
|
data/lib/pathtree/dsl.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
module Pathtree
|
6
|
+
# DSL for constructing path tree
|
7
|
+
module Dsl
|
8
|
+
attr_reader :names
|
9
|
+
|
10
|
+
# Grows file leaf from the branch;
|
11
|
+
# The path at the point where this method is called
|
12
|
+
# attempts to create an instance method that returns the path with the +name+.
|
13
|
+
#
|
14
|
+
# * If +path+ is +nil+, +name+ is used instead.
|
15
|
+
# * If +path+ is a +Proc+, give +name+ to it.
|
16
|
+
# * Otherwise, +path+ itself is used.
|
17
|
+
def file(name, path = nil)
|
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 }
|
23
|
+
end
|
24
|
+
|
25
|
+
# Grows directory branch from the branch.
|
26
|
+
# See also Pathtree::Dsl#file method.
|
27
|
+
# This method has optional block, which represents nested file structure.
|
28
|
+
def directory(name, path = nil, &block)
|
29
|
+
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
|
40
|
+
end
|
41
|
+
|
42
|
+
alias dir directory
|
43
|
+
|
44
|
+
def self.extend(path, root: nil)
|
45
|
+
path.instance_variable_set(:@names, [])
|
46
|
+
path.instance_variable_set(:@root, root)
|
47
|
+
path.extend(Dsl)
|
48
|
+
path
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def check_name(name)
|
54
|
+
raise MethodDuplicationError, name if respond_to?(name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def normalize(name:, path: nil)
|
58
|
+
if path.nil?
|
59
|
+
Pathname(name.to_s)
|
60
|
+
elsif path.is_a?(String)
|
61
|
+
Pathname(path)
|
62
|
+
elsif path.respond_to?(:call)
|
63
|
+
path.call(name).then { normalize(name: _1) }
|
64
|
+
else
|
65
|
+
path
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/pathtree/version.rb
CHANGED
data/lib/pathtree.rb
CHANGED
@@ -1,91 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'pathname'
|
4
3
|
require_relative 'pathtree/version'
|
4
|
+
require_relative 'pathtree/trunk'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# +type+ option can be one of the following:
|
10
|
-
#
|
11
|
-
# +:directory+:: +:directory+ simply converts to +String+.
|
12
|
-
# +:file+:: +:file+ converts to +String+, and turn +aaa_bbb_ccc+ into +aaa_bbb.ccc+ for example.
|
13
|
-
def path(type: :directory)
|
14
|
-
case type
|
15
|
-
in :directory
|
16
|
-
to_s
|
17
|
-
in :file
|
18
|
-
to_s.sub(/\A[a-z0-9_]*\K_(?=[a-z0-9]+\Z)/, '.')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module StringRefinements
|
25
|
-
refine String do
|
26
|
-
def prefix_dot
|
27
|
-
return self if start_with?('.')
|
6
|
+
# Pathname DSL
|
7
|
+
module Pathtree
|
8
|
+
class MethodDuplicationError < NameError; end
|
28
9
|
|
29
|
-
|
30
|
-
|
31
|
-
|
10
|
+
# Read Pathtree DSL from +path+.
|
11
|
+
# +root+ is base directory for tree.
|
12
|
+
def self.read(path, root: nil)
|
13
|
+
dsl = File.read(path)
|
14
|
+
self.load(dsl, root: root)
|
32
15
|
end
|
33
16
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
attr_reader :tree
|
39
|
-
|
40
|
-
def self.read(file_path, working_directory: Pathname.pwd)
|
41
|
-
new(working_directory: working_directory).tap { _1.read(file_path) }.tree
|
42
|
-
end
|
43
|
-
|
44
|
-
# See also Pathtree::Dsl.read.
|
45
|
-
def initialize(working_directory: Pathname.pwd)
|
46
|
-
@tree = Pathtree.new
|
47
|
-
@working_directory = Pathname(working_directory)
|
48
|
-
end
|
49
|
-
|
50
|
-
def read(file_path)
|
51
|
-
File.read(file_path).then { instance_eval(_1) }
|
52
|
-
end
|
53
|
-
|
54
|
-
def file(name, path = name.path(type: :file), dot: false)
|
55
|
-
# NOTE: Temporal variable is needed
|
56
|
-
# since define_singleton_method's block is evaluated using instance_eval
|
57
|
-
# which is same as define_method.
|
58
|
-
working_directory = @working_directory
|
59
|
-
|
60
|
-
path = path.prefix_dot if dot
|
61
|
-
|
62
|
-
@tree.define_singleton_method(name) { working_directory / path }
|
63
|
-
end
|
64
|
-
|
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.
|
71
|
-
working_directory = @working_directory / path
|
72
|
-
|
73
|
-
@tree.define_singleton_method(name) do
|
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
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
alias dir directory
|
17
|
+
# Load Pathtree DSL source.
|
18
|
+
# +root+ is base directory for tree.
|
19
|
+
def self.load(dsl, root: nil)
|
20
|
+
(root ? to_path(root) : Trunk.new).tap { _1.instance_eval(dsl) }
|
82
21
|
end
|
83
22
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
23
|
+
class << self
|
24
|
+
private
|
25
|
+
|
26
|
+
def to_path(value)
|
27
|
+
value = Pathname(value) if value.is_a?(String)
|
28
|
+
Dsl.extend(value, root: value)
|
89
29
|
end
|
90
30
|
end
|
91
31
|
end
|
metadata
CHANGED
@@ -1,128 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pathtree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gemmaro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
name: pathname
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.2.0
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.2.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: minitest
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '5.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '5.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '13.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '13.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rdoc
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '6.3'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '6.3'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.7'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.7'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-minitest
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.15.2
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.15.2
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rubocop-rake
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 0.6.0
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 0.6.0
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: solargraph
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 0.44.0
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: 0.44.0
|
125
|
-
description: Tree structure of Pathname
|
11
|
+
date: 2022-05-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Pathname DSL
|
126
14
|
email:
|
127
15
|
- gemmaro.dev@gmail.com
|
128
16
|
executables: []
|
@@ -133,11 +21,14 @@ files:
|
|
133
21
|
- LICENSE.txt
|
134
22
|
- README.md
|
135
23
|
- lib/pathtree.rb
|
24
|
+
- lib/pathtree/dsl.rb
|
25
|
+
- lib/pathtree/trunk.rb
|
136
26
|
- lib/pathtree/version.rb
|
137
27
|
homepage: https://gitlab.com/gemmaro/pathtree
|
138
28
|
licenses:
|
139
29
|
- MIT
|
140
|
-
metadata:
|
30
|
+
metadata:
|
31
|
+
rubygems_mfa_required: 'true'
|
141
32
|
post_install_message:
|
142
33
|
rdoc_options: []
|
143
34
|
require_paths:
|
@@ -153,8 +44,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
44
|
- !ruby/object:Gem::Version
|
154
45
|
version: '0'
|
155
46
|
requirements: []
|
156
|
-
rubygems_version: 3.
|
47
|
+
rubygems_version: 3.3.7
|
157
48
|
signing_key:
|
158
49
|
specification_version: 4
|
159
|
-
summary:
|
50
|
+
summary: Pathname DSL
|
160
51
|
test_files: []
|