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
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DevSuite
4
4
  module Performance
5
- module Reportor
5
+ module Reporter
6
6
  module Helpers
7
7
  module StatMappings
8
8
  PROFILER_STAT_TITLES = {
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DevSuite
4
4
  module Performance
5
- module Reportor
5
+ module Reporter
6
6
  module Helpers
7
7
  module TableBuilder
8
8
  class << self
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DevSuite
4
4
  module Performance
5
- module Reportor
5
+ module Reporter
6
6
  module Helpers
7
7
  require_relative "helpers/stat_mappings"
8
8
  require_relative "helpers/table_builder"
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DevSuite
4
4
  module Performance
5
- module Reportor
5
+ module Reporter
6
6
  class Simple < Base
7
7
  #
8
8
  # Generates the performance report
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Performance
5
+ module Reporter
6
+ require_relative "reporter/base"
7
+ require_relative "reporter/simple"
8
+ require_relative "reporter/helpers"
9
+
10
+ class << self
11
+ def create(reporter)
12
+ case reporter
13
+ when :simple
14
+ Simple.new
15
+ else
16
+ raise ArgumentError, "Invalid reporter: #{reporter}"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -8,7 +8,7 @@ module DevSuite
8
8
  require_relative "performance/data"
9
9
  require_relative "performance/profiler"
10
10
  require_relative "performance/profiler_manager"
11
- require_relative "performance/reportor"
11
+ require_relative "performance/reporter"
12
12
  require_relative "performance/analyzer"
13
13
  require_relative "performance/config"
14
14
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Adapter
6
+ require "net/http"
7
+
8
+ require_relative "base"
9
+ require_relative "net_http"
10
+
11
+ class << self
12
+ def create(adapter)
13
+ case adapter
14
+ when :net_http
15
+ NetHttp.new
16
+ else
17
+ raise ArgumentError, "Adapter not found: #{adapter}"
18
+ end
19
+ end
20
+
21
+ def create_multiple(adapters)
22
+ adapters.map { |adapter| create(adapter) }
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Adapter
6
+ class Base
7
+ def enable
8
+ raise NotImplementedError
9
+ end
10
+
11
+ def disable
12
+ raise NotImplementedError
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Adapter
6
+ class NetHttp < Base
7
+ # Enables the logging of Net::HTTP requests by monkey patching the request method
8
+ def enable
9
+ ::Net::HTTP.class_eval do
10
+ # Alias the original request method with a unique name (_original_request)
11
+ # This preserves the original functionality so it can still be called after logging is added
12
+ alias_method(:_original_request, :request)
13
+
14
+ # Override the request method to add logging functionality
15
+ def request(request, body = nil, &block)
16
+ # Log the full URL of the HTTP request using the DevSuite::Utils::Logger
17
+ Logger.log_request(self, request)
18
+
19
+ # Call the original request method (now aliased as _original_request) to perform the actual HTTP request
20
+ response = _original_request(request, body, &block)
21
+
22
+ # Optionally log the response details
23
+ Logger.log_response(self, response)
24
+
25
+ # Return the response object so that the calling code receives the expected result
26
+ response
27
+ end
28
+ end
29
+ end
30
+
31
+ # Disables the logging by restoring the original Net::HTTP request method
32
+ def disable
33
+ ::Net::HTTP.class_eval do
34
+ # Restore the original request method by aliasing it back from _original_request
35
+ # This effectively removes the logging functionality and returns Net::HTTP to its original state
36
+ alias_method(:request, :_original_request)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Adapter
6
+ require_relative "adapter/adapter"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Config
6
+ include Utils::Construct::Config
7
+
8
+ require_relative "configuration"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Config
6
+ class Configuration < BaseConfiguration
7
+ set_default_settings(
8
+ log_headers: true,
9
+ log_cookies: true,
10
+ log_body: true,
11
+ log_level: :debug,
12
+ )
13
+
14
+ config_attr :adapters, default_value: [:net_http], type: :array, resolver: :resolve_adapters
15
+
16
+ private
17
+
18
+ def resolve_adapters(value)
19
+ Adapter.create_multiple(value)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Config
6
+ require_relative "config/config"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Logger
6
+ class << self
7
+ def log_request(adapter, request)
8
+ log_entry(format_request_line(adapter, request), :start)
9
+ log_headers(request) if settings.get(:log_headers)
10
+ log_cookies(request) if settings.get(:log_cookies)
11
+ log_body(request.body, "Request") if settings.get(:log_body)
12
+ end
13
+
14
+ def log_response(adapter, response)
15
+ status_emoji = determine_status_emoji(response)
16
+ log_level = determine_log_level(response)
17
+
18
+ log_entry(format_response_line(adapter, response), status_emoji, log_level)
19
+ log_headers(response) if settings.get(:log_headers)
20
+ log_body(response.body, "Response") if settings.get(:log_body)
21
+ end
22
+
23
+ private
24
+
25
+ def config
26
+ Config.configuration
27
+ end
28
+
29
+ def settings
30
+ config.settings
31
+ end
32
+
33
+ def log_entry(message, emoji, level = settings.get(:log_level))
34
+ Utils::Logger.log(message, level: level, emoji: emoji)
35
+ end
36
+
37
+ def determine_status_emoji(response)
38
+ response_success?(response) ? :success : :error
39
+ end
40
+
41
+ def determine_log_level(response)
42
+ response_success?(response) ? settings.get(:log_level) : :error
43
+ end
44
+
45
+ def response_success?(response)
46
+ response.code.to_i.between?(200, 299)
47
+ end
48
+
49
+ def extract_headers(request)
50
+ request.each_header.to_h
51
+ end
52
+
53
+ def extract_cookies(request)
54
+ if request.respond_to?(:to_hash) && request.to_hash["cookie"]
55
+ request.to_hash["cookie"]
56
+ elsif request.respond_to?(:headers) && request.headers["Cookie"]
57
+ [request.headers["Cookie"]]
58
+ else
59
+ []
60
+ end
61
+ end
62
+
63
+ def format_request_line(adapter, request)
64
+ "#{adapter.class} Request: #{request.method} #{request.uri}"
65
+ end
66
+
67
+ def format_response_line(adapter, response)
68
+ "#{adapter.class} Response: #{response.code} #{response.message}"
69
+ end
70
+
71
+ def log_headers(request)
72
+ headers = extract_headers(request)
73
+ log_entry("Headers: #{headers}", :document) unless headers.empty?
74
+ end
75
+
76
+ def log_cookies(request)
77
+ cookies = extract_cookies(request)
78
+ if cookies.any?
79
+ log_entry("Cookies: #{cookies.join("; ")}", :cookie)
80
+ else
81
+ log_entry("Cookies: None", :cookie)
82
+ end
83
+ end
84
+
85
+ def log_body(body, type)
86
+ return unless body && !body.empty?
87
+
88
+ log_entry("#{type} Body: #{body}", :code)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ require_relative "config"
6
+ require_relative "adapter"
7
+ require_relative "logger"
8
+
9
+ class << self
10
+ def with_logging(&block)
11
+ enable_adapters
12
+ block.call
13
+ ensure
14
+ # Ensure that adapters are disabled even if an exception is raised
15
+ disable_adapters
16
+ end
17
+
18
+ private
19
+
20
+ def enable_adapters
21
+ Config.configuration.adapters.each(&:enable)
22
+ end
23
+
24
+ def disable_adapters
25
+ Config.configuration.adapters.each(&:disable)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ require_relative "request_logger/request_logger"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Color
6
+ require_relative "colorizer"
7
+ require_relative "palette"
8
+ require_relative "strategy"
9
+ require_relative "config"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Color
6
+ module Config
7
+ include Construct::Config
8
+
9
+ require_relative "configuration"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Color
6
+ module Config
7
+ class Configuration < BaseConfiguration
8
+ config_attr :strategy,
9
+ default_value: :theme,
10
+ type: :symbol,
11
+ resolver: :resolve_strategy
12
+
13
+ config_attr :palette,
14
+ default_value: :default,
15
+ type: :symbol,
16
+ resolver: :resolve_palette
17
+
18
+ private
19
+
20
+ def resolve_strategy(value)
21
+ Strategy.create(value)
22
+ end
23
+
24
+ def resolve_palette(value)
25
+ Palette.create(value)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -3,37 +3,8 @@
3
3
  module DevSuite
4
4
  module Utils
5
5
  module Color
6
- class Config
7
- attr_accessor :strategy, :palette
8
-
9
- def initialize(strategy: :theme, palette: :default)
10
- @palette = Palette.create(palette)
11
- @strategy = Strategy.create(strategy, palette: @palette)
12
- freeze # Make the instance of this class immutable as well
13
- end
14
-
15
- class << self
16
- #
17
- # Provide global access to a single instance of Config
18
- #
19
- def configuration
20
- @configuration ||= new
21
- end
22
-
23
- # Allow block-based configuration
24
- def configure
25
- yield(configuration)
26
- rescue StandardError => e
27
- handle_configuration_error(e)
28
- raise
29
- end
30
-
31
- private
32
-
33
- def handle_configuration_error(error)
34
- puts "Configuration error: #{error.message}"
35
- end
36
- end
6
+ module Config
7
+ require_relative "config/config"
37
8
  end
38
9
  end
39
10
  end
@@ -5,17 +5,12 @@ module DevSuite
5
5
  module Color
6
6
  module Strategy
7
7
  class Theme < Base
8
- def initialize(palette)
9
- super()
10
- @palette = palette
11
- end
12
-
13
8
  def colorize(text, color: :default)
14
- unless @palette.colors.key?(color)
9
+ unless palette.colors.key?(color)
15
10
  raise ArgumentError, "Invalid color key"
16
11
  end
17
12
 
18
- color_code = @palette.colors[color]
13
+ color_code = palette.colors[color]
19
14
 
20
15
  unless valid_color_code?(color_code)
21
16
  raise ArgumentError, "Invalid color code"
@@ -26,6 +21,10 @@ module DevSuite
26
21
 
27
22
  private
28
23
 
24
+ def palette
25
+ Config.configuration.palette
26
+ end
27
+
29
28
  def valid_color_code?(color_code)
30
29
  color_code.is_a?(Integer) && color_code.between?(0, 255)
31
30
  end
@@ -10,16 +10,14 @@ module DevSuite
10
10
  require_relative "strategy/theme"
11
11
 
12
12
  class << self
13
- def create(type, palette: nil)
13
+ def create(type)
14
14
  case type
15
15
  when :basic
16
16
  Basic.new
17
17
  when :rgb
18
18
  Rgb.new
19
19
  when :theme
20
- raise ArgumentError, "Palette is required for theme strategy" unless palette
21
-
22
- Theme.new(palette)
20
+ Theme.new
23
21
  else
24
22
  raise ArgumentError, "Unknown strategy type: #{type}"
25
23
  end
@@ -3,10 +3,7 @@
3
3
  module DevSuite
4
4
  module Utils
5
5
  module Color
6
- require_relative "color/colorizer"
7
- require_relative "color/palette"
8
- require_relative "color/strategy"
9
- require_relative "color/config"
6
+ require_relative "color/color"
10
7
  end
11
8
  end
12
9
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Construct
6
+ module Config
7
+ module Attribute
8
+ require_relative "validator"
9
+ require_relative "resolver"
10
+ require_relative "manager"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Construct
6
+ module Config
7
+ module Attribute
8
+ module Manager
9
+ include Validator
10
+ include Resolver
11
+
12
+ class << self
13
+ def included(base)
14
+ base.extend(ClassMethods)
15
+ end
16
+ end
17
+
18
+ module ClassMethods
19
+ def config_attr(attr, default_value: nil, type: nil, resolver: nil)
20
+ config_attrs[attr] = { default_value: default_value, type: type, resolver: resolver }
21
+ define_config_attr_methods(attr)
22
+ end
23
+
24
+ def config_attrs
25
+ @config_attrs ||= {}
26
+ end
27
+
28
+ def config_attr_present?(attr)
29
+ config_attrs.key?(attr)
30
+ end
31
+
32
+ private
33
+
34
+ def define_config_attr_methods(attr)
35
+ define_method(attr) { instance_variable_get("@#{attr}") }
36
+ define_method("#{attr}=") do |value|
37
+ validate_and_set_config_attr(attr: attr, value: value)
38
+ end
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def initialize_config_attrs
45
+ self.class.config_attrs.each do |attr, details|
46
+ send("#{attr}=", details[:default_value]) unless instance_variable_defined?("@#{attr}")
47
+ end
48
+ end
49
+
50
+ def validate_and_set_config_attr(attr:, value:)
51
+ attr_details = self.class.config_attrs[attr]
52
+ type, resolver = attr_details.values_at(:type, :resolver)
53
+
54
+ validate_config_attr_type!(attr: attr, value: value, type: type) if type
55
+ resolved_value = resolver ? resolve_config_attr(value: value, resolver: resolver) : value
56
+ instance_variable_set("@#{attr}", resolved_value)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Construct
6
+ module Config
7
+ module Attribute
8
+ module Resolver
9
+ extend self
10
+
11
+ # Resolves the value of an attribute based on its resolver.
12
+ # If no resolver is provided, the value is returned as is.
13
+ #
14
+ # @param value [Object] The value to resolve.
15
+ # @param resolver [Proc] The resolver to use for the attribute.
16
+ def resolve_config_attr(value:, resolver:)
17
+ case resolver
18
+ when Proc
19
+ resolver.call(value)
20
+ when Symbol
21
+ send(resolver, value)
22
+ else
23
+ value
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Construct
6
+ module Config
7
+ module Attribute
8
+ module Validator
9
+ extend self
10
+
11
+ # Validates an attribute's value based on its type.
12
+ #
13
+ # @param attr [Symbol] The name of the attribute.
14
+ # @param value [Object] The value to validate.
15
+ # @param type [Symbol] The expected type of the attribute.
16
+ def validate_config_attr_type!(attr:, value:, type:)
17
+ case type
18
+ when :symbol
19
+ validate_symbol!(value)
20
+ when :hash
21
+ validate_hash!(value)
22
+ when :array
23
+ validate_array!(value)
24
+ when :class
25
+ validate_instance_of!(value, Object)
26
+ else
27
+ raise ArgumentError, "Unknown type #{type} for attribute #{attr}"
28
+ end
29
+ end
30
+
31
+ # Utility method to validate a Symbol.
32
+ def validate_symbol!(value)
33
+ raise ArgumentError, "Expected a Symbol, got #{value.class}" unless value.is_a?(Symbol)
34
+ end
35
+
36
+ # Utility method to validate a Hash.
37
+ def validate_hash!(value)
38
+ raise ArgumentError, "Expected a Hash, got #{value.class}" unless value.is_a?(Hash)
39
+ end
40
+
41
+ # Utility method to validate an Array.
42
+ def validate_array!(value)
43
+ raise ArgumentError, "Expected an Array, got #{value.class}" unless value.is_a?(Array)
44
+ end
45
+
46
+ # Utility method to validate a class instance.
47
+ def validate_instance_of!(value, klass)
48
+ raise ArgumentError, "Expected an instance of #{klass}, got #{value.class}" unless value.is_a?(klass)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end