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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +37 -0
  3. data/Gemfile +11 -6
  4. data/Gemfile.lock +15 -3
  5. data/README.md +69 -46
  6. data/dev_suite.gemspec +7 -1
  7. data/exe/devsuite +6 -0
  8. data/lib/dev_suite/cli/commands/base.rb +16 -0
  9. data/lib/dev_suite/cli/commands/tree.rb +42 -0
  10. data/lib/dev_suite/cli/commands/version.rb +13 -0
  11. data/lib/dev_suite/cli/commands.rb +11 -0
  12. data/lib/dev_suite/cli/main.rb +32 -0
  13. data/lib/dev_suite/cli.rb +12 -0
  14. data/lib/dev_suite/directory_tree/config.rb +31 -6
  15. data/lib/dev_suite/directory_tree/directory_tree.rb +21 -0
  16. data/lib/dev_suite/directory_tree/renderer/simple.rb +3 -3
  17. data/lib/dev_suite/directory_tree/settings.rb +1 -12
  18. data/lib/dev_suite/directory_tree/visualizer/base.rb +13 -0
  19. data/lib/dev_suite/directory_tree/visualizer/tree.rb +50 -0
  20. data/lib/dev_suite/directory_tree/visualizer.rb +14 -13
  21. data/lib/dev_suite/directory_tree.rb +1 -8
  22. data/lib/dev_suite/emoji.rb +33 -0
  23. data/lib/dev_suite/error_handler.rb +22 -0
  24. data/lib/dev_suite/logger.rb +56 -0
  25. data/lib/dev_suite/performance/analyzer.rb +6 -23
  26. data/lib/dev_suite/performance/config.rb +25 -4
  27. data/lib/dev_suite/performance/profiler/execution_time.rb +29 -0
  28. data/lib/dev_suite/performance/profiler/memory.rb +20 -14
  29. data/lib/dev_suite/performance/profiler.rb +18 -1
  30. data/lib/dev_suite/performance/profiler_manager.rb +55 -0
  31. data/lib/dev_suite/performance/reportor/helpers/stat_mappings.rb +40 -0
  32. data/lib/dev_suite/performance/reportor/helpers/table_builder.rb +47 -0
  33. data/lib/dev_suite/performance/reportor/helpers.rb +12 -0
  34. data/lib/dev_suite/performance/reportor/simple.rb +7 -61
  35. data/lib/dev_suite/performance/reportor.rb +1 -0
  36. data/lib/dev_suite/performance.rb +1 -0
  37. data/lib/dev_suite/utils/config_tools/configuration.rb +103 -10
  38. data/lib/dev_suite/utils/config_tools/settings.rb +0 -8
  39. data/lib/dev_suite/version.rb +1 -1
  40. data/lib/dev_suite.rb +9 -6
  41. metadata +67 -6
  42. 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: eca02b15867ef75a77fed4586931ab72a98c33202dd3792daf44cc208c0f9e72
4
- data.tar.gz: b6bc4187d4e93978fab552d47178792efb7862c9055f868469b138ee37e755e0
3
+ metadata.gz: 6765c4b9fa4637dafaac36da47cd8adf18652cd0d38804ddcd8641b851669f12
4
+ data.tar.gz: 3a3b27ad8b9fa4319829175995b1d6ea999e9877d537b1316b531247d6bd4b53
5
5
  SHA512:
6
- metadata.gz: 70e87b35875abc89df1823e80fd6fda525eb019e992b8e454cdf22043b98b0b731cdc6b111af15ca23bb8818857de387ae996adbeb1d0920413dbe807804119e
7
- data.tar.gz: 9c4396647818118bde2c5c82a3b9f0d5ce2775d3c53812070071b4b3d37ebc931786214a3a8a8b6c3c151eb64904bebcf61298ba915dbd99baf64c1e54d13737
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
- # Specify your gem's dependencies in dev_suite.gemspec
5
+ # Use the gemspec method to include dependencies specified in the gemspec file
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
9
- gem "rspec", "~> 3.9"
10
- gem "rubocop", "~> 1.65", require: false
11
- gem "rubocop-shopify", "~> 2.15", require: false
12
- gem "pry", "~> 0.14"
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.2)
4
+ dev_suite (0.2.4)
5
5
  benchmark (~> 0.1)
