dev_suite 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +37 -0
- data/Gemfile +11 -6
- data/Gemfile.lock +15 -3
- data/README.md +69 -46
- data/dev_suite.gemspec +7 -1
- data/exe/devsuite +6 -0
- data/lib/dev_suite/cli/commands/base.rb +16 -0
- data/lib/dev_suite/cli/commands/tree.rb +42 -0
- data/lib/dev_suite/cli/commands/version.rb +13 -0
- data/lib/dev_suite/cli/commands.rb +11 -0
- data/lib/dev_suite/cli/main.rb +32 -0
- data/lib/dev_suite/cli.rb +12 -0
- data/lib/dev_suite/directory_tree/config.rb +31 -6
- data/lib/dev_suite/directory_tree/directory_tree.rb +21 -0
- data/lib/dev_suite/directory_tree/renderer/simple.rb +3 -3
- data/lib/dev_suite/directory_tree/settings.rb +1 -12
- data/lib/dev_suite/directory_tree/visualizer/base.rb +13 -0
- data/lib/dev_suite/directory_tree/visualizer/tree.rb +50 -0
- data/lib/dev_suite/directory_tree/visualizer.rb +14 -13
- data/lib/dev_suite/directory_tree.rb +1 -8
- data/lib/dev_suite/emoji.rb +33 -0
- data/lib/dev_suite/error_handler.rb +22 -0
- data/lib/dev_suite/logger.rb +56 -0
- data/lib/dev_suite/performance/analyzer.rb +6 -23
- data/lib/dev_suite/performance/config.rb +25 -4
- data/lib/dev_suite/performance/profiler/execution_time.rb +29 -0
- data/lib/dev_suite/performance/profiler/memory.rb +20 -14
- data/lib/dev_suite/performance/profiler.rb +18 -1
- data/lib/dev_suite/performance/profiler_manager.rb +55 -0
- data/lib/dev_suite/performance/reportor/helpers/stat_mappings.rb +40 -0
- data/lib/dev_suite/performance/reportor/helpers/table_builder.rb +47 -0
- data/lib/dev_suite/performance/reportor/helpers.rb +12 -0
- data/lib/dev_suite/performance/reportor/simple.rb +7 -61
- data/lib/dev_suite/performance/reportor.rb +1 -0
- data/lib/dev_suite/performance.rb +1 -0
- data/lib/dev_suite/utils/config_tools/configuration.rb +103 -10
- data/lib/dev_suite/utils/config_tools/settings.rb +0 -8
- data/lib/dev_suite/version.rb +1 -1
- data/lib/dev_suite.rb +9 -6
- metadata +67 -6
- data/lib/dev_suite/performance/profiler/benchmark.rb +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6765c4b9fa4637dafaac36da47cd8adf18652cd0d38804ddcd8641b851669f12
|
|
4
|
+
data.tar.gz: 3a3b27ad8b9fa4319829175995b1d6ea999e9877d537b1316b531247d6bd4b53
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c2c9a91ccdfe89d997d66e8441d0b130dacc9edeb5fae6a3f949f1e25ff9aec09c41603597dbc7e017e9e3857c838e88182e4b670c220ea376d28934eb45c6e4
|
|
7
|
+
data.tar.gz: 4f2e69b97a36b68eb84d2c808ede9072b6f333aebe7f2049d16dc7c55e99592604e9e7234b36471d8d84208fec05cfa27b8ce9b942e93d566159209d7fe652d2
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
test:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
|
|
11
|
+
steps:
|
|
12
|
+
- name: Check out code
|
|
13
|
+
uses: actions/checkout@v2
|
|
14
|
+
|
|
15
|
+
- name: Set up Ruby
|
|
16
|
+
uses: ruby/setup-ruby@v1
|
|
17
|
+
with:
|
|
18
|
+
ruby-version: 3.0 # Specify your project's Ruby version
|
|
19
|
+
|
|
20
|
+
- name: Install dependencies
|
|
21
|
+
run: bundle install
|
|
22
|
+
|
|
23
|
+
- name: Run tests
|
|
24
|
+
env:
|
|
25
|
+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
|
26
|
+
run: |
|
|
27
|
+
bundle exec rspec
|
|
28
|
+
|
|
29
|
+
- name: Upload coverage to Code Climate
|
|
30
|
+
env:
|
|
31
|
+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
|
32
|
+
run: |
|
|
33
|
+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
|
34
|
+
chmod +x ./cc-test-reporter
|
|
35
|
+
./cc-test-reporter before-build
|
|
36
|
+
bundle exec rspec
|
|
37
|
+
./cc-test-reporter after-build --exit-code $?
|
data/Gemfile
CHANGED
|
@@ -2,11 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# Use the gemspec method to include dependencies specified in the gemspec file
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
gem "
|
|
11
|
-
gem "
|
|
12
|
-
|
|
8
|
+
# Additional development tools not required as part of the gem's runtime
|
|
9
|
+
group :development, :test do
|
|
10
|
+
gem "rake", "~> 13.0"
|
|
11
|
+
gem "pry", "~> 0.14"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
group :development do
|
|
15
|
+
gem "rubocop", "~> 1.65", require: false
|
|
16
|
+
gem "rubocop-shopify", "~> 2.15", require: false
|
|
17
|
+
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
dev_suite (0.2.
|
|
4
|
+
dev_suite (0.2.4)
|
|
5
5
|
benchmark (~> 0.1)
|
|
6
|
-
get_process_mem (~> 0
|
|
6
|
+
get_process_mem (~> 1.0)
|
|
7
|
+
thor (~> 1.1)
|
|
7
8
|
|
|
8
9
|
GEM
|
|
9
10
|
remote: https://rubygems.org/
|
|
10
11
|
specs:
|
|
11
12
|
ast (2.4.2)
|
|
12
13
|
benchmark (0.3.0)
|
|
14
|
+
bigdecimal (3.1.8)
|
|
13
15
|
coderay (1.1.3)
|
|
14
16
|
diff-lcs (1.5.1)
|
|
17
|
+
docile (1.4.1)
|
|
15
18
|
ffi (1.17.0)
|
|
16
19
|
ffi (1.17.0-aarch64-linux-gnu)
|
|
17
20
|
ffi (1.17.0-aarch64-linux-musl)
|
|
@@ -23,7 +26,8 @@ GEM
|
|
|
23
26
|
ffi (1.17.0-x86_64-darwin)
|
|
24
27
|
ffi (1.17.0-x86_64-linux-gnu)
|
|
25
28
|
ffi (1.17.0-x86_64-linux-musl)
|
|
26
|
-
get_process_mem (0.
|
|
29
|
+
get_process_mem (1.0.0)
|
|
30
|
+
bigdecimal (>= 2.0)
|
|
27
31
|
ffi (~> 1.0)
|
|
28
32
|
json (2.7.2)
|
|
29
33
|
language_server-protocol (3.17.0.3)
|
|
@@ -70,7 +74,14 @@ GEM
|
|
|
70
74
|
rubocop-shopify (2.15.1)
|
|
71
75
|
rubocop (~> 1.51)
|
|
72
76
|
ruby-progressbar (1.13.0)
|
|
77
|
+
simplecov (0.22.0)
|
|
78
|
+
docile (~> 1.1)
|
|
79
|
+
simplecov-html (~> 0.11)
|
|
80
|
+
simplecov_json_formatter (~> 0.1)
|
|
81
|
+
simplecov-html (0.12.3)
|
|
82
|
+
simplecov_json_formatter (0.1.4)
|
|
73
83
|
strscan (3.1.0)
|
|
84
|
+
thor (1.3.1)
|
|
74
85
|
unicode-display_width (2.5.0)
|
|
75
86
|
|
|
76
87
|
PLATFORMS
|
|
@@ -93,6 +104,7 @@ DEPENDENCIES
|
|
|
93
104
|
rspec (~> 3.9)
|
|
94
105
|
rubocop (~> 1.65)
|
|
95
106
|
rubocop-shopify (~> 2.15)
|
|
107
|
+
simplecov (~> 0.21)
|
|
96
108
|
|
|
97
109
|
BUNDLED WITH
|
|
98
110
|
2.5.17
|
data/README.md
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
# DevSuite
|
|
2
2
|
|
|
3
|
-
[](https://rubygems.org/gems/dev_suite)
|
|
4
|
+
[](https://rubygems.org/gems/dev_suite)
|
|
5
|
+
[](https://codeclimate.com/github/patrick204nqh/dev_suite/maintainability)
|
|
6
|
+
[](https://codeclimate.com/github/patrick204nqh/dev_suite/test_coverage)
|
|
7
|
+
[](https://sonarcloud.io/summary/overall?id=patrick204nqh_dev_suite)
|
|
8
|
+
[](https://depfu.com/github/patrick204nqh/dev_suite?project_id=44065)
|
|
9
|
+
[](https://snyk.io/test/github/patrick204nqh/dev_suite)
|
|
5
10
|
|
|
6
11
|
Welcome to DevSuite! This gem provides a suite of utilities for developers to enhance their productivity.
|
|
7
12
|
|
|
@@ -40,82 +45,100 @@ require 'dev_suite'
|
|
|
40
45
|
DevSuite::SomeUtility.do_something
|
|
41
46
|
```
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
### CLI Commands
|
|
44
49
|
|
|
50
|
+
DevSuite also provides a command-line interface for various utilities. Below are some general commands:
|
|
51
|
+
|
|
52
|
+
| Command | Description |
|
|
53
|
+
|--------------------|-------------------------------------|
|
|
54
|
+
| `devsuite version` | Displays the version of DevSuite |
|
|
55
|
+
| `devsuite help` | Shows help information for commands |
|
|
56
|
+
|
|
57
|
+
## Features Overview
|
|
58
|
+
|
|
59
|
+
### Performance Analysis
|
|
45
60
|
<details>
|
|
46
|
-
<summary
|
|
47
|
-
|
|
48
|
-
Analyze the performance of your code blocks with detailed benchmark and memory usage reports.
|
|
61
|
+
<summary>Show more</summary>
|
|
49
62
|
|
|
50
|
-
**
|
|
63
|
+
**Purpose**: Quickly analyze the performance of Ruby code blocks, capturing metrics like execution time and memory usage.
|
|
64
|
+
|
|
65
|
+
**How to Use**:
|
|
51
66
|
```ruby
|
|
52
67
|
require 'dev_suite'
|
|
53
|
-
|
|
54
|
-
DevSuite::Performance.analyze(description: "
|
|
68
|
+
|
|
69
|
+
DevSuite::Performance.analyze(description: "Example Analysis") do
|
|
55
70
|
sum = 0
|
|
56
|
-
1_000_000.times
|
|
57
|
-
sum += i
|
|
58
|
-
end
|
|
71
|
+
1_000_000.times { |i| sum += i }
|
|
59
72
|
sum
|
|
60
73
|
end
|
|
61
74
|
```
|
|
62
75
|
|
|
63
|
-
**
|
|
76
|
+
**Sample Output**:
|
|
64
77
|
```
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
| Memory Before (MB) | 25.39 |
|
|
75
|
-
| Memory After (MB) | 25.42 |
|
|
76
|
-
| Memory Used (MB) | 0.03 |
|
|
77
|
-
| Max Memory Used (MB) | 25.41 |
|
|
78
|
-
| Min Memory Used (MB) | 25.41 |
|
|
79
|
-
| Avg Memory Used (MB) | 25.41 |
|
|
78
|
+
| Metric | Value |
|
|
79
|
+
|---------------------|------------------|
|
|
80
|
+
| Description | Example Analysis |
|
|
81
|
+
| Total Time (s) | 0.056238 |
|
|
82
|
+
| User CPU Time (s) | 0.055662 |
|
|
83
|
+
| System CPU Time (s) | 0.000097 |
|
|
84
|
+
| Memory Before (MB) | 25.39 |
|
|
85
|
+
| Memory After (MB) | 25.42 |
|
|
86
|
+
| Memory Used (MB) | 0.03 |
|
|
80
87
|
```
|
|
81
88
|
</details>
|
|
82
89
|
|
|
90
|
+
### Directory Tree Visualization
|
|
83
91
|
<details>
|
|
84
|
-
<summary
|
|
92
|
+
<summary>Show more</summary>
|
|
85
93
|
|
|
86
|
-
Visualize the structure of directories and
|
|
94
|
+
**Purpose**: Visualize the file structure of directories and subdirectories to better understand project organization.
|
|
87
95
|
|
|
88
|
-
**
|
|
96
|
+
**How to Use**:
|
|
89
97
|
```ruby
|
|
90
98
|
require 'dev_suite'
|
|
91
99
|
|
|
92
|
-
#
|
|
100
|
+
# Define the directory path
|
|
93
101
|
base_path = "/path/to/your/directory"
|
|
94
102
|
|
|
95
|
-
#
|
|
103
|
+
# Execute the visualization
|
|
96
104
|
DevSuite::DirectoryTree.visualize(base_path)
|
|
97
105
|
```
|
|
98
106
|
|
|
99
|
-
**
|
|
107
|
+
**CLI Command**:
|
|
108
|
+
DevSuite also provides a command-line interface for directory tree visualization. Use the following command to print the directory tree of the specified path:
|
|
100
109
|
|
|
110
|
+
```sh
|
|
111
|
+
$ devsuite tree [PATH] [OPTIONS]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**CLI Options**:
|
|
115
|
+
|
|
116
|
+
Below is a table describing the available options for the `devsuite tree` command:
|
|
117
|
+
|
|
118
|
+
| Option | Description | Example Usage |
|
|
119
|
+
|-----------------|--------------------------------------------------|------------------------------------------------|
|
|
120
|
+
| `--depth`, `-d` | Limit the depth of the directory tree displayed. | `$ devsuite tree /path --depth 2` |
|
|
121
|
+
| `--skip-hidden` | Skip hidden files and directories. | `$ devsuite tree /path --skip-hidden` |
|
|
122
|
+
| `--skip-types` | Exclude files of specific types. | `$ devsuite tree /path --skip-types .log .tmp` |
|
|
123
|
+
|
|
124
|
+
**Configuration Guide**:
|
|
125
|
+
Customize the visualization by setting configuration options:
|
|
101
126
|
```ruby
|
|
102
127
|
DevSuite::DirectoryTree::Config.configure do |config|
|
|
103
|
-
|
|
104
|
-
|
|
128
|
+
config.settings.set(:skip_hidden, true)
|
|
129
|
+
# ...
|
|
105
130
|
end
|
|
106
131
|
```
|
|
107
132
|
|
|
108
|
-
**
|
|
133
|
+
**Configuration Options**:
|
|
134
|
+
| Setting | Description | Example Values |
|
|
135
|
+
|----------------|---------------------------------------------------|--------------------------|
|
|
136
|
+
| `:skip_hidden` | Skips hidden files and directories. | `true`, `false` |
|
|
137
|
+
| `:max_depth` | Limits the depth of the directory tree displayed. | `1`, `2`, `3`, ... |
|
|
138
|
+
| `:skip_types` | Excludes files of specific types. | `['.log', '.tmp']`, `[]` |
|
|
109
139
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
| `:skip_hidden` | Skip hidden files and directories. | `true`, `false` |
|
|
113
|
-
| `:max_depth` | Limit the depth of the directory tree displayed. | `1`, `2`, `3`, ... |
|
|
114
|
-
| `:skip_types` | Exclude files of specific types. | `['.log', '.tmp']`, `[]` |
|
|
115
|
-
|
|
116
|
-
**Example output**
|
|
117
|
-
|
|
118
|
-
```bash
|
|
140
|
+
**Sample Output**:
|
|
141
|
+
```
|
|
119
142
|
/path/to/your/directory/
|
|
120
143
|
├── project/
|
|
121
144
|
│ ├── src/
|
data/dev_suite.gemspec
CHANGED
|
@@ -29,6 +29,12 @@ Gem::Specification.new do |spec|
|
|
|
29
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
30
30
|
spec.require_paths = ["lib"]
|
|
31
31
|
|
|
32
|
+
# Runtime dependencies
|
|
32
33
|
spec.add_dependency("benchmark", "~> 0.1")
|
|
33
|
-
spec.add_dependency("get_process_mem", "~> 0
|
|
34
|
+
spec.add_dependency("get_process_mem", "~> 1.0")
|
|
35
|
+
spec.add_dependency("thor", "~> 1.1")
|
|
36
|
+
|
|
37
|
+
# Development dependencies
|
|
38
|
+
spec.add_development_dependency("rspec", "~> 3.9")
|
|
39
|
+
spec.add_development_dependency("simplecov", "~> 0.21")
|
|
34
40
|
end
|
data/exe/devsuite
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DevSuite
|
|
4
|
+
module CLI
|
|
5
|
+
module Commands
|
|
6
|
+
class Tree < Base
|
|
7
|
+
desc "visualize PATH", "Visualize the directory structure at given PATH"
|
|
8
|
+
def execute(path, options: {})
|
|
9
|
+
Logger.log("Starting visualization for: #{path}", emoji: :start)
|
|
10
|
+
|
|
11
|
+
apply_configure(options)
|
|
12
|
+
visualize(path)
|
|
13
|
+
|
|
14
|
+
Logger.log("Visualization complete!", emoji: :success)
|
|
15
|
+
rescue StandardError => e
|
|
16
|
+
ErrorHandler.handle_error(e)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def visualize(path)
|
|
22
|
+
DirectoryTree.visualize(path)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def apply_configure(options)
|
|
26
|
+
option_config_mapping = {
|
|
27
|
+
depth: :max_depth,
|
|
28
|
+
skip_hidden: :skip_hidden,
|
|
29
|
+
skip_types: :skip_types,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
DirectoryTree::Config.configure do |config|
|
|
33
|
+
option_config_mapping.each do |option_key, config_key|
|
|
34
|
+
value = options[option_key]
|
|
35
|
+
config.settings.set(config_key, value) if value
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DevSuite
|
|
4
|
+
module CLI
|
|
5
|
+
class Main < Thor
|
|
6
|
+
desc "tree DIRECTORY", "Prints the directory tree"
|
|
7
|
+
method_option :depth, aliases: "-d", type: :numeric, desc: "Limit the depth of the directory tree displayed"
|
|
8
|
+
method_option :skip_hidden, type: :boolean, default: false, desc: "Skip hidden files and directories"
|
|
9
|
+
method_option :skip_types,
|
|
10
|
+
type: :array,
|
|
11
|
+
default: [],
|
|
12
|
+
banner: "TYPE1 TYPE2",
|
|
13
|
+
desc: "Exclude files of specific types"
|
|
14
|
+
def tree(path = ".")
|
|
15
|
+
execute_command(Commands::Tree, path, options: options)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
desc "version", "Displays the version of the dev_suite gem"
|
|
19
|
+
def version
|
|
20
|
+
execute_command(Commands::Version)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def execute_command(command_class, *args, **kargs)
|
|
26
|
+
command_class.new.execute(*args, **kargs)
|
|
27
|
+
rescue StandardError => e
|
|
28
|
+
ErrorHandler.handle_error(e)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -5,13 +5,38 @@ module DevSuite
|
|
|
5
5
|
class Config
|
|
6
6
|
include Utils::ConfigTools::Configuration
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
# Define configuration attributes
|
|
9
|
+
config_attr :settings, default_value: {}
|
|
10
|
+
config_attr :builder, default_value: :base
|
|
11
|
+
config_attr :renderer, default_value: :simple
|
|
12
|
+
config_attr :visualizer, default_value: :tree
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def validate_attr!(attr, value)
|
|
17
|
+
case attr
|
|
18
|
+
when :settings
|
|
19
|
+
validate_hash!(attr, value)
|
|
20
|
+
when :builder, :renderer, :visualizer
|
|
21
|
+
validate_symbol!(attr, value)
|
|
22
|
+
else
|
|
23
|
+
raise ArgumentError, "Invalid attribute: #{attr}"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def resolve_attr(attr, value)
|
|
28
|
+
case attr
|
|
29
|
+
when :settings
|
|
30
|
+
Settings.new(value)
|
|
31
|
+
when :builder
|
|
32
|
+
Builder.create(value)
|
|
33
|
+
when :renderer
|
|
34
|
+
Renderer.create(value)
|
|
35
|
+
when :visualizer
|
|
36
|
+
Visualizer.create(value)
|
|
37
|
+
else
|
|
38
|
+
super # Return the value directly if no special resolution is needed
|
|
39
|
+
end
|
|
15
40
|
end
|
|
16
41
|
end
|
|
17
42
|
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DevSuite
|
|
4
|
+
module DirectoryTree
|
|
5
|
+
require "pathname"
|
|
6
|
+
|
|
7
|
+
require_relative "node"
|
|
8
|
+
require_relative "config"
|
|
9
|
+
require_relative "settings"
|
|
10
|
+
require_relative "renderer"
|
|
11
|
+
require_relative "builder"
|
|
12
|
+
require_relative "visualizer"
|
|
13
|
+
|
|
14
|
+
class << self
|
|
15
|
+
def visualize(path)
|
|
16
|
+
visualizer = Config.configuration.visualizer
|
|
17
|
+
visualizer.visualize(path)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -40,15 +40,15 @@ module DevSuite
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def hidden_file_skipped?(node)
|
|
43
|
-
settings.skip_hidden
|
|
43
|
+
settings.get(:skip_hidden) && node.hidden?
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def filetype_skipped?(node)
|
|
47
|
-
node.file? && settings.skip_types.include?(::File.extname(node.name))
|
|
47
|
+
node.file? && settings.get(:skip_types).include?(::File.extname(node.name))
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def exceeds_max_depth?(depth)
|
|
51
|
-
max_depth = settings.max_depth
|
|
51
|
+
max_depth = settings.get(:max_depth)
|
|
52
52
|
max_depth && depth > max_depth
|
|
53
53
|
end
|
|
54
54
|
|
|
@@ -10,20 +10,9 @@ module DevSuite
|
|
|
10
10
|
skip_hidden: false,
|
|
11
11
|
skip_types: [],
|
|
12
12
|
max_depth: nil,
|
|
13
|
+
max_size: 100 * 1024 * 1024, # 100 MB
|
|
13
14
|
}
|
|
14
15
|
end
|
|
15
|
-
|
|
16
|
-
def skip_hidden?
|
|
17
|
-
get(:skip_hidden)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def skip_types
|
|
21
|
-
get(:skip_types)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def max_depth
|
|
25
|
-
get(:max_depth)
|
|
26
|
-
end
|
|
27
16
|
end
|
|
28
17
|
end
|
|
29
18
|
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DevSuite
|
|
4
|
+
module DirectoryTree
|
|
5
|
+
module Visualizer
|
|
6
|
+
class Tree < Base
|
|
7
|
+
# Visualizes the directory tree
|
|
8
|
+
# @param path [String] The base path of the directory
|
|
9
|
+
def visualize(path)
|
|
10
|
+
path = Pathname.new(path)
|
|
11
|
+
validate_path!(path)
|
|
12
|
+
validate_size!(path)
|
|
13
|
+
|
|
14
|
+
root = build_root_node(path)
|
|
15
|
+
output = render_output(root)
|
|
16
|
+
|
|
17
|
+
puts output
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def validate_path!(path)
|
|
23
|
+
raise ArgumentError, "Invalid path" unless path.exist?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def validate_size!(path)
|
|
27
|
+
config = Config.configuration
|
|
28
|
+
max_size = config.settings.get(:max_size)
|
|
29
|
+
raise ArgumentError, "Directory too large to render" if directory_size(path) > max_size
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def directory_size(path)
|
|
33
|
+
path.children.reduce(0) do |size, child|
|
|
34
|
+
size + (child.directory? ? directory_size(child) : child.size)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def build_root_node(path)
|
|
39
|
+
config = Config.configuration
|
|
40
|
+
config.builder.build(path)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def render_output(root)
|
|
44
|
+
config = Config.configuration
|
|
45
|
+
config.renderer.render(node: root)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
module DevSuite
|
|
4
4
|
module DirectoryTree
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
renderer = Config.configuration.renderer
|
|
11
|
-
puts renderer.render(node: root)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
5
|
+
module Visualizer
|
|
6
|
+
require "pathname"
|
|
7
|
+
|
|
8
|
+
require_relative "visualizer/base"
|
|
9
|
+
require_relative "visualizer/tree"
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
class << self
|
|
12
|
+
def create(type)
|
|
13
|
+
case type
|
|
14
|
+
when :tree
|
|
15
|
+
Tree.new
|
|
16
|
+
else
|
|
17
|
+
raise ArgumentError, "Unknown renderer type: #{type}"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
19
20
|
end
|
|
20
21
|
end
|
|
21
22
|
end
|