pathtree 0.2.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5618618520c5b3e5d9c7d1094ac3ca0e42805d016d5152d3ee42a0b06e912a36
4
- data.tar.gz: 4d1e1bf3729a4393d9d0bd6a9d9dff8a2e9e6490e40a696b7c7ed13f63bcec84
3
+ metadata.gz: 06e46ecc4b58e4553042302669756be661ac48184b80ed5dd54da22dc8697b5f
4
+ data.tar.gz: d73d5937c003469eede446f6e700657b594083a09b5d4f9d886df3ecc3369a48
5
5
  SHA512:
6
- metadata.gz: 1c1491f67f13883d135417a51986777577ca70119796d8db898dd548b19a8c1f6c1e47d866066210564ad6d586c61ce598ffa5e9ef8b734e0ff628d3ff3aaef8
7
- data.tar.gz: f553ba89a367f84541ddcfba1dcfbbf13b398fefbc9d652f1de83895af66c2b4b8321144a5b23309c89f11a7aec2dd9c62639937857f2f22e3e308b2c6d1e4f3
6
+ metadata.gz: 9b2c4e1e4f15378a564e3db49d93b77126d55900a913435b74e71206195153f723785369f800d107a3c3bb3d4966a0a44c47c9d5a18322a48886d9e8413a7294
7
+ data.tar.gz: d76946784f32750357ab5bbe6145f114b5207c6204fdd3f2663c2d7da5d322aa25d5e3047fc0a514d1749e33164f30323dd4564f3c2a3953366215ab3c31de8f
data/CHANGELOG.md CHANGED
@@ -7,9 +7,61 @@ 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
+
25
+ ## 0.4.0 - 2022-05-14
26
+
27
+ ### Changed in 0.4.0
28
+
29
+ * Moved `Pathtree::Dsl.read` and `Pathtree::Dsl.load` to `Pathtree.read` and `Pathree.load`.
30
+ * If root path is not given, `Pathtree::Trunk` is used, rather than `Pathname.pwd`.
31
+
32
+ ### Removed in 0.4.0
33
+
34
+ * Refinements for `String`, `Pathname`, and `Object`
35
+
36
+ ## 0.3.0 - 2021-12-12
37
+
38
+ ### Added in 0.3.0
39
+
40
+ * GitLab CI which checks tests with Minitest and lint rules with RuboCop
41
+ * Enable to pass `Proc` object to `path` argument
42
+ of `Pathtree::Dsl#file` and `Pathtree::Dsl#directory`.
43
+
44
+ ```ruby
45
+ file :main_idr, -> { _1.capitalize } # Main.idr
46
+ ```
47
+
48
+ * `Pathtree::StringRefinements#split_extension`
49
+ * `Pathtree::ObjectRefinements#file_path` and `Pathtree::ObjectRefinements#directory_path`
50
+
51
+ ### Removed in 0.3.0
52
+
53
+ * `Pathtree::SymbolRefinements`
54
+ * Move to `Pathtree::StringRefinements#split_extension`
55
+ * `dot` option for `Pathtree::Dsl#file` and `Pathtree::Dsl#directory`
56
+ * Use `Proc` for path instead
57
+
58
+ ### Changed in 0.3.0
59
+
60
+ * Visibility of `Pathtree::Dsl#read` to private
61
+
10
62
  ## 0.2.0 - 2021-11-20
11
63
 
12
- ### Changed
64
+ ### Changed in 0.2.0
13
65
 
14
66
  * `Pathtree` inherits `Pathname`
15
67
 
@@ -29,14 +81,14 @@ Pathtree::Dsl.read('paths.rb').aaa.then { path(_1) } # $PWD/aaa
29
81
  Pathtree::Dsl.read('paths.rb').aaa # $PWD/aaa
30
82
  ```
31
83
 
32
- ### Removed
84
+ ### Removed in 0.2.0
33
85
 
34
86
  * `KernelRefinements` since `Pathtree` directory object is now `Pathtree` itself
35
87
  * Instance reader attribute `@tree` of `Pathtree::Dsl`
36
88
 
37
89
  ## 0.1.1 - 2021-11-20
38
90
 
39
- ### Added
91
+ ### Added in 0.1.1
40
92
 
41
93
  * `dot` option for `Pathtree::Dsl#file` and `Pathtree::Dsl#directory`.