6
- get_process_mem (~> 0.2)
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.2.7)
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
- [![Gem Version](https://badge.fury.io/rb/dev_suite.svg)](https://badge.fury.io/rb/dev_suite)
4
- [![Code Climate](https://codeclimate.com/github/patrick204nqh/dev_suite/badges/gpa.svg)](https://codeclimate.com/github/patrick204nqh/dev_suite)
3
+ [![Gem Version](https://img.shields.io/gem/v/dev_suite?color=blue)](https://rubygems.org/gems/dev_suite)
4
+ [![Gem Downloads](https://img.shields.io/gem/dt/dev_suite?color=blue)](https://rubygems.org/gems/dev_suite)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/fd83689d39e0f24663fa/maintainability)](https://codeclimate.com/github/patrick204nqh/dev_suite/maintainability)
6
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/fd83689d39e0f24663fa/test_coverage)](https://codeclimate.com/github/patrick204nqh/dev_suite/test_coverage)
7
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=patrick204nqh_dev_suite&metric=alert_status)](https://sonarcloud.io/summary/overall?id=patrick204nqh_dev_suite)
8
+ [![Dependencies Status](https://badges.depfu.com/badges/84fefb47a5b99ea19afd20a2aae22e3e/overview.svg)](https://depfu.com/github/patrick204nqh/dev_suite?project_id=44065)
9
+ [![Known Vulnerabilities](https://snyk.io/test/github/patrick204nqh/dev_suite/badge.svg)](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
- ## Features
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><strong>Performance Analysis</strong></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
- **Usage:**
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: "My Code Block") do
68
+
69
+ DevSuite::Performance.analyze(description: "Example Analysis") do
55
70
  sum = 0
56
- 1_000_000.times do |i|
57
- sum += i
58
- end
71
+ 1_000_000.times { |i| sum += i }
59
72
  sum
60
73
  end
61
74
  ```
62
75
 
63
- **Example output**
76
+ **Sample Output**:
64
77
  ```
65
- | Performance Analysis |
66
- +----------------------------+---------------+
67
- | Metric | Value |
68
- +----------------------------+---------------+
69
- | Description | My Code Block |
70
- | Total Time (s) | 0.056238 |
71
- | User CPU Time (s) | 0.055662 |
72
- | System CPU Time (s) | 0.000097 |
73
- | User + System CPU Time (s) | 0.055759 |
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><strong>Directory Tree Visualization</strong></summary>
92
+ <summary>Show more</summary>
85
93
 
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.
94
+ **Purpose**: Visualize the file structure of directories and subdirectories to better understand project organization.
87
95
 
88
- **Usage:**
96
+ **How to Use**:
89
97
  ```ruby
90
98
  require 'dev_suite'
91
99
 
92
- # Set the base path for the directory you want to visualize
100
+ # Define the directory path
93
101
  base_path = "/path/to/your/directory"
94
102
 
95
- # Perform the visualization
103
+ # Execute the visualization
96
104
  DevSuite::DirectoryTree.visualize(base_path)
97
105
  ```
98
106
 
99
- **Configuring the Visualization:**
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
- config.settings.set(:skip_hidden, true)
104
- # ...
128
+ config.settings.set(:skip_hidden, true)
129
+ # ...
105
130
  end
106
131
  ```
107
132
 
108
- **Available Configuration Options:**
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
- | Setting | Description | Example Values |
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.2")
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,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/dev_suite"
5
+
6
+ DevSuite::CLI::Main.start(ARGV)
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module CLI
5
+ module Commands
6
+ class Base < Thor
7
+ include ErrorHandler
8
+
9
+ desc "execute", "Execute the command"
10
+ def execute
11
+ raise NotImplementedError
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -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,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module CLI
5
+ module Commands
6
+ class Version < Base
7
+ def execute
8
+ Logger.log("DevSuite version: #{DevSuite::VERSION} is live!", emoji: :start)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module CLI
5
+ module Commands
6
+ require_relative "commands/base"
7
+ require_relative "commands/version"
8
+ require_relative "commands/tree"
9
+ end
10
+ end
11
+ 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
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module CLI
5
+ require "thor"
6
+
7
+ require_relative "cli/commands"
8
+
9
+ # Main CLI class
10
+ require_relative "cli/main"
11
+ end
12
+ end
@@ -5,13 +5,38 @@ module DevSuite
5
5
  class Config
6
6
  include Utils::ConfigTools::Configuration
7
7
 
8
- attr_reader :settings, :builder, :renderer
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
- def initialize(settings: {}, builder: :base, renderer: :simple)
11
- @settings = Settings.new(settings)
12
- @builder = Builder.create(builder)
13
- @renderer = Renderer.create(renderer)
14
- freeze # Make the instance of this class immutable as well
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? && node.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,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module DirectoryTree
5
+ module Visualizer
6
+ class Base
7
+ def visualize(path)
8
+ raise NotImplementedError, "You must implement #{self.class}##{__method}"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ 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
- class Visualizer
6
- # Visualizes the directory tree
7
- # @param path [String] The base path of the directory
8
- def visualize(path)
9
- root = Config.configuration.builder.build(Pathname.new(path))
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
- class << self
16
- def visualize(path)
17
- visualizer = Visualizer.new
18
- visualizer.visualize(path)
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