dev_suite 0.2.3 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +37 -0
  3. data/Gemfile +13 -6
  4. data/Gemfile.lock +9 -1
  5. data/README.md +66 -2
  6. data/dev_suite.gemspec +1 -0
  7. data/lib/dev_suite/cli/commands/base.rb +0 -30
  8. data/lib/dev_suite/cli/commands/tree.rb +29 -8
  9. data/lib/dev_suite/cli/commands/version.rb +1 -1
  10. data/lib/dev_suite/cli/main.rb +12 -9
  11. data/lib/dev_suite/dev_suite.rb +12 -0
  12. data/lib/dev_suite/directory_tree/config/config.rb +11 -0
  13. data/lib/dev_suite/directory_tree/config/configuration.rb +21 -0
  14. data/lib/dev_suite/directory_tree/config.rb +2 -11
  15. data/lib/dev_suite/directory_tree/directory_tree.rb +20 -0
  16. data/lib/dev_suite/directory_tree/renderer/base.rb +0 -6
  17. data/lib/dev_suite/directory_tree/renderer/simple.rb +3 -3
  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/performance/analyzer.rb +1 -1
  23. data/lib/dev_suite/performance/config/config.rb +11 -0
  24. data/lib/dev_suite/performance/config/configuration.rb +30 -0
  25. data/lib/dev_suite/performance/config.rb +2 -10
  26. data/lib/dev_suite/performance/{reportor → reporter}/base.rb +1 -1
  27. data/lib/dev_suite/performance/{reportor → reporter}/helpers/stat_mappings.rb +1 -1
  28. data/lib/dev_suite/performance/{reportor → reporter}/helpers/table_builder.rb +1 -1
  29. data/lib/dev_suite/performance/{reportor → reporter}/helpers.rb +1 -1
  30. data/lib/dev_suite/performance/{reportor → reporter}/simple.rb +1 -1
  31. data/lib/dev_suite/performance/reporter.rb +22 -0
  32. data/lib/dev_suite/performance.rb +1 -1
  33. data/lib/dev_suite/request_logger/adapter/adapter.rb +27 -0
  34. data/lib/dev_suite/request_logger/adapter/base.rb +17 -0
  35. data/lib/dev_suite/request_logger/adapter/net_http.rb +42 -0
  36. data/lib/dev_suite/request_logger/adapter.rb +9 -0
  37. data/lib/dev_suite/request_logger/config/config.rb +11 -0
  38. data/lib/dev_suite/request_logger/config/configuration.rb +24 -0
  39. data/lib/dev_suite/request_logger/config.rb +9 -0
  40. data/lib/dev_suite/request_logger/logger.rb +93 -0
  41. data/lib/dev_suite/request_logger/request_logger.rb +29 -0
  42. data/lib/dev_suite/request_logger.rb +7 -0
  43. data/lib/dev_suite/utils/color/color.rb +12 -0
  44. data/lib/dev_suite/utils/color/config/config.rb +13 -0
  45. data/lib/dev_suite/utils/color/config/configuration.rb +31 -0
  46. data/lib/dev_suite/utils/color/config.rb +2 -31
  47. data/lib/dev_suite/utils/color/strategy/theme.rb +6 -7
  48. data/lib/dev_suite/utils/color/strategy.rb +2 -4
  49. data/lib/dev_suite/utils/color.rb +1 -4
  50. data/lib/dev_suite/utils/construct/config/attribute/attribute.rb +15 -0
  51. data/lib/dev_suite/utils/construct/config/attribute/manager.rb +63 -0
  52. data/lib/dev_suite/utils/construct/config/attribute/resolver.rb +31 -0
  53. data/lib/dev_suite/utils/construct/config/attribute/validator.rb +55 -0
  54. data/lib/dev_suite/utils/construct/config/attribute.rb +13 -0
  55. data/lib/dev_suite/utils/construct/config/base.rb +20 -0
  56. data/lib/dev_suite/utils/construct/config/config.rb +24 -0
  57. data/lib/dev_suite/utils/construct/config/configuration.rb +13 -0
  58. data/lib/dev_suite/utils/construct/config/hook/hook.rb +13 -0
  59. data/lib/dev_suite/utils/construct/config/hook/manager.rb +36 -0
  60. data/lib/dev_suite/utils/construct/config/hook.rb +13 -0
  61. data/lib/dev_suite/utils/construct/config/initializer.rb +21 -0
  62. data/lib/dev_suite/utils/construct/config/manager.rb +33 -0
  63. data/lib/dev_suite/utils/construct/config/settings/base.rb +59 -0
  64. data/lib/dev_suite/utils/construct/config/settings/manager.rb +38 -0
  65. data/lib/dev_suite/utils/construct/config/settings/settings.rb +14 -0
  66. data/lib/dev_suite/utils/construct/config/settings.rb +13 -0
  67. data/lib/dev_suite/utils/construct/config.rb +11 -0
  68. data/lib/dev_suite/utils/construct/construct.rb +9 -0
  69. data/lib/dev_suite/utils/construct.rb +16 -0
  70. data/lib/dev_suite/utils/emoji.rb +71 -0
  71. data/lib/dev_suite/utils/error_handler.rb +24 -0
  72. data/lib/dev_suite/utils/file_loader/config/config.rb +13 -0
  73. data/lib/dev_suite/utils/file_loader/config/configuration.rb +33 -0
  74. data/lib/dev_suite/utils/file_loader/config.rb +11 -0
  75. data/lib/dev_suite/utils/file_loader/file_loader.rb +23 -0
  76. data/lib/dev_suite/utils/file_loader/loader/base.rb +21 -0
  77. data/lib/dev_suite/utils/file_loader/loader/json.rb +21 -0
  78. data/lib/dev_suite/utils/file_loader/loader/text.rb +21 -0
  79. data/lib/dev_suite/utils/file_loader/loader/yaml.rb +38 -0
  80. data/lib/dev_suite/utils/file_loader/loader.rb +41 -0
  81. data/lib/dev_suite/utils/file_loader/loader_manager.rb +34 -0
  82. data/lib/dev_suite/utils/file_loader/loader_registry.rb +36 -0
  83. data/lib/dev_suite/utils/file_loader.rb +9 -0
  84. data/lib/dev_suite/utils/logger.rb +58 -0
  85. data/lib/dev_suite/utils/path_matcher/matcher.rb +31 -0
  86. data/lib/dev_suite/utils/path_matcher/path_matcher.rb +17 -0
  87. data/lib/dev_suite/utils/path_matcher/pattern.rb +35 -0
  88. data/lib/dev_suite/utils/path_matcher.rb +9 -0
  89. data/lib/dev_suite/utils/table/config/config.rb +13 -0
  90. data/lib/dev_suite/utils/table/config/configuration.rb +32 -0
  91. data/lib/dev_suite/utils/table/config.rb +2 -23
  92. data/lib/dev_suite/utils/table/renderer/base.rb +0 -6
  93. data/lib/dev_suite/utils/table/renderer/simple.rb +9 -5
  94. data/lib/dev_suite/utils/table/renderer.rb +2 -2
  95. data/lib/dev_suite/utils/table/table.rb +6 -0
  96. data/lib/dev_suite/utils/table.rb +0 -6
  97. data/lib/dev_suite/utils/utils.rb +14 -0
  98. data/lib/dev_suite/utils.rb +1 -3
  99. data/lib/dev_suite/version.rb +1 -1
  100. data/lib/dev_suite.rb +1 -8
  101. metadata +72 -13
  102. data/lib/dev_suite/directory_tree/settings.rb +0 -29
  103. data/lib/dev_suite/performance/reportor.rb +0 -22
  104. data/lib/dev_suite/utils/config_tools/configuration.rb +0 -41
  105. data/lib/dev_suite/utils/config_tools/settings.rb +0 -75
  106. data/lib/dev_suite/utils/config_tools.rb +0 -10
  107. data/lib/dev_suite/utils/table/settings.rb +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fde5663cbb9add03d1db18d4b31fffba0049d8d4f49e5e6bcac7d5d72c6933a2