42
94
  If `dot: true`, then path name is prefixed with dot (period) character
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Pathtree
2
2
 
3
- Tree structure of Pathname
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
- See tests.
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. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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`. 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).
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](https://opensource.org/licenses/MIT).
68
+ The gem is available as open source under the terms of the [MIT License][mit].
69
+
70
+ [mit]: https://opensource.org/licenses/MIT
@@ -0,0 +1,67 @@
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(path, name: name).then { nest(_1) }
20
+ sprout(name: name, path: path)
21
+ end
22
+
23
+ # Grows directory branch from the branch.
24
+ # See also Pathtree::Dsl#file method.
25
+ # This method has optional block, which represents nested file structure.
26
+ def directory(name, path = nil, &block)
27
+ check_name(name)
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)
32
+ end
33
+
34
+ alias dir directory
35
+
36
+ def self.extend(path)
37
+ path.instance_variable_set(:@names, [])
38
+ path.extend(Dsl)
39
+ path
40
+ end
41
+
42
+ private
43
+
44
+ def check_name(name)
45
+ raise MethodDuplicationError, name if respond_to?(name)
46
+ end
47
+
48
+ def normalize(path, name:)
49
+ if path.nil?
50
+ Pathname(name.to_s)
51
+ elsif path.is_a?(String)
52
+ Pathname(path)
53
+ elsif path.respond_to?(:call)
54
+ path.call(name).to_s.then { Pathname(_1) }
55
+ else
56
+ path
57
+ end
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
66
+ end
67
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require_relative 'dsl'
5
+
6
+ module Pathtree
7
+ # A trunk of path tree
8
+ class Trunk
9
+ include Dsl
10
+
11
+ def initialize
12
+ @names = []
13
+ end
14
+ end
15
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  require 'pathname'
4
4
 
5
- class Pathtree < Pathname
6
- VERSION = '0.2.0'
5
+ module Pathtree
6
+ VERSION = '0.4.1'
7
7
  end
data/lib/pathtree.rb CHANGED
@@ -1,81 +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
- class Pathtree < Pathname
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
- 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
- ".#{self}"
30
- end
31
- end
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
- class Dsl
35
- using SymbolRefinements
36
- using StringRefinements
37
-
38
- def self.read(file_path, working_directory: Pathname.pwd)
39
- new(working_directory: working_directory)
40
- .tap { _1.read(file_path) }
41
- .instance_variable_get(:@working_directory)
42
- end
43
-
44
- # See also Pathtree::Dsl.read.
45
- def initialize(working_directory: Pathname.pwd)
46
- @working_directory = Pathtree.new(working_directory)
47
- end
48
-
49
- def read(file_path)
50
- instance_eval File.read(file_path)
51
- end
52
-
53
- def file(name, path = name.path(type: :file), dot: false)
54
- # NOTE: Temporal variable is needed
55
- # since define_singleton_method's block is evaluated using instance_eval
56
- # which is same as define_method.
57
- working_directory = @working_directory
58
-
59
- path = path.prefix_dot if dot
60
-
61
- @working_directory.define_singleton_method(name) { working_directory / path }
62
- end
63
-
64
- def directory(name, path = name.path, dot: false, &block)
65
- path = path.prefix_dot if dot
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) }
21
+ end
66
22
 
67
- # NOTE: Temporal variable is needed
68
- # since define_singleton_method's block is evaluated using instance_eval
69
- # which is same as define_method.
70
- working_directory = @working_directory / path
23
+ class << self
24
+ private
71
25
 
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)
76
- end
26
+ def to_path(value)
27
+ value = Pathname(value) if value.is_a?(String)
28
+ Dsl.extend(value)
77
29
  end
78
-
79
- alias dir directory
80
30
  end
81
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.2.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: 2021-11-19 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
11
+ date: 2022-05-17 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.2.22
47
+ rubygems_version: 3.3.7
157
48
  signing_key:
158
49
  specification_version: 4
159
- summary: Tree structure of Pathname
50
+ summary: Pathname DSL
160
51
  test_files: []