dev_suite 0.2.4 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -5
  3. data/.vscode/extensions.json +8 -0
  4. data/.vscode/launch.json +39 -0
  5. data/.vscode/settings.json +28 -0
  6. data/Gemfile +6 -1
  7. data/Gemfile.lock +28 -2
  8. data/README.md +69 -8
  9. data/bin/rspec +27 -0
  10. data/dev_suite.gemspec +0 -4
  11. data/lib/dev_suite/cli/commands/base.rb +0 -2
  12. data/lib/dev_suite/cli/commands/tree.rb +3 -3
  13. data/lib/dev_suite/cli/commands/version.rb +1 -1
  14. data/lib/dev_suite/cli/main.rb +1 -1
  15. data/lib/dev_suite/dev_suite.rb +12 -0
  16. data/lib/dev_suite/directory_tree/builder/base.rb +1 -1
  17. data/lib/dev_suite/directory_tree/builder/builder.rb +13 -0
  18. data/lib/dev_suite/directory_tree/builder.rb +1 -12
  19. data/lib/dev_suite/directory_tree/config/config.rb +11 -0
  20. data/lib/dev_suite/directory_tree/config/configuration.rb +34 -0
  21. data/lib/dev_suite/directory_tree/config.rb +2 -36
  22. data/lib/dev_suite/directory_tree/directory_tree.rb +0 -3
  23. data/lib/dev_suite/directory_tree/node/node.rb +12 -0
  24. data/lib/dev_suite/directory_tree/node.rb +1 -4
  25. data/lib/dev_suite/directory_tree/renderer/base.rb +1 -7
  26. data/lib/dev_suite/directory_tree/renderer/renderer.rb +14 -0
  27. data/lib/dev_suite/directory_tree/renderer.rb +1 -13
  28. data/lib/dev_suite/directory_tree/visualizer/base.rb +1 -1
  29. data/lib/dev_suite/directory_tree/visualizer/visualizer.rb +16 -0
  30. data/lib/dev_suite/directory_tree/visualizer.rb +1 -15
  31. data/lib/dev_suite/performance/analyzer.rb +1 -1
  32. data/lib/dev_suite/performance/config/config.rb +11 -0
  33. data/lib/dev_suite/performance/config/configuration.rb +30 -0
  34. data/lib/dev_suite/performance/config.rb +2 -30
  35. data/lib/dev_suite/performance/data/data.rb +9 -0
  36. data/lib/dev_suite/performance/data.rb +1 -1
  37. data/lib/dev_suite/performance/profiler/base.rb +1 -1
  38. data/lib/dev_suite/performance/profiler/profiler.rb +16 -0
  39. data/lib/dev_suite/performance/profiler.rb +1 -20
  40. data/lib/dev_suite/performance/profiler_manager.rb +1 -0
  41. data/lib/dev_suite/performance/{reportor → reporter}/base.rb +2 -2
  42. data/lib/dev_suite/performance/{reportor → reporter}/helpers/stat_mappings.rb +1 -1
  43. data/lib/dev_suite/performance/{reportor → reporter}/helpers/table_builder.rb +1 -1
  44. data/lib/dev_suite/performance/{reportor → reporter}/helpers.rb +1 -1
  45. data/lib/dev_suite/performance/reporter/reporter.rb +15 -0
  46. data/lib/dev_suite/performance/{reportor → reporter}/simple.rb +1 -1
  47. data/lib/dev_suite/performance/reporter.rb +9 -0
  48. data/lib/dev_suite/performance.rb +1 -1
  49. data/lib/dev_suite/request_logger/adapter/adapter.rb +31 -0
  50. data/lib/dev_suite/request_logger/adapter/base.rb +17 -0
  51. data/lib/dev_suite/request_logger/adapter/faraday.rb +37 -0
  52. data/lib/dev_suite/request_logger/adapter/middleware/faraday.rb +22 -0
  53. data/lib/dev_suite/request_logger/adapter/net_http.rb +43 -0
  54. data/lib/dev_suite/request_logger/adapter.rb +9 -0
  55. data/lib/dev_suite/request_logger/config/config.rb +11 -0
  56. data/lib/dev_suite/request_logger/config/configuration.rb +24 -0
  57. data/lib/dev_suite/request_logger/config.rb +9 -0
  58. data/lib/dev_suite/request_logger/extractor/base.rb +17 -0
  59. data/lib/dev_suite/request_logger/extractor/extractor.rb +22 -0
  60. data/lib/dev_suite/request_logger/extractor/faraday.rb +37 -0
  61. data/lib/dev_suite/request_logger/extractor/net_http.rb +36 -0
  62. data/lib/dev_suite/request_logger/extractor.rb +9 -0
  63. data/lib/dev_suite/request_logger/logger.rb +87 -0
  64. data/lib/dev_suite/request_logger/request.rb +19 -0
  65. data/lib/dev_suite/request_logger/request_logger.rb +32 -0
  66. data/lib/dev_suite/request_logger/response.rb +28 -0
  67. data/lib/dev_suite/request_logger.rb +7 -0
  68. data/lib/dev_suite/utils/color/color.rb +12 -0
  69. data/lib/dev_suite/utils/color/config/config.rb +13 -0
  70. data/lib/dev_suite/utils/color/config/configuration.rb +31 -0
  71. data/lib/dev_suite/utils/color/config.rb +2 -31
  72. data/lib/dev_suite/utils/color/palette/base.rb +1 -14
  73. data/lib/dev_suite/utils/color/palette/palette.rb +16 -0
  74. data/lib/dev_suite/utils/color/palette.rb +1 -13
  75. data/lib/dev_suite/utils/color/strategy/base.rb +1 -1
  76. data/lib/dev_suite/utils/color/strategy/strategy.rb +20 -0
  77. data/lib/dev_suite/utils/color/strategy/theme.rb +6 -7
  78. data/lib/dev_suite/utils/color/strategy.rb +1 -21
  79. data/lib/dev_suite/utils/color.rb +1 -4
  80. data/lib/dev_suite/utils/construct/component/base.rb +30 -0
  81. data/lib/dev_suite/utils/construct/component/component.rb +12 -0
  82. data/lib/dev_suite/utils/construct/component/initializer.rb +28 -0
  83. data/lib/dev_suite/utils/construct/component/manager.rb +57 -0
  84. data/lib/dev_suite/utils/construct/component.rb +11 -0
  85. data/lib/dev_suite/utils/construct/config/attribute/attr_definition.rb +76 -0
  86. data/lib/dev_suite/utils/construct/config/attribute/attr_initialization.rb +22 -0
  87. data/lib/dev_suite/utils/construct/config/attribute/attr_resolving.rb +80 -0
  88. data/lib/dev_suite/utils/construct/config/attribute/attribute.rb +24 -0
  89. data/lib/dev_suite/utils/construct/config/attribute/validator.rb +55 -0
  90. data/lib/dev_suite/utils/construct/config/attribute.rb +13 -0
  91. data/lib/dev_suite/utils/construct/config/base.rb +25 -0
  92. data/lib/dev_suite/utils/construct/config/config.rb +16 -0
  93. data/lib/dev_suite/utils/construct/config/dependency_handler.rb +56 -0
  94. data/lib/dev_suite/utils/construct/config/hook/hook.rb +22 -0
  95. data/lib/dev_suite/utils/construct/config/hook/hook_registry.rb +24 -0
  96. data/lib/dev_suite/utils/construct/config/hook/hook_runner.rb +20 -0
  97. data/lib/dev_suite/utils/construct/config/hook/manager.rb +36 -0
  98. data/lib/dev_suite/utils/construct/config/hook.rb +13 -0
  99. data/lib/dev_suite/utils/construct/config/manager.rb +41 -0
  100. data/lib/dev_suite/utils/construct/config/settings/base.rb +59 -0
  101. data/lib/dev_suite/utils/construct/config/settings/manager.rb +38 -0
  102. data/lib/dev_suite/utils/construct/config/settings/settings.rb +14 -0
  103. data/lib/dev_suite/utils/construct/config/settings.rb +13 -0
  104. data/lib/dev_suite/utils/construct/config.rb +11 -0
  105. data/lib/dev_suite/utils/construct/construct.rb +10 -0
  106. data/lib/dev_suite/utils/construct.rb +16 -0
  107. data/lib/dev_suite/utils/dependency_loader.rb +71 -0
  108. data/lib/dev_suite/utils/emoji.rb +71 -0
  109. data/lib/dev_suite/utils/error_handler.rb +24 -0
  110. data/lib/dev_suite/utils/file_loader/config/config.rb +13 -0
  111. data/lib/dev_suite/utils/file_loader/config/configuration.rb +33 -0
  112. data/lib/dev_suite/utils/file_loader/config.rb +11 -0
  113. data/lib/dev_suite/utils/file_loader/file_loader.rb +23 -0
  114. data/lib/dev_suite/utils/file_loader/loader/base.rb +21 -0
  115. data/lib/dev_suite/utils/file_loader/loader/json.rb +21 -0
  116. data/lib/dev_suite/utils/file_loader/loader/loader.rb +41 -0
  117. data/lib/dev_suite/utils/file_loader/loader/text.rb +21 -0
  118. data/lib/dev_suite/utils/file_loader/loader/yaml.rb +38 -0
  119. data/lib/dev_suite/utils/file_loader/loader.rb +13 -0
  120. data/lib/dev_suite/utils/file_loader/loader_manager.rb +34 -0
  121. data/lib/dev_suite/utils/file_loader/loader_registry.rb +36 -0
  122. data/lib/dev_suite/utils/file_loader.rb +9 -0
  123. data/lib/dev_suite/utils/logger.rb +58 -0
  124. data/lib/dev_suite/utils/path_matcher/matcher.rb +31 -0
  125. data/lib/dev_suite/utils/path_matcher/path_matcher.rb +17 -0
  126. data/lib/dev_suite/utils/path_matcher/pattern.rb +35 -0
  127. data/lib/dev_suite/utils/path_matcher.rb +9 -0
  128. data/lib/dev_suite/utils/table/config/config.rb +13 -0
  129. data/lib/dev_suite/utils/table/config/configuration.rb +32 -0
  130. data/lib/dev_suite/utils/table/config.rb +2 -23
  131. data/lib/dev_suite/utils/table/formatter/formatter.rb +12 -0
  132. data/lib/dev_suite/utils/table/formatter.rb +1 -2
  133. data/lib/dev_suite/utils/table/renderer/base.rb +1 -7
  134. data/lib/dev_suite/utils/table/renderer/renderer.rb +16 -0
  135. data/lib/dev_suite/utils/table/renderer/simple.rb +9 -5
  136. data/lib/dev_suite/utils/table/renderer.rb +1 -13
  137. data/lib/dev_suite/utils/table/table.rb +6 -0
  138. data/lib/dev_suite/utils/table.rb +0 -6
  139. data/lib/dev_suite/utils/utils.rb +15 -0
  140. data/lib/dev_suite/utils.rb +1 -3
  141. data/lib/dev_suite/version.rb +3 -1
  142. data/lib/dev_suite.rb +1 -10
  143. metadata +101 -44
  144. data/lib/dev_suite/directory_tree/settings.rb +0 -18
  145. data/lib/dev_suite/emoji.rb +0 -33
  146. data/lib/dev_suite/error_handler.rb +0 -22
  147. data/lib/dev_suite/logger.rb +0 -56
  148. data/lib/dev_suite/performance/reportor.rb +0 -22
  149. data/lib/dev_suite/utils/config_tools/configuration.rb +0 -134
  150. data/lib/dev_suite/utils/config_tools/settings.rb +0 -67
  151. data/lib/dev_suite/utils/config_tools.rb +0 -10
  152. data/lib/dev_suite/utils/table/settings.rb +0 -34
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Emoji
6
+ # Status-related emojis
7
+ STATUS = {
8
+ start: "🚀",
9
+ success: "✅",
10
+ error: "🚨❌",
11
+ retry: "💥",
12
+ warning: "⚠️", # For warnings
13
+ caution: "🟡", # For caution or proceed with care
14
+ }.freeze
15
+
16
+ # Action-related emojis
17
+ ACTIONS = {
18
+ update: "🔄", # For updates or changes
19
+ fix: "🔧", # For fixes or repairs
20
+ bug: "🐞", # For bugs or issues
21
+ code: "💻", # For code or technical content
22
+ }.freeze
23
+
24
+ # Notification-related emojis
25
+ NOTIFICATIONS = {
26
+ info: "ℹ️",
27
+ important: "❗",
28
+ note: "📝", # For notes or annotations
29
+ tip: "💡", # For tips or helpful hints
30
+ }.freeze
31
+
32
+ # Resource-related emojis
33
+ RESOURCES = {
34
+ document: "📄", # For representing documents or files
35
+ network: "🌐", # For network-related logs
36
+ database: "💾", # For database-related logs
37
+ cache: "🗄️", # For cache-related logs
38
+ file: "📁", # For file-related logs
39
+ cookie: "🍪", # For cookie-related logs
40
+ header: "📑", # For header-related logs
41
+ request: "📤", # For request-related logs
42
+ response: "📥", # For response-related logs
43
+ }.freeze
44
+
45
+ DEFAULT_EMOJI = "❓"
46
+
47
+ EMOJIS = STATUS.merge(ACTIONS).merge(NOTIFICATIONS).merge(RESOURCES).freeze
48
+
49
+ class << self
50
+ # Returns the emoji corresponding to the given key.
51
+ # @param key [Symbol] the key to look up the emoji
52
+ # @param default [String] the default emoji if the key is not found
53
+ # @return [String] the corresponding emoji or the default emoji
54
+ def get(key, default: DEFAULT_EMOJI)
55
+ EMOJIS[key] || default
56
+ end
57
+
58
+ # Returns all emojis categorized by their purpose.
59
+ # @return [Hash] a hash containing all emojis organized by categories.
60
+ def all
61
+ {
62
+ status: STATUS,
63
+ actions: ACTIONS,
64
+ notifications: NOTIFICATIONS,
65
+ resources: RESOURCES,
66
+ }
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module ErrorHandler
6
+ extend self # This makes all instance methods behave like class methods
7
+
8
+ def handle_error(error)
9
+ Utils::Logger.log(
10
+ "Oops! An error occurred: #{error.message}",
11
+ level: :error,
12
+ emoji: :error,
13
+ )
14
+ Utils::Logger.log(
15
+ "For more information, please refer to the README: " \
16
+ "https://github.com/patrick204nqh/dev_suite",
17
+ level: :error,
18
+ emoji: :document,
19
+ )
20
+ # exit(1)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module FileLoader
6
+ module Config
7
+ include Construct::Config::Manager
8
+
9
+ require_relative "configuration"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module FileLoader
6
+ module Config
7
+ class Configuration < Utils::Construct::Config::Base
8
+ config_attr :loaders, default_value: [:text, :json, :yaml], type: :array
9
+
10
+ register_hook :after_initialize do
11
+ setup_registry
12
+ end
13
+
14
+ # Expose the registry as a read-only attribute
15
+ attr_reader :registry
16
+
17
+ # Setup the registry based on the current loaders
18
+ def setup_registry
19
+ @registry = LoaderRegistry.new
20
+ update_registry(loaders)
21
+ end
22
+
23
+ # Update the registry with the provided loaders
24
+ def update_registry(loaders)
25
+ @registry ||= LoaderRegistry.new
26
+ @registry.clear # Clear the existing registry
27
+ Loader.registry_loaders(@registry, loaders)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module FileLoader
6
+ module Config
7
+ require_relative "config/config"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module FileLoader
6
+ require "pathname"
7
+ require "json"
8
+ require "yaml"
9
+
10
+ require_relative "loader"
11
+ require_relative "loader_registry"
12
+ require_relative "loader_manager"
13
+ require_relative "config"
14
+
15
+ class << self
16
+ def load(path)
17
+ loader = LoaderManager.new
18
+ loader.load(path)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module FileLoader
6
+ module Loader
7
+ class Base < Utils::Construct::Component::Base
8
+ class << self
9
+ def extensions
10
+ raise NotImplementedError, "You must implement the extensions method"
11
+ end
12
+ end
13
+
14
+ def load(_path)
15
+ raise NotImplementedError, "You must implement the load method"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module FileLoader
6
+ module Loader
7
+ class Json < Base
8
+ class << self
9
+ def extensions
10
+ ["json"]
11
+ end
12
+ end
13
+
14
+ def load(path)
15
+ ::JSON.parse(::File.read(path))
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module FileLoader
6
+ module Loader
7
+ require_relative "base"
8
+ require_relative "text"
9
+ require_relative "json"
10
+ require_relative "yaml"
11
+
12
+ class << self
13
+ def registry_loaders(registry, loader_symbols)
14
+ loader_classes = map_loaders(loader_symbols)
15
+ loader_classes.each do |loader|
16
+ registry.register(loader)
17
+ end
18
+ registry
19
+ end
20
+
21
+ private
22
+
23
+ def map_loaders(loader_symbols)
24
+ loader_symbols.map do |symbol|
25
+ case symbol
26
+ when :json
27
+ Loader::Json
28
+ when :text
29
+ Loader::Text
30
+ when :yaml
31
+ Loader::Yaml
32
+ else
33
+ raise "Unknown loader: #{symbol}"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module FileLoader
6
+ module Loader
7
+ class Text < Base
8
+ class << self
9
+ def extensions
10
+ ["txt"]
11
+ end
12
+ end
13
+
14
+ def load(path)
15
+ ::File.read(path)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module FileLoader
6
+ module Loader
7
+ class Yaml < Base
8
+ class << self
9
+ def extensions
10
+ ["yml", "yaml"]
11
+ end
12
+ end
13
+
14
+ def load(path, safe: true)
15
+ validate_file_existence!(path)
16
+ parse_yaml_file(path, safe)
17
+ rescue ::Psych::SyntaxError => e
18
+ handle_yaml_parsing_error(path, e)
19
+ end
20
+
21
+ private
22
+
23
+ def validate_file_existence!(path)
24
+ raise "File not found: #{path}" unless ::File.exist?(path)
25
+ end
26
+
27
+ def parse_yaml_file(path, safe)
28
+ safe ? ::YAML.safe_load_file(path) : ::YAML.load_file(path)
29
+ end
30
+
31
+ def handle_yaml_parsing_error(path, error)
32
+ raise "YAML parsing error in file #{path}: #{error.message}"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module FileLoader
6
+ module Loader
7
+ include Construct::Component::Manager
8
+
9
+ require_relative "loader/loader"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module FileLoader
6
+ class LoaderManager
7
+ def load(path)
8
+ loader = find_loader_for(path)
9
+ loader.load(path)
10
+ end
11
+
12
+ private
13
+
14
+ def find_loader_for(path)
15
+ extension = extract_extension(path)
16
+ loader = registry.find_loader(extension)
17
+ raise LoaderNotFoundError, "No loader registered for #{extension}" unless loader
18
+
19
+ loader
20
+ end
21
+
22
+ def extract_extension(path)
23
+ ::File.extname(path).delete_prefix(".")
24
+ end
25
+
26
+ def registry
27
+ Config.configuration.registry
28
+ end
29
+ end
30
+
31
+ class LoaderNotFoundError < StandardError; end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module FileLoader
6
+ class LoaderRegistry
7
+ def initialize
8
+ @registry = {}
9
+ end
10
+
11
+ def register(loader_class)
12
+ loader = loader_class.new
13
+ loader_class.extensions.each do |ext|
14
+ @registry[ext] = loader
15
+ end
16
+ end
17
+
18
+ def clear
19
+ @registry.clear
20
+ end
21
+
22
+ def find_loader(extension)
23
+ @registry[extension]
24
+ end
25
+
26
+ def registered_extensions
27
+ @registry.keys
28
+ end
29
+
30
+ def registered_loaders
31
+ @registry.values.uniq
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module FileLoader
6
+ require_relative "file_loader/file_loader"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Logger
6
+ LOG_DETAILS = {
7
+ info: { prefix: "[INFO]", color: :green },
8
+ warn: { prefix: "[WARNING]", color: :yellow },
9
+ error: { prefix: "[ERROR]", color: :red },
10
+ debug: { prefix: "[DEBUG]", color: :blue },
11
+ }.freeze
12
+
13
+ class << self
14
+ # Logs a message with an optional emoji and specified log level.
15
+ #
16
+ # @param message [String] The message to log.
17
+ # @param level [Symbol] The log level (:info, :warn, :error, :debug).
18
+ # @param emoji [String, Symbol] Optional emoji to prepend to the message.
19
+ def log(message, level: :info, emoji: nil)
20
+ emoji_icon = resolve_emoji(emoji)
21
+ formatted_message = format_message("#{emoji_icon} #{message}", level)
22
+ output_log(formatted_message)
23
+ end
24
+
25
+ private
26
+
27
+ # Resolves the emoji, either from a symbol or directly as a string.
28
+ #
29
+ # @param emoji [String, Symbol, nil] The emoji or its symbol key.
30
+ # @return [String] The resolved emoji or an empty string if none is provided.
31
+ def resolve_emoji(emoji)
32
+ return "" unless emoji
33
+
34
+ emoji.is_a?(Symbol) ? Emoji.get(emoji) : emoji
35
+ end
36
+
37
+ # Formats the log message with the appropriate prefix and color.
38
+ #
39
+ # @param message [String] The message to format.
40
+ # @param level [Symbol] The log level (:info, :warn, :error, :debug).
41
+ # @return [String] The formatted log message.
42
+ def format_message(message, level)
43
+ details = LOG_DETAILS[level]
44
+ raise ArgumentError, "Invalid log level: #{level}" unless details
45
+
46
+ Utils::Color.colorize("#{details[:prefix]} #{message}", color: details[:color])
47
+ end
48
+
49
+ # Outputs the formatted log message to the console.
50
+ #
51
+ # @param formatted_message [String] The message to output.
52
+ def output_log(formatted_message)
53
+ puts formatted_message if formatted_message
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module PathMatcher
6
+ class Matcher
7
+ def initialize(includes: [], excludes: [])
8
+ @include_patterns = includes.map { |pattern| Pattern.new(pattern) }
9
+ @exclude_patterns = excludes.map { |pattern| Pattern.new(pattern) }
10
+ end
11
+
12
+ def match?(path)
13
+ return false if excluded?(path)
14
+ return true if included?(path)
15
+
16
+ false
17
+ end
18
+
19
+ private
20
+
21
+ def included?(path)
22
+ @include_patterns.empty? || @include_patterns.any? { |pattern| pattern.match?(path) }
23
+ end
24
+
25
+ def excluded?(path)
26
+ @exclude_patterns.any? { |pattern| pattern.match?(path) }
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module PathMatcher
6
+ require_relative "pattern"
7
+ require_relative "matcher"
8
+
9
+ class << self
10
+ def match?(path, includes: [], excludes: [])
11
+ matcher = Matcher.new(includes: includes, excludes: excludes)
12
+ matcher.match?(path)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module PathMatcher
6
+ class Pattern
7
+ def initialize(pattern)
8
+ @regex = convert_to_regex(pattern)
9
+ end
10
+
11
+ def match?(path)
12
+ !!(@regex =~ path)
13
+ end
14
+
15
+ private
16
+
17
+ def convert_to_regex(pattern)
18
+ # Escape all regex special characters except '*'
19
+ pattern = Regexp.escape(pattern).gsub('\*', "*")
20
+
21
+ # Convert glob patterns to regex:
22
+ # - '**/' matches any directory level
23
+ # - '*.txt' matches any .txt file in any directory
24
+ pattern = pattern.gsub("**", ".*") # ** -> .*
25
+ pattern = pattern.gsub("*", "[^/]*") # * -> [^/]*
26
+
27
+ # Allow '*.txt' to match any .txt file in any directory by prefixing with '.*'
28
+ pattern = ".*#{pattern}" unless pattern.start_with?(".*")
29
+
30
+ Regexp.new("^#{pattern}$")
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module PathMatcher
6
+ require_relative "path_matcher/path_matcher"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Table
6
+ module Config
7
+ include Construct::Config::Manager
8
+
9
+ require_relative "configuration"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Table
6
+ module Config
7
+ class Configuration < Utils::Construct::Config::Base
8
+ set_default_settings(
9
+ colors: {
10
+ title: :cyan,
11
+ column: :yellow,
12
+ row: :default,
13
+ border: :blue,
14
+ },
15
+ # alignments: {
16
+ # column: :left,
17
+ # row: :left,
18
+ # },
19
+ )
20
+
21
+ config_attr :renderer, default_value: :simple, type: :symbol, resolver: :resolve_renderer
22
+
23
+ private
24
+
25
+ def resolve_renderer(value)
26
+ Renderer.build_component(value)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -3,29 +3,8 @@
3
3
  module DevSuite
4
4
  module Utils
5
5
  module Table
6
- class Config
7
- include ConfigTools::Configuration
8
-
9
- DEFAULT_SETTING = {
10
- colors: {
11
- title: :cyan,
12
- column: :yellow,
13
- row: :default,
14
- border: :blue,
15
- },
16
- alignments: {
17
- column: :left,
18
- row: :left,
19
- },
20
- }.freeze
21
-
22
- attr_reader :settings, :renderer
23
-
24
- def initialize(settings: {}, renderer: :simple)
25
- @settings = Settings.new(settings)
26
- @renderer = Renderer.create(renderer, settings: @settings)
27
- freeze
28
- end
6
+ module Config
7
+ require_relative "config/config"
29
8
  end
30
9
  end
31
10
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Table
6
+ module Formatter
7
+ require_relative "column_width_calculator"
8
+ require_relative "text_aligner"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -4,8 +4,7 @@ module DevSuite
4
4
  module Utils
5
5
  module Table
6
6
  module Formatter
7
- require_relative "formatter/column_width_calculator"
8
- require_relative "formatter/text_aligner"
7
+ require_relative "formatter/formatter"
9
8
  end
10
9
  end
11
10
  end