tty-tree 0.3.0 → 0.4.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: 53809e6a714d9396dad1142a2a2b9a0183c7cc18580634ea3d9e0e42a22fb58a
4
- data.tar.gz: 14326bab7fc703fb8e39870238f9a4ff964c9ab60699d2a18bf4c42a381abe88
3
+ metadata.gz: 5b8452b6655c19ad246609177067301233b28c43fb9c893923d7f4ad22563788
4
+ data.tar.gz: d830d19213e512c25ccb5101e5dcf1b493e4ef0a386e0552d140cdf6e0d9e679
5
5
  SHA512:
6
- metadata.gz: 2a4a9598b9b71c63eb8332b6445686b553aba1e6af92937dc23a0f3432f5ae67190bd91985975bba95afe18bf70dd89e58001f5c2875c4dd4b35790ec38933e6
7
- data.tar.gz: 27dafaa5422382d8749017825110641ea4021c71a3778997a6484804015d08b217eaec6941e834a448fc9d25e07ea4f3e2d94735e0bcbf9367b93e37f4459e64
6
+ metadata.gz: e20e02a6917378ca0a002ca21ca9bcbffaa73bafd53350eee51053e2b42ce530bd3a0ee12d71368f0ce2e44bb759479964c8f582f71d6db427b7ed37cadc2f1e
7
+ data.tar.gz: d9da30e6338893311439317b5fa8e0a4d63ec3358fd825d0b546b6e6219edd6eba3f416a52f74e88f8edf277aef917efff70994595497799739fcc14aed695d0
@@ -1,5 +1,13 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.4.0] - 2020-01-16
4
+
5
+ ### Changed
6
+ * Change gemspec to add metadata and remove test artifacts
7
+
8
+ ### Fixed
9
+ * Change to fix Ruby 2.7 keyword conversion warnings
10
+
3
11
  ## [v0.3.0] - 2019-05-03
4
12
 
5
13
  ### Changed
@@ -14,6 +22,7 @@
14
22
 
15
23
  * Initial implementation and release
16
24
 
25
+ [v0.4.0]: https://github.com/piotrmurach/tty-tree/compare/v0.3.0...v0.4.0
17
26
  [v0.3.0]: https://github.com/piotrmurach/tty-tree/compare/v0.2.0...v0.3.0
18
27
  [v0.2.0]: https://github.com/piotrmurach/tty-tree/compare/v0.1.0...v0.2.0
19
28
  [v0.1.0]: https://github.com/piotrmurach/tty-tree/compare/v0.1.0
