pathtree 0.1.1 → 0.2.0

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: 13b52803c5a409fd368d095edb856e29a3a54c6c7e177df66e4410473ee3f776
4
- data.tar.gz: 4ee4258ce192ae3d6ff2f8b943f1d76bc886ce7a2fdbaf851aa549c74d6050ac
3
+ metadata.gz: 5618618520c5b3e5d9c7d1094ac3ca0e42805d016d5152d3ee42a0b06e912a36
4
+ data.tar.gz: 4d1e1bf3729a4393d9d0bd6a9d9dff8a2e9e6490e40a696b7c7ed13f63bcec84
5
5
  SHA512:
6
- metadata.gz: f615213773979b011228246740045d274021ca3c453466403cb3c90a44795d0f589f2f4ac5fad0dc1938ee19fb72d089217739fea2061ee7b9d81dc583cc8a64
7
- data.tar.gz: 476c327f6704ec2a80ef6abc2eb98f079b6f82aba2cf40f5299e7a7a37163e44dec6baa6046824dc71623f0dab9dd30f8a88b58f7817003e3ed4a9105bbc6c09
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
- - Initial release
57
+ * Initial release
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Pathtree
4
- VERSION = '0.1.1'
3
+ require 'pathname'
4
+
5
+ class Pathtree < Pathname
6
+ VERSION = '0.2.0'
5
7
  end
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).tap { _1.read(file_path) }.tree
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
- @tree = Pathtree.new
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).then { instance_eval(_1) }
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
- @tree.define_singleton_method(name) { working_directory / path }
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
- @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
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pathtree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gemmaro