4
- data.tar.gz: d37a1514954b871e610f07942556581f0c68ff83ce35f8f408e35adbabaeee3b
3
+ metadata.gz: d90d0f33e4d0651dbc5ed388a62c7c0b3a665cb27db805631d8771245b21129e
4
+ data.tar.gz: e87b028766648877eea33d3c2910d3879510a50d4425fd9b19bf96212cb141a7
5
5
  SHA512:
6
- metadata.gz: 89a013a696f477509da2adc76551badd312dbe73f6ca94440c57384e6a749e0327a4d9a8d9c2262eab7da4dd0ac431656f163e5f7df1068276397c92d641d9a9
7
- data.tar.gz: 6067472079ddfdb69796f2fa34727e44dd8bc8e39c825748aaad8d138640960796bbc15262e0e0d845bfe5b53838d55a8d84208aa89bf6d685f8264e5a5dc2c8
6
+ metadata.gz: c7a4fdb6138b2c9e75bafa923f095479827d58c229fdc60f2ae8c2b5e2a6a04f8e39c6ed27cf26ab3c53a62f606c5931c851698c1b577f6bdb1bad45289b344e
7
+ data.tar.gz: 1d10bd660e02d4100ee58fb7607626cfaf2ef714811a9407d25ae12f9fe71ae3ed9fd36d8b21de8bdba6b288223ed9a8b58ae22deb6e3ac297d24692e90ca86e
@@ -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,18 @@
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 "rspec", "~> 3.9"
11
+ gem "simplecov", "~> 0.21"
12
+ gem "rake", "~> 13.0"
13
+ gem "pry", "~> 0.14"
14
+ end
15
+
16
+ group :development do
17
+ gem "rubocop", "~> 1.65", require: false
18
+ gem "rubocop-shopify", "~> 2.15", require: false
19
+ end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dev_suite (0.2.3)
4
+ dev_suite (0.2.5)
5
5
  benchmark (~> 0.1)