data/README.md CHANGED
@@ -44,12 +44,12 @@ Or install it yourself as:
44
44
  * [1. Usage](#1-usage)
45
45
  * [2. Interface](#2-interface)
46
46
  * [2.1 new](#21-new)
47
- * [2.1.1 level](#211-level)
48
- * [2.1.2 file_limit](#212-level)
49
- * [2.1.3 show_hidden](#213-show_hidden)
50
- * [2.1.4 only_dirs](#214-only_dirs)
47
+ * [2.1.1 :level](#211-level)
48
+ * [2.1.2 :file_limit](#212-file_limit)
49
+ * [2.1.3 :show_hidden](#213-show_hidden)
50
+ * [2.1.4 :only_dirs](#214-only_dirs)
51
51
  * [2.2 render](#22-render)
52
- * [2.2.1 indent](#221-indent)
52
+ * [2.2.1 :indent](#221-indent)
53
53
 
54
54
  ## 1. Usage
55
55
 
@@ -104,12 +104,12 @@ puts tree.render
104
104
  # =>
105
105
  # dir1
106
106
  # ├── config.dat
107
- # ├── dir2,
108
- # │ ├── dir3\n",
109
- # │ │ └── file3-1.txt\n",
110
- # │ └── file2-1.txt\n",
111
- # ├── file1-1.txt\n",
112
- # └── file1-2.txt\n",
107
+ # ├── dir2
108
+ # │ ├── dir3
109
+ # │ │ └── file3-1.txt
110
+ # │ └── file2-1.txt
111
+ # ├── file1-1.txt
112
+ # └── file1-2.txt
113
113
  ```
114
114
 
115
115
  The `render` call returns a string and leaves it up to api consumer how to handle the tree like output.
@@ -126,7 +126,7 @@ tree = TTY::Tree.new('dir-name')
126
126
  tree = TTY::Tree.new(Pathname.pwd)
127
127
  ```
128
128
 
129
- or hash data structure:
129
+ Or hash data structure:
130
130
 
131
131
  ```ruby
132
132
  data = {
@@ -172,7 +172,7 @@ tree = TTY::Tree.new('dir-name', level: 2)
172
172
  # => parse directories as deep as 2 levels
173
173
  ```
174
174
 
175
- #### 2.1.2 file_limit
175
+ #### 2.1.2 `:file_limit`
176
176
 
177
177
  Prevent `TTY::Tree` descending directories more than `#` entries:
178
178
 
@@ -180,7 +180,7 @@ Prevent `TTY::Tree` descending directories more than `#` entries:
180
180
  tree = TTY::Tree.new('dir-name', file_limit: 2)
181
181
  ```
182
182
 
183
- #### 2.1.3 show_hidden
183
+ #### 2.1.3 `:show_hidden`
184
184
 
185
185
  In order to for `TTY::Tree` to include hidden files in its output use `:show_hidden` option like so:
186
186
 
@@ -211,17 +211,17 @@ If you prefer a numeric notation of nested content you can use `TTY::NumberRende
211
211
  ```ruby
212
212
  puts tree.render(as: :number)
213
213
  # =>
214
- # dir1\n",
215
- # 1.1 config.dat\n",
216
- # 1.2 dir2\n",
217
- # 2.3 dir3\n",
218
- # 3.4 file3-1.txt\n",
219
- # 2.5 file2-1.txt\n",
220
- # 1.6 file1-1.txt\n",
221
- # 1.7 file1-2.txt\n",
214
+ # dir1
215
+ # 1.1 config.dat
216
+ # 1.2 dir2
217
+ # 2.3 dir3
218
+ # 3.4 file3-1.txt
219
+ # 2.5 file2-1.txt
220
+ # 1.6 file1-1.txt
221
+ # 1.7 file1-2.txt
222
222
  ```
223
223
 
224
- #### 2.2.1 indent
224
+ #### 2.2.1 `:indent`
225
225
 
226
226
  The number of spaces to use when indenting nested directories. By default `4` spaces are used.
227
227
 
@@ -241,4 +241,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/piotrm
241
241
 
242
242
  ## Copyright
243
243
 
244
- Copyright (c) 2017-2018 Piotr Murach. See LICENSE for further details.
244
+ Copyright (c) 2017 Piotr Murach. See LICENSE for further details.
@@ -19,7 +19,7 @@ module TTY
19
19
  # Create a PathWalker
20
20
  #
21
21
  # @api public
22
- def initialize(**options)
22
+ def initialize(options = {})
23
23
  @files_count = 0
24
24
  @dirs_count = 0
25
25
  @nodes = []
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  class Tree
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end # Tree
7
7
  end # TTY
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-03 00:00:00.000000000 Z
11
+ date: 2020-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -54,17 +54,15 @@ dependencies:
54
54
  version: '3.0'
55
55
  description: Print directory or structured data in a tree like format.
56
56
  email:
57
- - me@piotrmurach.com
57
+ - piotr@piotrmurach.com
58
58
  executables: []
59
59
  extensions: []
60
- extra_rdoc_files: []
60
+ extra_rdoc_files:
61
+ - README.md
61
62
  files:
62
63
  - CHANGELOG.md
63
64
  - LICENSE.txt
64
65
  - README.md
65
- - Rakefile
66
- - bin/console
67
- - bin/setup
68
66
  - lib/tty-tree.rb
69
67
  - lib/tty/tree.rb
70
68
  - lib/tty/tree/directory_renderer.rb
@@ -73,21 +71,16 @@ files:
73
71
  - lib/tty/tree/number_renderer.rb
74
72
  - lib/tty/tree/path_walker.rb
75
73
  - lib/tty/tree/version.rb
76
- - spec/spec_helper.rb
77
- - spec/unit/directory_renderer_spec.rb
78
- - spec/unit/hash_walker_spec.rb
79
- - spec/unit/new_spec.rb
80
- - spec/unit/node_spec.rb
81
- - spec/unit/number_renderer_spec.rb
82
- - spec/unit/path_walker_spec.rb
83
- - tasks/console.rake
84
- - tasks/coverage.rake
85
- - tasks/spec.rake
86
- - tty-tree.gemspec
87
74
  homepage: https://piotrmurach.github.io/tty
88
75
  licenses:
89
76
  - MIT
90
- metadata: {}
77
+ metadata:
78
+ allowed_push_host: https://rubygems.org
79
+ bug_tracker_uri: https://github.com/piotrmurach/tty-tree/issues
80
+ changelog_uri: https://github.com/piotrmurach/tty-tree/blob/master/CHANGELOG.md
81
+ documentation_uri: https://www.rubydoc.info/gems/tty-tree
82
+ homepage_uri: https://piotrmurach.github.io/tty
83
+ source_code_uri: https://github.com/piotrmurach/tty-tree
91
84
  post_install_message:
92
85
  rdoc_options: []
93
86
  require_paths:
@@ -103,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
96
  - !ruby/object:Gem::Version
104
97
  version: '0'
105
98
  requirements: []
106
- rubygems_version: 3.0.3
99
+ rubygems_version: 3.1.2
107
100
  signing_key:
108
101
  specification_version: 4
109
102
  summary: Print directory or structured data in a tree like format.
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'bundler/gem_tasks'
4
-
5
- FileList['tasks/**/*.rake'].each(&method(:import))
6
-
7
- desc 'Run all specs'
8
- task ci: %w[ spec ]
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "tty/tree"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,71 +0,0 @@
1
- # encoding: utf-8
2
-
3
- if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
4
- require 'simplecov'
5
- require 'coveralls'
6
-
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ]
11
-
12
- SimpleCov.start do
13
- command_name 'spec'
14
- add_filter 'spec'
15
- end
16
- end
17
-
18
- require 'bundler/setup'
19
- require 'tty/tree'
20
- require 'fileutils'
21
-
22
- module TestHelpers
23
- module Paths
24
- def gem_root
25
- File.expand_path("#{File.dirname(__FILE__)}/..")
26
- end
27
-
28
- def dir_path(*args)
29
- path = File.join(gem_root, *args)
30
- FileUtils.mkdir_p(path)
31
- File.realpath(path)
32
- end
33
-
34
- def tmp_path(*args)
35
- File.join(dir_path('tmp'), *args)
36
- end
37
-
38
- def fixtures_path(*args)
39
- File.join(dir_path('spec/fixtures'), *args)
40
- end
41
-
42
- def within_dir(target, &block)
43
- ::Dir.chdir(target, &block)
44
- end
45
- end
46
- end
47
-
48
- RSpec.configure do |config|
49
- config.include(TestHelpers::Paths)
50
- # config.example_status_persistence_file_path = ".rspec_status"
51
-
52
- config.expect_with :rspec do |c|
53
- c.syntax = :expect
54
- end
55
-
56
- config.mock_with :rspec do |mocks|
57
- mocks.verify_partial_doubles = true
58
- end
59
-
60
- config.disable_monkey_patching!
61
-
62
- config.warnings = true
63
-
64
- if config.files_to_run.one?
65
- config.default_formatter = 'doc'
66
- end
67
-
68
- config.order = :random
69
-
70
- Kernel.srand config.seed
71
- end
@@ -1,173 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- RSpec.describe TTY::Tree::DirectoryRenderer do
5
- it "renders directory as path" do
6
- tree = within_dir(fixtures_path) do
7
- TTY::Tree.new('dir1')
8
- end
9
-
10
- expect(tree.render).to eq([
11
- "dir1\n",
12
- "├── config.dat\n",
13
- "├── dir2\n",
14
- "│ ├── dir3\n",
15
- "│ │ └── file3-1.txt\n",
16
- "│ └── file2-1.txt\n",
17
- "├── file1-1.txt\n",
18
- "└── file1-2.txt\n",
19
- ].join)
20
- end
21
-
22
- it "renders hash data as path " do
23
- data = {
24
- dir1: [
25
- 'config.dat',
26
- { dir2: [
27
- { dir3: [ 'file3-1.txt' ] },
28
- 'file2-1.txt'
29
- ]
30
- },
31
- 'file1-1.txt',
32
- 'file1-2.txt'
33
- ]
34
- }
35
-
36
- tree = TTY::Tree.new(data)
37
-
38
- expect(tree.render).to eq([
39
- "dir1\n",
40
- "├── config.dat\n",
41
- "├── dir2\n",
42
- "│ ├── dir3\n",
43
- "│ │ └── file3-1.txt\n",
44
- "│ └── file2-1.txt\n",
45
- "├── file1-1.txt\n",
46
- "└── file1-2.txt\n",
47
- ].join)
48
- end
49
-
50
- it "correctly renders orphaned directory as path" do
51
- tree = within_dir(fixtures_path) do
52
- TTY::Tree.new('orphan_dir')
53
- end
54
-
55
- expect(tree.render).to eq([
56
- "orphan_dir\n",
57
- "├── a.txt\n",
58
- "├── b.txt\n",
59
- "└── data\n",
60
- " ├── data1.bin\n",
61
- " ├── data2.sql\n",
62
- " └── data3.inf\n",
63
- ].join)
64
- end
65
-
66
- it "correctly renders hash with orphaned directory as path" do
67
- data = {
68
- orphan_dir: [
69
- 'a.txt',
70
- 'b.txt',
71
- { data: [
72
- 'data1.bin',
73
- 'data2.sql',
74
- 'data3.inf'
75
- ]
76
- }
77
- ]
78
- }
79
-
80
- tree = TTY::Tree.new(data)
81
-
82
- expect(tree.render).to eq([
83
- "orphan_dir\n",
84
- "├── a.txt\n",
85
- "├── b.txt\n",
86
- "└── data\n",
87
- " ├── data1.bin\n",
88
- " ├── data2.sql\n",
89
- " └── data3.inf\n",
90
- ].join)
91
- end
92
-
93
- it "renders directory as path without indentation" do
94
- tree = within_dir(fixtures_path) do
95
- TTY::Tree.new('dir1')
96
- end
97
-
98
- expect(tree.render(indent: 0)).to eq([
99
- "dir1\n",
100
- "├── config.dat\n",
101
- "├── dir2\n",
102
- "│├── dir3\n",
103
- "││└── file3-1.txt\n",
104
- "│└── file2-1.txt\n",
105
- "├── file1-1.txt\n",
106
- "└── file1-2.txt\n",
107
- ].join)
108
- end
109
-
110
- it "renders directory without hidden files" do
111
- tree = within_dir(fixtures_path) do
112
- TTY::Tree.new('hidden_dir', show_hidden: true)
113
- end
114
-
115
- expect(tree.render).to eq([
116
- "hidden_dir\n",
117
- "├── .with_dot\n",
118
- "│ └── config.dat\n",
119
- "├── dir1\n",
120
- "│ ├── .file1.2\n",
121
- "│ ├── dir1.1\n",
122
- "│ │ └── .file1.1.1\n",
123
- "│ ├── dir1.2\n",
124
- "│ │ └── file1.2.1\n",
125
- "│ └── file1.1\n",
126
- "└── dir2\n",
127
- " └── .file2.1\n",
128
- ].join)
129
- end
130
-
131
- it "renders directory with only dirs" do
132
- tree = within_dir(fixtures_path) do
133
- TTY::Tree.new('hidden_dir', only_dirs: true)
134
- end
135
-
136
- expect(tree.render).to eq([
137
- "hidden_dir\n",
138
- "├── dir1\n",
139
- "│ ├── dir1.1\n",
140
- "│ └── dir1.2\n",
141
- "└── dir2\n",
142
- ].join)
143
- end
144
-
145
- it "renders directory with only dirs including hidden ones" do
146
- tree = within_dir(fixtures_path) do
147
- TTY::Tree.new('hidden_dir', only_dirs: true, show_hidden: true)
148
- end
149
-
150
- expect(tree.render).to eq([
151
- "hidden_dir\n",
152
- "├── .with_dot\n",
153
- "├── dir1\n",
154
- "│ ├── dir1.1\n",
155
- "│ └── dir1.2\n",
156
- "└── dir2\n",
157
- ].join)
158
- end
159
-
160
- it "doesn't show dirs with files exceeding limit" do
161
- tree = within_dir(fixtures_path) do
162
- TTY::Tree.new('large_dir', file_limit: 4)
163
- end
164
-
165
- expect(tree.render).to eq([
166
- "large_dir\n",
167
- "├── huge_dir\n",
168
- "├── large1\n",
169
- "├── large2\n",
170
- "└── large3\n",
171
- ].join)
172
- end
173
- end
@@ -1,122 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- RSpec.describe TTY::Tree::HashWalker do
5
- it "walks hash data and collects nodes" do
6
- data = {
7
- dir1: [
8
- 'config.dat',
9
- { dir2: [
10
- { dir3: [ 'file3-1.txt' ] },
11
- 'file2-1.txt'
12
- ]
13
- },
14
- 'file1-1.txt',
15
- 'file1-2.txt'
16
- ]
17
- }
18
-
19
- walker = TTY::Tree::HashWalker.new
20
-
21
- walker.traverse(data)
22
-
23
- expect(walker.nodes).to eq([
24
- TTY::Tree::Node.new('dir1', '', '', 0),
25
- TTY::Tree::Node.new('config.dat', 'dir1', '', 1),
26
- TTY::Tree::Node.new('dir2', 'dir1', '', 1),
27
- TTY::Tree::Node.new('dir3', 'dir1/dir2', ':pipe', 2),
28
- TTY::Tree::LeafNode.new('file3-1.txt', 'dir1/dir2/dir3', ':pipe:pipe', 3),
29
- TTY::Tree::LeafNode.new('file2-1.txt', 'dir1/dir2', ':pipe', 2),
30
- TTY::Tree::Node.new('file1-1.txt', 'dir1', '', 1),
31
- TTY::Tree::LeafNode.new('file1-2.txt', 'dir1', '', 1),
32
- ])
33
-
34
- expect(walker.nodes.map(&:full_path).map(&:to_s)).to eq([
35
- "dir1",
36
- "dir1/config.dat",
37
- "dir1/dir2",
38
- "dir1/dir2/dir3",
39
- "dir1/dir2/dir3/file3-1.txt",
40
- "dir1/dir2/file2-1.txt",
41
- "dir1/file1-1.txt",
42
- "dir1/file1-2.txt",
43
- ])
44
- end
45
-
46
- it "walks path tree and collects nodes up to max level" do
47
- data = {
48
- dir1: [
49
- 'config.dat',
50
- { dir2: [
51
- { dir3: [ 'file3-1.txt' ] },
52
- 'file2-1.txt'
53
- ]
54
- },
55
- 'file1-1.txt',
56
- 'file1-2.txt'
57
- ]
58
- }
59
-
60
- walker = TTY::Tree::HashWalker.new(level: 2)
61
-
62
- walker.traverse(data)
63
-
64
- expect(walker.nodes.map(&:full_path).map(&:to_s)).to eq([
65
- "dir1",
66
- "dir1/config.dat",
67
- "dir1/dir2",
68
- "dir1/dir2/file2-1.txt",
69
- "dir1/file1-1.txt",
70
- "dir1/file1-2.txt",
71
- ])
72
- end
73
-
74
- it "doesn't walks path tree exceeding file limit" do
75
- data = {
76
- orphan_dir: [
77
- 'a.txt',
78
- 'b.txt',
79
- { data: [
80
- 'data1.bin',
81
- 'data2.sql',
82
- 'data3.inf',
83
- 'data4.csv'
84
- ]
85
- }
86
- ]
87
- }
88
-
89
- walker = TTY::Tree::HashWalker.new(file_limit: 3)
90
-
91
- walker.traverse(data)
92
-
93
- expect(walker.nodes.map(&:full_path).map(&:to_s)).to eq([
94
- "orphan_dir",
95
- "orphan_dir/a.txt",
96
- "orphan_dir/b.txt",
97
- "orphan_dir/data"
98
- ])
99
- end
100
-
101
- it "counts files & dirs" do
102
- data = {
103
- dir1: [
104
- 'config.dat',
105
- { dir2: [
106
- { dir3: [ 'file3-1.txt' ] },
107
- 'file2-1.txt'
108
- ]
109
- },
110
- 'file1-1.txt',
111
- 'file1-2.txt'
112
- ]
113
- }
114
- walker = TTY::Tree::HashWalker.new
115
-
116
- walker.traverse(data)
117
-
118
- expect(walker.files_count).to eq(5)
119
-
120
- expect(walker.dirs_count).to eq(2)
121
- end
122
- end
@@ -1,85 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- RSpec.describe TTY::Tree, '#new' do
5
- it "exposes [] as instance creation & accepts Dir" do
6
- tree = TTY::Tree[::File.join(Dir.pwd, 'lib')]
7
-
8
- expect(tree.nodes).to_not be_empty
9
- end
10
-
11
- it "exposes [] as instance creation & accepts Pathname" do
12
- tree = TTY::Tree[Pathname.pwd.join('lib')]
13
-
14
- expect(tree.nodes).to_not be_empty
15
- end
16
-
17
- it "provides DSL for creating tree" do
18
- tree = TTY::Tree.new do
19
- node 'dir1' do
20
- node 'config.dat'
21
- node 'dir2' do
22
- node 'dir3' do
23
- leaf 'file3-1.txt'
24
- end
25
- leaf 'file2-1.txt'
26
- end
27
- node 'file1-1.txt'
28
- leaf 'file1-2.txt'
29
- end
30
- end
31
-
32
- expect(tree.nodes).to eq([
33
- TTY::Tree::Node.new('dir1', '', '', 0),
34
- TTY::Tree::Node.new('config.dat', 'dir1', '', 1),
35
- TTY::Tree::Node.new('dir2', 'dir1', '', 1),
36
- TTY::Tree::Node.new('dir3', 'dir1/dir2', ':pipe', 2),
37
- TTY::Tree::LeafNode.new('file3-1.txt', 'dir1/dir2/dir3', ':pipe:pipe', 3),
38
- TTY::Tree::LeafNode.new('file2-1.txt', 'dir1/dir2', ':pipe', 2),
39
- TTY::Tree::Node.new('file1-1.txt', 'dir1', '', 1),
40
- TTY::Tree::LeafNode.new('file1-2.txt', 'dir1', '', 1),
41
- ])
42
- end
43
-
44
- it "provides DSL for creating orphaned tree" do
45
- tree = TTY::Tree.new do
46
- node 'orphan_dir' do
47
- node 'a.txt'
48
- node 'b.txt'
49
- leaf 'data' do
50
- node 'data1.bin'
51
- node 'data2.sql'
52
- leaf 'data3.inf'
53
- end
54
- end
55
- end
56
-
57
- expect(tree.nodes).to eq([
58
- TTY::Tree::Node.new("orphan_dir", '', '', 0),
59
- TTY::Tree::Node.new("a.txt", 'orphan_dir', '', 1),
60
- TTY::Tree::Node.new("b.txt", 'orphan_dir', '', 1),
61
- TTY::Tree::LeafNode.new("data", 'orphan_dir', '', 1),
62
- TTY::Tree::Node.new("data1.bin", 'orphan_dir/data', ':space', 2),
63
- TTY::Tree::Node.new("data2.sql", 'orphan_dir/data', ':space', 2),
64
- TTY::Tree::LeafNode.new("data3.inf", 'orphan_dir/data', ':space', 2)
65
- ])
66
- end
67
-
68
- it "yields current node to DSL tree node" do
69
- yielded = []
70
-
71
- TTY::Tree.new do
72
- node 'dir1' do |dir1|
73
- yielded << dir1
74
- node 'dir2' do |dir2|
75
- yielded << dir2
76
- end
77
- end
78
- end
79
-
80
- expect(yielded).to eq([
81
- TTY::Tree::Node.new("dir1", '', '', 0),
82
- TTY::Tree::Node.new("dir2", 'dir1', '', 1)
83
- ])
84
- end
85
- end
@@ -1,42 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- RSpec.describe TTY::Tree::Node do
5
- it "provides directory stats" do
6
- dir = fixtures_path('dir1')
7
- node = TTY::Tree::Node.new(dir, '', '', 0)
8
-
9
- expect(node.directory?).to eq(true)
10
- expect(node.file?).to eq(false)
11
- expect(node.symlink?).to eq(false)
12
- expect(node.socket?).to eq(false)
13
- expect(node.pipe?).to eq(false)
14
- end
15
-
16
- it "informs if node is hidden" do
17
- file = fixtures_path('hidden', 'dir1', '.file1.2')
18
- node = TTY::Tree::Node.new(file, '', '', 0)
19
-
20
- expect(node.hidden?).to eq(true)
21
- end
22
-
23
- it "compares two nodes for equality" do
24
- node_a = TTY::Tree::Node.new('dir1', '', '', 0)
25
- node_b = TTY::Tree::Node.new('dir1', '', '', 0)
26
-
27
- expect(node_a).to eq(node_b)
28
- end
29
-
30
- it "compares two nodes for inequlity" do
31
- node_a = TTY::Tree::Node.new('dir1', '', '', 0)
32
- node_b = TTY::Tree::Node.new('dir2', '', '', 0)
33
-
34
- expect(node_a).to_not eq(node_b)
35
- end
36
-
37
- it "strips null bytes from pathname" do
38
- node = nil
39
- expect {node = TTY::Tree::Node.new("dir1\0", '', '', 0)}.not_to raise_error
40
- expect(node.path.to_s).to eq('dir1')
41
- end
42
- end
@@ -1,65 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Tree::NumberRenderer do
4
- it "renders directory as numbers" do
5
- tree = within_dir(fixtures_path) do
6
- TTY::Tree.new('dir1')
7
- end
8
-
9
- expect(tree.render(as: :number)).to eq([
10
- "dir1\n",
11
- "1.1 config.dat\n",
12
- "1.2 dir2\n",
13
- " 2.3 dir3\n",
14
- " 3.4 file3-1.txt\n",
15
- " 2.5 file2-1.txt\n",
16
- "1.6 file1-1.txt\n",
17
- "1.7 file1-2.txt\n",
18
- ].join)
19
- end
20
-
21
- it "renders hash data as numbers" do
22
- data = {
23
- dir1: [
24
- 'config.dat',
25
- { dir2: [
26
- { dir3: [ 'file3-1.txt' ] },
27
- 'file2-1.txt'
28
- ]
29
- },
30
- 'file1-1.txt',
31
- 'file1-2.txt'
32
- ]
33
- }
34
-
35
- tree = TTY::Tree.new(data)
36
-
37
- expect(tree.render(as: :number)).to eq([
38
- "dir1\n",
39
- "1.1 config.dat\n",
40
- "1.2 dir2\n",
41
- " 2.3 dir3\n",
42
- " 3.4 file3-1.txt\n",
43
- " 2.5 file2-1.txt\n",
44
- "1.6 file1-1.txt\n",
45
- "1.7 file1-2.txt\n",
46
- ].join)
47
- end
48
-
49
- it "renders directory as numbers without indentation" do
50
- tree = within_dir(fixtures_path) do
51
- TTY::Tree.new('dir1')
52
- end
53
-
54
- expect(tree.render(as: :number, indent: 0)).to eq([
55
- "dir1\n",
56
- "1.1 config.dat\n",
57
- "1.2 dir2\n",
58
- "2.3 dir3\n",
59
- "3.4 file3-1.txt\n",
60
- "2.5 file2-1.txt\n",
61
- "1.6 file1-1.txt\n",
62
- "1.7 file1-2.txt\n",
63
- ].join)
64
- end
65
- end
@@ -1,127 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- RSpec.describe TTY::Tree::PathWalker do
5
- it "walks path tree and collects nodes" do
6
- walker = TTY::Tree::PathWalker.new
7
-
8
- within_dir(fixtures_path) do
9
- walker.traverse('dir1')
10
- end
11
-
12
- expect(walker.nodes).to eq([
13
- TTY::Tree::Node.new('dir1', '', '', 0),
14
- TTY::Tree::Node.new('dir1/config.dat', 'dir1', '', 1),
15
- TTY::Tree::Node.new('dir2', 'dir1', '', 1),
16
- TTY::Tree::Node.new('dir3', 'dir1/dir2', ':pipe', 2),
17
- TTY::Tree::LeafNode.new('dir1/dir2/dir3/file3-1.txt', 'dir1/dir2/dir3', ':pipe:pipe', 3),
18
- TTY::Tree::LeafNode.new('dir1/dir2/file2-1.txt', 'dir1/dir2', ':pipe', 2),
19
- TTY::Tree::Node.new('dir1/file1-1.txt', 'dir1', '', 1),
20
- TTY::Tree::LeafNode.new('dir1/file1-2.txt', 'dir1', '', 1),
21
- ])
22
-
23
- expect(walker.nodes.map(&:full_path).map(&:to_s)).to eq([
24
- "dir1",
25
- "dir1/config.dat",
26
- "dir1/dir2",
27
- "dir1/dir2/dir3",
28
- "dir1/dir2/dir3/file3-1.txt",
29
- "dir1/dir2/file2-1.txt",
30
- "dir1/file1-1.txt",
31
- "dir1/file1-2.txt",
32
- ])
33
- end
34
-
35
- it "walks orphaned path tree and collects nodes" do
36
- walker = TTY::Tree::PathWalker.new
37
-
38
- within_dir(fixtures_path) do
39
- walker.traverse('orphan_dir')
40
- end
41
-
42
- expect(walker.nodes).to eq([
43
- TTY::Tree::Node.new("orphan_dir", '', '', 0),
44
- TTY::Tree::Node.new("orphan_dir/a.txt", 'orphan_dir', '', 1),
45
- TTY::Tree::Node.new("orphan_dir/b.txt", 'orphan_dir', '', 1),
46
- TTY::Tree::LeafNode.new("data", 'orphan_dir', '', 1),
47
- TTY::Tree::Node.new("orphan_dir/data/data1.bin", 'orphan_dir/data', ':space', 2),
48
- TTY::Tree::Node.new("orphan_dir/data/data2.sql", 'orphan_dir/data', ':space', 2),
49
- TTY::Tree::LeafNode.new("orphan_dir/data/data3.inf", 'orphan_dir/data', ':space', 2)
50
- ])
51
-
52
- expect(walker.nodes.map(&:full_path).map(&:to_s)).to eq([
53
- "orphan_dir",
54
- "orphan_dir/a.txt",
55
- "orphan_dir/b.txt",
56
- "orphan_dir/data",
57
- "orphan_dir/data/data1.bin",
58
- "orphan_dir/data/data2.sql",
59
- "orphan_dir/data/data3.inf"
60
- ])
61
- end
62
-
63
- it "walks path tree and collects nodes limited by the level" do
64
- walker = TTY::Tree::PathWalker.new(level: 2)
65
-
66
- within_dir(fixtures_path) do
67
- walker.traverse('dir1')
68
- end
69
-
70
- expect(walker.nodes.map(&:full_path).map(&:to_s)).to eq([
71
- "dir1",
72
- "dir1/config.dat",
73
- "dir1/dir2",
74
- "dir1/dir2/file2-1.txt",
75
- "dir1/file1-1.txt",
76
- "dir1/file1-2.txt",
77
- ])
78
- end
79
-
80
- it "doesn't walk paths exceeding file limit" do
81
- walker = TTY::Tree::PathWalker.new(file_limit: 4)
82
-
83
- within_dir(fixtures_path) do
84
- walker.traverse('large_dir')
85
- end
86
-
87
- expect(walker.nodes.map(&:full_path).map(&:to_s)).to eq([
88
- "large_dir",
89
- "large_dir/huge_dir",
90
- "large_dir/large1",
91
- "large_dir/large2",
92
- "large_dir/large3"
93
- ])
94
- end
95
-
96
- it "counts files & dirs" do
97
- walker = TTY::Tree::PathWalker.new
98
-
99
- within_dir(fixtures_path) do
100
- walker.traverse('dir1')
101
- end
102
-
103
- expect(walker.files_count).to eq(5)
104
-
105
- expect(walker.dirs_count).to eq(2)
106
- end
107
-
108
- it "counts files & dirs including max level limit" do
109
- walker = TTY::Tree::PathWalker.new(level: 2)
110
-
111
- within_dir(fixtures_path) do
112
- walker.traverse('dir1')
113
- end
114
-
115
- expect(walker.files_count).to eq(4)
116
-
117
- expect(walker.dirs_count).to eq(1)
118
- end
119
-
120
- it "raises when walking non-directory" do
121
- walker = TTY::Tree::PathWalker.new
122
-
123
- expect {
124
- walker.traverse('unknown-dir')
125
- }.to raise_error(ArgumentError, /unknown-dir is not a directory path/)
126
- end
127
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Load gem inside irb console'
4
- task :console do
5
- require 'irb'
6
- require 'irb/completion'
7
- require File.join(__FILE__, '../../lib/tty-prompt')
8
- ARGV.clear
9
- IRB.start
10
- end
11
- task c: %w[ console ]
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Measure code coverage'
4
- task :coverage do
5
- begin
6
- original, ENV['COVERAGE'] = ENV['COVERAGE'], 'true'
7
- Rake::Task['spec'].invoke
8
- ensure
9
- ENV['COVERAGE'] = original
10
- end
11
- end
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
-
3
- begin
4
- require 'rspec/core/rake_task'
5
-
6
- desc 'Run all specs'
7
- RSpec::Core::RakeTask.new(:spec) do |task|
8
- task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
9
- end
10
-
11
- namespace :spec do
12
- desc 'Run unit specs'
13
- RSpec::Core::RakeTask.new(:unit) do |task|
14
- task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
15
- end
16
-
17
- desc 'Run integration specs'
18
- RSpec::Core::RakeTask.new(:integration) do |task|
19
- task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
20
- end
21
- end
22
-
23
- rescue LoadError
24
- %w[spec spec:unit spec:integration].each do |name|
25
- task name do
26
- $stderr.puts "In order to run #{name}, do `gem install rspec`"
27
- end
28
- end
29
- end
@@ -1,27 +0,0 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'tty/tree/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "tty-tree"
7
- spec.version = TTY::Tree::VERSION
8
- spec.authors = ["Piotr Murach"]
9
- spec.email = ["me@piotrmurach.com"]
10
-
11
- spec.summary = %q{Print directory or structured data in a tree like format.}
12
- spec.description = %q{Print directory or structured data in a tree like format.}
13
- spec.homepage = "https://piotrmurach.github.io/tty"
14
- spec.license = "MIT"
15
-
16
- spec.files = Dir['{lib,spec}/**/*.rb', '{bin,tasks}/*', 'tty-tree.gemspec']
17
- spec.files += Dir['README.md', 'CHANGELOG.md', 'LICENSE.txt', 'Rakefile']
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
-
22
- spec.required_ruby_version = '>= 2.0.0'
23
-
24
- spec.add_development_dependency "bundler", ">= 1.14.0"
25
- spec.add_development_dependency "rake"
26
- spec.add_development_dependency "rspec", "~> 3.0"
27
- end