pathtree 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: de74120e5b4aa9d6861e270420fb1e03fc28a77e9e9ef6f88299e931293511f2
4
+ data.tar.gz: ec2845821ab2900a60588e4ad1762cae05111ce7b6a7eada70a4a46d889843d9
5
+ SHA512:
6
+ metadata.gz: ae867e4b72f16495c41f196d5795762cc16992437e3e5ddb86dad1ba99415df5e22143ff390557a7fc19d43af5ed84efbe33f8f9038282816aa7bb40bca5fcc8
7
+ data.tar.gz: e623ba3f2e117245979f6d9ebe3a2fbc4866bc8aef4100afb4ba90d25c60c0e35b35a8468d2d8f6e09621d8716528fc7127691f393ab58530ee34102531bcdf1
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## Unreleased
9
+
10
+ ## 0.1.0 - 2021-11-13
11
+
12
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 gemmaro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Pathtree
2
+
3
+ Tree structure of Pathname
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pathtree'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```shell-session
16
+ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```shell-session
22
+ gem install pathtree
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ See tests.
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitLab at <https://gitlab.com/gemmaro/pathtree>.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pathtree
4
+ VERSION = '0.1.0'
5
+ end
data/lib/pathtree.rb ADDED
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require_relative 'pathtree/version'
5
+
6
+ class Pathtree
7
+ module SymbolRefinements
8
+ refine Symbol do
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
+ class Dsl
25
+ using SymbolRefinements
26
+
27
+ attr_reader :tree
28
+
29
+ def self.read(file_path, working_directory: Pathname.pwd)
30
+ new(working_directory: working_directory).tap { _1.read(file_path) }.tree
31
+ end
32
+
33
+ # See also Pathtree::Dsl.read.
34
+ def initialize(working_directory: Pathname.pwd)
35
+ @tree = Pathtree.new
36
+ @working_directory = Pathname(working_directory)
37
+ end
38
+
39
+ def read(file_path)
40
+ File.read(file_path).then { instance_eval(_1) }
41
+ end
42
+
43
+ def file(name, path = name.path(type: :file))
44
+ # NOTE: Temporal variable is needed
45
+ # since define_singleton_method's block is evaluated using instance_eval
46
+ # which is same as define_method.
47
+ working_directory = @working_directory
48
+
49
+ @tree.define_singleton_method(name) { working_directory / path }
50
+ end
51
+
52
+ def directory(name, path = name.path, &block)
53
+ working_directory = @working_directory / path
54
+
55
+ @tree.define_singleton_method(name) do
56
+ Dsl.new(working_directory: working_directory)
57
+ .tap do |d|
58
+ d.tree.instance_variable_set('@path', working_directory)
59
+ d.instance_eval(&block) if block_given?
60
+ end.tree
61
+ end
62
+ end
63
+ end
64
+
65
+ module KernelRefinements
66
+ refine Kernel do
67
+ def path(tree)
68
+ tree.instance_variable_get('@path')
69
+ end
70
+ end
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pathtree
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - gemmaro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
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
126
+ email:
127
+ - gemmaro.dev@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - CHANGELOG.md
133
+ - LICENSE.txt
134
+ - README.md
135
+ - lib/pathtree.rb
136
+ - lib/pathtree/version.rb
137
+ homepage: https://gitlab.com/gemmaro/pathtree
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: 3.0.0
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubygems_version: 3.2.22
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Tree structure of Pathname
160
+ test_files: []