6
6
  get_process_mem (~> 1.0)
7
7
  thor (~> 1.1)
@@ -14,6 +14,7 @@ GEM
14
14
  bigdecimal (3.1.8)
15
15
  coderay (1.1.3)
16
16
  diff-lcs (1.5.1)
17
+ docile (1.4.1)
17
18
  ffi (1.17.0)
18
19
  ffi (1.17.0-aarch64-linux-gnu)
19
20
  ffi (1.17.0-aarch64-linux-musl)
@@ -73,6 +74,12 @@ GEM
73
74
  rubocop-shopify (2.15.1)
74
75
  rubocop (~> 1.51)
75
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)
76
83
  strscan (3.1.0)
77
84
  thor (1.3.1)
78
85
  unicode-display_width (2.5.0)
@@ -97,6 +104,7 @@ DEPENDENCIES
97
104
  rspec (~> 3.9)
98
105
  rubocop (~> 1.65)
99
106
  rubocop-shopify (~> 2.15)
107
+ simplecov (~> 0.21)
100
108
 
101
109
  BUNDLED WITH
102
110
  2.5.17
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://img.shields.io/gem/v/dev_suite?color=blue)](https://rubygems.org/gems/dev_suite)
4
4
  [![Gem Downloads](https://img.shields.io/gem/dt/dev_suite?color=blue)](https://rubygems.org/gems/dev_suite)
5
- [![Code Climate](https://codeclimate.com/github/patrick204nqh/dev_suite/badges/gpa.svg)](https://codeclimate.com/github/patrick204nqh/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)
6
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)
7
8
  [![Dependencies Status](https://badges.depfu.com/badges/84fefb47a5b99ea19afd20a2aae22e3e/overview.svg)](https://depfu.com/github/patrick204nqh/dev_suite?project_id=44065)
8
9
  [![Known Vulnerabilities](https://snyk.io/test/github/patrick204nqh/dev_suite/badge.svg)](https://snyk.io/test/github/patrick204nqh/dev_suite)
@@ -107,9 +108,19 @@ DevSuite also provides a command-line interface for various utilities. Below are
107
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:
108
109
 
109
110
  ```sh
110
- $ devsuite tree [PATH]
111
+ $ devsuite tree [PATH] [OPTIONS]
111
112
  ```
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
+
113
124
  **Configuration Guide**:
114
125
  Customize the visualization by setting configuration options:
115
126
  ```ruby
@@ -142,6 +153,59 @@ DevSuite also provides a command-line interface for various utilities. Below are
142
153
  ```
143
154
  </details>
144
155
 
156
+ ### Request Logging
157
+ <details>
158
+ <summary>Show more</summary>
159
+
160
+ **Purpose**: The `RequestLogger` feature enables detailed logging of HTTP requests and responses across different adapters (e.g., `Net::HTTP`, `Faraday`). This can be useful for debugging, monitoring, and auditing API interactions.
161
+
162
+ **How to Use**:
163
+ ```ruby
164
+ require 'dev_suite'
165
+
166
+ DevSuite::RequestLogger.with_logging do
167
+ # Make an HTTP request using Net::HTTP
168
+ uri = URI('https://jsonplaceholder.typicode.com/posts')
169
+ response = Net::HTTP.get(uri)
170
+ end
171
+ ```
172
+
173
+ **Configuration Guide**:
174
+ Customize the request logging behavior by setting configuration options:
175
+ ```ruby
176
+ DevSuite::RequestLogger.configure do |config|
177
+ config.adapters = [:net_http]
178
+ ...
179
+ end
180
+ ```
181
+
182
+ **Configuration Options**:
183
+
184
+ Below is a table describing the available configuration settings:
185
+
186
+ | Setting | Description | Example Values |
187
+ |----------------|----------------------------------------------------|------------------------------------|
188
+ | `:adapters` | List of adapters for which logging is enabled. | `[:net_http, :faraday]` |
189
+ <!-- | `:log_level` | Set the logging level (e.g., info, debug). | `:info`, `:debug`, `:warn`, `:error` |
190
+ | `:log_response` | Enable or disable response logging. | `true`, `false` |
191
+ | `:log_emoji` | Customize emojis for request and response logs. | `{ request: :globe, response: :envelope }` | -->
192
+
193
+ **Adapters Supported**:
194
+
195
+ The `RequestLogger` currently supports the following adapters:
196
+
197
+ | Adapter | Description | Example Usage |
198
+ |--------------|--------------------------------------------|---------------------------------------------------|
199
+ | `Net::HTTP` | Logs requests made with the Net::HTTP class.| `DevSuite::RequestLogger::Adapter::NetHttp.new(config)` |
200
+ <!-- | `Faraday` | Logs requests made with the Faraday gem. | `DevSuite::RequestLogger::Adapter::Faraday.new(config)` | -->
201
+
202
+ **Sample Output**:
203
+ ```bash
204
+ [INFO] 🌐 Net::HTTP Request: GET http://example.com
205
+ [DEBUG] 📄 Net::HTTP Response: 200 OK
206
+ ```
207
+ </details>
208
+
145
209
  ## Development
146
210
 
147
211
  After checking out the repo, run `bin/setup`for an interactive prompt that will allow you to experiment.
data/dev_suite.gemspec CHANGED
@@ -29,6 +29,7 @@ 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
34
  spec.add_dependency("get_process_mem", "~> 1.0")
34
35
  spec.add_dependency("thor", "~> 1.1")
@@ -4,36 +4,6 @@ module DevSuite
4
4
  module CLI
5
5
  module Commands
6
6
  class Base < Thor
7
- no_commands do
8
- # Log message to console
9
- def log(message, level: :info)
10
- case level
11
- when :info
12
- puts "[INFO] #{message}"
13
- when :warn
14
- puts "[WARNING] #{message}"
15
- when :error
16
- puts "[ERROR] #{message}"
17
- when :debug
18
- puts "[DEBUG] #{message}" if ENV["DEBUG_MODE"]
19
- end
20
- end
21
-
22
- # Handle common errors
23
- def handle_error(error)
24
- log("Error: #{error.message}", level: :error)
25
- exit(1)
26
- end
27
-
28
- # Default method to load configuration
29
- def load_config(file)
30
- YAML.load_file(file)
31
- rescue Errno::ENOENT
32
- log("Configuration file not found: #{file}", level: :error)
33
- exit(1)
34
- end
35
- end
36
-
37
7
  desc "execute", "Execute the command"
38
8
  def execute
39
9
  raise NotImplementedError
@@ -5,14 +5,35 @@ module DevSuite
5
5
  module Commands
6
6
  class Tree < Base
7
7
  desc "visualize PATH", "Visualize the directory structure at given PATH"
8
- def execute(path)
9
- log("Starting visualization for: #{path}")
10
- begin
11
- # Assume visualize_path is a method that can raise exceptions
12
- DirectoryTree.visualize(path)
13
- log("Visualization complete.")
14
- rescue StandardError => e
15
- handle_error(e)
8
+ def execute(path, options: {})
9
+ Utils::Logger.log("Starting visualization for: #{path}", emoji: :start)
10
+
11
+ apply_configure(options)
12
+ visualize(path)
13
+
14
+ Utils::Logger.log("Visualization complete!", emoji: :success)
15
+ rescue StandardError => e
16
+ Utils::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
16
37
  end
17
38
  end
18
39
  end
@@ -5,7 +5,7 @@ module DevSuite
5
5
  module Commands
6
6
  class Version < Base
7
7
  def execute
8
- log("DevSuite version: #{DevSuite::VERSION}")
8
+ Utils::Logger.log("DevSuite version: #{DevSuite::VERSION} is live!", emoji: :start)
9
9
  end
10
10
  end
11
11
  end
@@ -4,8 +4,15 @@ module DevSuite
4
4
  module CLI
5
5
  class Main < Thor
6
6
  desc "tree DIRECTORY", "Prints the directory tree"
7
- def tree(directory)
8
- execute_command(Commands::Tree, directory)
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)
9
16
  end
10
17
 
11
18
  desc "version", "Displays the version of the dev_suite gem"
@@ -15,14 +22,10 @@ module DevSuite
15
22
 
16
23
  private
17
24
 
18
- def execute_command(command_class, *args)
19
- command_class.new.execute(*args)
25
+ def execute_command(command_class, *args, **kargs)
26
+ command_class.new.execute(*args, **kargs)
20
27
  rescue StandardError => e
21
- handle_error(e)
22
- end
23
-
24
- def handle_error(error)
25
- puts "An error occurred: #{error.message}"
28
+ Utils::ErrorHandler.handle_error(e)
26
29
  end
27
30
  end
28
31
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ require_relative "version"
5
+ require_relative "utils"
6
+ require_relative "cli"
7
+ require_relative "performance"
8
+ require_relative "directory_tree"
9
+ require_relative "request_logger"
10
+
11
+ class Error < StandardError; end
12
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module DirectoryTree
5
+ module Config
6
+ include Utils::Construct::Config
7
+
8
+ require_relative "configuration"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module DirectoryTree
5
+ module Config
6
+ class Configuration < BaseConfiguration
7
+ set_default_settings(
8
+ skip_hidden: false,
9
+ skip_types: [],
10
+ max_depth: nil,
11
+ max_size: 100 * 1024 * 1024, # 100 MB
12
+ )
13
+
14
+ # Define configuration attributes
15
+ config_attr :builder, default_value: :base, type: :symbol, resolver: ->(value) { Builder.create(value) }
16
+ config_attr :renderer, default_value: :simple, type: :symbol, resolver: ->(value) { Renderer.create(value) }
17
+ config_attr :visualizer, default_value: :tree, type: :symbol, resolver: ->(value) { Visualizer.create(value) }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -2,17 +2,8 @@
2
2
 
3
3
  module DevSuite
4
4
  module DirectoryTree
5
- class Config
6
- include Utils::ConfigTools::Configuration
7
-
8
- attr_reader :settings, :builder, :renderer
9
-
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
15
- end
5
+ module Config
6
+ require_relative "config/config"
16
7
  end
17
8
  end
18
9
  end
@@ -0,0 +1,20 @@
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 "renderer"
10
+ require_relative "builder"
11
+ require_relative "visualizer"
12
+
13
+ class << self
14
+ def visualize(path)
15
+ visualizer = Config.configuration.visualizer
16
+ visualizer.visualize(path)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -4,12 +4,6 @@ module DevSuite
4
4
  module DirectoryTree
5
5
  module Renderer
6
6
  class Base
7
- attr_reader :settings
8
-
9
- def initialize(settings: Settings.new)
10
- @settings = settings
11
- end
12
-
13
7
  def render
14
8
  raise NotImplementedError
15
9
  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
 
@@ -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
@@ -2,13 +2,6 @@
2
2
 
3
3
  module DevSuite
4
4
  module DirectoryTree
5
- require "pathname"
6
-
7
- require_relative "directory_tree/node"
8
- require_relative "directory_tree/config"
9
- require_relative "directory_tree/settings"
10
- require_relative "directory_tree/renderer"
11
- require_relative "directory_tree/builder"
12
- require_relative "directory_tree/visualizer"
5
+ require_relative "directory_tree/directory_tree"
13
6
  end
14
7
  end
@@ -25,7 +25,7 @@ module DevSuite
25
25
  # @param benchmark_result [Benchmark::Tms] The benchmark result
26
26
  # @param memory_stats [Hash] The memory statistics
27
27
  def generate_report(results)
28
- Config.configuration.reportor.generate(
28
+ Config.configuration.reporter.generate(
29
29
  description: @description,
30
30
  results: results,
31
31
  )
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Performance
5
+ module Config
6
+ include Utils::Construct::Config
7
+
8
+ require_relative "configuration"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Performance
5
+ module Config
6
+ class Configuration < BaseConfiguration
7
+ # Define configuration attributes
8
+ config_attr :profilers,
9
+ default_value: [:execution_time, :memory],
10
+ type: :array,
11
+ resolver: :resolve_profilers
12
+
13
+ config_attr :reporter,
14
+ default_value: :simple,
15
+ type: :symbol,
16
+ resolver: :resolve_reporter
17
+
18
+ private
19
+
20
+ def resolve_profilers(value)
21
+ Profiler.create_multiple(value)
22
+ end
23
+
24
+ def resolve_reporter(value)
25
+ Reporter.create(value)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,16 +2,8 @@
2
2
 
3
3
  module DevSuite
4
4
  module Performance
5
- class Config
6
- include Utils::ConfigTools::Configuration
7
-
8
- attr_reader :profilers, :reportor
9
-
10
- def initialize(profilers: [:execution_time, :memory], reportor: :simple)
11
- @profilers = Profiler.create_multiple(profilers)
12
- @reportor = Reportor.create(reportor)
13
- freeze # Make the instance of this class immutable
14
- end
5
+ module Config
6
+ require_relative "config/config"
15
7
  end
16
8
  end
17
9
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DevSuite
4
4
  module Performance
5
- module Reportor
5
+ module Reporter
6
6
  class Base
7
7
  def generate
8
8
  raise NotImplementedError, "Subclasses must implement the generate method"