dev_suite 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +31 -0
- data/lib/dev_suite/directory_tree/node/base.rb +19 -0
- data/lib/dev_suite/directory_tree/node/directory.rb +26 -0
- data/lib/dev_suite/directory_tree/node/file.rb +15 -0
- data/lib/dev_suite/directory_tree/node/permission_denied.rb +25 -0
- data/lib/dev_suite/directory_tree/node.rb +11 -0
- data/lib/dev_suite/directory_tree/renderer/base.rb +38 -0
- data/lib/dev_suite/directory_tree/renderer/simple.rb +61 -0
- data/lib/dev_suite/directory_tree/renderer.rb +9 -0
- data/lib/dev_suite/directory_tree/visualizer.rb +26 -0
- data/lib/dev_suite/directory_tree.rb +7 -0
- data/lib/dev_suite/performance/reportor/base.rb +2 -0
- data/lib/dev_suite/version.rb +1 -1
- data/lib/dev_suite.rb +1 -0
- metadata +11 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b962be05b7f06443a5620effcba37759712b4a930654f28782280bdcfb975698
|
4
|
+
data.tar.gz: 3d3987ce785c0211d279a382fcd0dace11ce3e66861629b613e1857ddf9064c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5cc89b151a1224cd7fa29c65c05a0d873e400585ad949e5f5b6278bb23aacfda90367036372f659f5596e948217b63cc00a71c71cfcc1a20fe4c72076227257
|
7
|
+
data.tar.gz: 13998cef95d7658837462bb319f5af0664302eeeb54168fc1fe0c9049f3f287df8887665d27eaf69009789cac71541b3d0e457d3f456ce2af35557d2832b2248
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -80,6 +80,37 @@ DevSuite::SomeUtility.do_something
|
|
80
80
|
```
|
81
81
|
</details>
|
82
82
|
|
83
|
+
<details>
|
84
|
+
<summary><strong>Directory Tree Visualization</strong></summary>
|
85
|
+
|
86
|
+
Visualize the structure of directories and their subdirectories with a detailed hierarchical representation. This tool is essential for understanding the organization of your files and directories at a glance.
|
87
|
+
|
88
|
+
**Usage:**
|
89
|
+
```ruby
|
90
|
+
require 'dev_suite'
|
91
|
+
|
92
|
+
# Set the base path for the directory you want to visualize
|
93
|
+
base_path = "/path/to/your/directory"
|
94
|
+
|
95
|
+
# Perform the visualization
|
96
|
+
DevSuite::DirectoryTree::Visualizer.visualize(base_path)
|
97
|
+
```
|
98
|
+
|
99
|
+
**Example output**
|
100
|
+
```
|
101
|
+
/path/to/your/directory/
|
102
|
+
├── project/
|
103
|
+
│ ├── src/
|
104
|
+
│ │ ├── main.rb
|
105
|
+
│ │ └── helper.rb
|
106
|
+
│ └── spec/
|
107
|
+
│ └── main_spec.rb
|
108
|
+
├── doc/
|
109
|
+
│ └── README.md
|
110
|
+
└── test/
|
111
|
+
└── test_helper.rb
|
112
|
+
```
|
113
|
+
</details>
|
83
114
|
|
84
115
|
## Development
|
85
116
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module DirectoryTree
|
5
|
+
module Node
|
6
|
+
class Base
|
7
|
+
attr_reader :name
|
8
|
+
|
9
|
+
def initialize(name)
|
10
|
+
@name = name
|
11
|
+
end
|
12
|
+
|
13
|
+
def directory?
|
14
|
+
raise NotImplementedError, "Must implement in subclass"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module DevSuite
|
6
|
+
module DirectoryTree
|
7
|
+
module Node
|
8
|
+
class Directory < Base
|
9
|
+
attr_reader :children
|
10
|
+
|
11
|
+
def initialize(name)
|
12
|
+
super
|
13
|
+
@children = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def directory?
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_child(child)
|
21
|
+
@children << child
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module DevSuite
|
6
|
+
module DirectoryTree
|
7
|
+
module Node
|
8
|
+
class PermissionDenied < Base
|
9
|
+
# This class is used to represent a file or directory that the user does not have permission to access.
|
10
|
+
def initialize(name, is_directory)
|
11
|
+
super(name)
|
12
|
+
@is_directory = is_directory
|
13
|
+
end
|
14
|
+
|
15
|
+
def directory?
|
16
|
+
@is_directory
|
17
|
+
end
|
18
|
+
|
19
|
+
def children
|
20
|
+
[]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
module DevSuite
|
6
|
+
module DirectoryTree
|
7
|
+
module Renderer
|
8
|
+
class Base
|
9
|
+
def initialize(base_path)
|
10
|
+
@base_path = Pathname.new(base_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def render
|
14
|
+
root = build_tree(@base_path)
|
15
|
+
render_node(root, "", true)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# Builds the tree structure
|
21
|
+
# @param path [Pathname] The path to build the tree from
|
22
|
+
# @return [Node::Base] The root node of the tree
|
23
|
+
def build_tree(path)
|
24
|
+
raise NotImplementedError, "You must implement the build_tree method"
|
25
|
+
end
|
26
|
+
|
27
|
+
# Renders a node in the tree
|
28
|
+
# @param node [Node::Base] The node to render
|
29
|
+
# @param prefix [String] The prefix to add to the node
|
30
|
+
# @param is_last [Boolean] Whether this is the last node in the list
|
31
|
+
# @return [String] The rendered node
|
32
|
+
def render_node(node, prefix, is_last)
|
33
|
+
raise NotImplementedError, "You must implement the render_node method"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
require_relative "../node"
|
5
|
+
|
6
|
+
module DevSuite
|
7
|
+
module DirectoryTree
|
8
|
+
module Renderer
|
9
|
+
class Simple < Base
|
10
|
+
private
|
11
|
+
|
12
|
+
def build_tree(path)
|
13
|
+
return Node::PermissionDenied.new(path.basename.to_s, path.directory?) unless path.readable?
|
14
|
+
|
15
|
+
if path.directory?
|
16
|
+
dir = Node::Directory.new(path.basename.to_s)
|
17
|
+
children = path.children.sort_by { |child| child.basename.to_s.downcase }
|
18
|
+
children.each do |child|
|
19
|
+
dir.add_child(build_tree(child))
|
20
|
+
end
|
21
|
+
dir
|
22
|
+
else
|
23
|
+
Node::File.new(path.basename.to_s)
|
24
|
+
end
|
25
|
+
rescue Errno::EACCES
|
26
|
+
Node::PermissionDenied.new(path.basename.to_s, path.directory?)
|
27
|
+
end
|
28
|
+
|
29
|
+
def render_node(node, prefix = "", is_last = true)
|
30
|
+
# Determine if this is the root node based on the prefix content
|
31
|
+
is_root = prefix.empty?
|
32
|
+
|
33
|
+
# Prepare the connector appropriately, omitting it for the root
|
34
|
+
connector = if is_root
|
35
|
+
""
|
36
|
+
else
|
37
|
+
(is_last ? "└── " : "├── ")
|
38
|
+
end
|
39
|
+
|
40
|
+
# Compute the new prefix for children
|
41
|
+
new_prefix = "#{prefix}#{is_last ? " " : "| "}"
|
42
|
+
|
43
|
+
# Construct the output for the current node, avoiding the connector for the root
|
44
|
+
output = "#{prefix}#{connector}#{node.name}"
|
45
|
+
output += "/\n" if node.directory?
|
46
|
+
|
47
|
+
# Recursively render children if it's a directory
|
48
|
+
if node.directory? && node.children.any?
|
49
|
+
node.children.each_with_index do |child, index|
|
50
|
+
output += render_node(child, new_prefix, index == node.children.size - 1)
|
51
|
+
end
|
52
|
+
elsif !node.directory?
|
53
|
+
output += "\n"
|
54
|
+
end
|
55
|
+
|
56
|
+
output
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
require_relative "renderer"
|
5
|
+
|
6
|
+
module DevSuite
|
7
|
+
module DirectoryTree
|
8
|
+
class Visualizer
|
9
|
+
class << self
|
10
|
+
# Visualizes the directory tree
|
11
|
+
# @param base_path [String] The base path of the directory
|
12
|
+
def visualize(base_path)
|
13
|
+
new(base_path).visualize
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(base_path, renderer: Renderer::Simple.new(base_path))
|
18
|
+
@renderer = renderer
|
19
|
+
end
|
20
|
+
|
21
|
+
def visualize
|
22
|
+
puts @renderer.render
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/dev_suite/version.rb
CHANGED
data/lib/dev_suite.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev_suite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Huy Nguyen
|
@@ -61,6 +61,16 @@ files:
|
|
61
61
|
- bin/setup
|
62
62
|
- dev_suite.gemspec
|
63
63
|
- lib/dev_suite.rb
|
64
|
+
- lib/dev_suite/directory_tree.rb
|
65
|
+
- lib/dev_suite/directory_tree/node.rb
|
66
|
+
- lib/dev_suite/directory_tree/node/base.rb
|
67
|
+
- lib/dev_suite/directory_tree/node/directory.rb
|
68
|
+
- lib/dev_suite/directory_tree/node/file.rb
|
69
|
+
- lib/dev_suite/directory_tree/node/permission_denied.rb
|
70
|
+
- lib/dev_suite/directory_tree/renderer.rb
|
71
|
+
- lib/dev_suite/directory_tree/renderer/base.rb
|
72
|
+
- lib/dev_suite/directory_tree/renderer/simple.rb
|
73
|
+
- lib/dev_suite/directory_tree/visualizer.rb
|
64
74
|
- lib/dev_suite/performance.rb
|
65
75
|
- lib/dev_suite/performance/analyzer.rb
|
66
76
|
- lib/dev_suite/performance/data.rb
|