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
@@ -3,21 +3,7 @@
3
3
  module DevSuite
4
4
  module DirectoryTree
5
5
  module Visualizer
6
- require "pathname"
7
-
8
- require_relative "visualizer/base"
9
- require_relative "visualizer/tree"
10
-
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
20
- end
6
+ require_relative "visualizer/visualizer"
21
7
  end
22
8
  end
23
9
  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::Manager
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 < Utils::Construct::Config::Base
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.build_components(value)
22
+ end
23
+
24
+ def resolve_reporter(value)
25
+ Reporter.build_component(value)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,36 +2,8 @@
2
2
 
3
3
  module DevSuite
4
4
  module Performance
5
- class Config
6
- include Utils::ConfigTools::Configuration
7
-
8
- # Define configuration attributes
9
- config_attr :profilers, default_value: [:execution_time, :memory]
10
- config_attr :reportor, default_value: :simple
11
-
12
- private
13
-
14
- def validate_attr!(attr, value)
15
- case attr
16
- when :profilers
17
- validate_array!(attr, value)
18
- when :reportor
19
- validate_symbol!(attr, value)
20
- else
21
- raise ArgumentError, "Invalid attribute: #{attr}"
22
- end
23
- end
24
-
25
- def resolve_attr(attr, value)
26
- case attr
27
- when :profilers
28
- Profiler.create_multiple(value)
29
- when :reportor
30
- Reportor.create(value)
31
- else
32
- value
33
- end
34
- end
5
+ module Config
6
+ require_relative "config/config"
35
7
  end
36
8
  end
37
9
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Performance
5
+ module Data
6
+ require_relative "memory_usage"
7
+ end
8
+ end
9
+ end
@@ -3,7 +3,7 @@
3
3
  module DevSuite
4
4
  module Performance
5
5
  module Data
6
- require_relative "data/memory_usage"
6
+ require_relative "data/data"
7
7
  end
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@
3
3
  module DevSuite
4
4
  module Performance
5
5
  module Profiler
6
- class Base
6
+ class Base < Utils::Construct::Component::Base
7
7
  def run(&block)
8
8
  raise NotImplementedError, "Subclasses must implement the run method"
9
9
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Performance
5
+ module Profiler
6
+ include Utils::Construct::Component::Manager
7
+
8
+ require_relative "base"
9
+ require_relative "execution_time"
10
+ require_relative "memory"
11
+
12
+ register_component(ExecutionTime)
13
+ register_component(Memory)
14
+ end
15
+ end
16
+ end
@@ -3,26 +3,7 @@
3
3
  module DevSuite
4
4
  module Performance
5
5
  module Profiler
6
- require_relative "profiler/base"
7
- require_relative "profiler/execution_time"
8
- require_relative "profiler/memory"
9
-
10
- class << self
11
- def create(profiler)
12
- case profiler
13
- when :execution_time
14
- ExecutionTime.new
15
- when :memory
16
- Memory.new
17
- else
18
- raise ArgumentError, "Invalid profiler: #{profiler}"
19
- end
20
- end
21
-
22
- def create_multiple(profilers)
23
- profilers.map { |profiler| create(profiler) }
24
- end
25
- end
6
+ require_relative "profiler/profiler"
26
7
  end
27
8
  end
28
9
  end
@@ -5,6 +5,7 @@ module DevSuite
5
5
  class ProfilerManager
6
6
  attr_reader :results
7
7
 
8
+ # TODO: building as function in Construct::Component
8
9
  def initialize
9
10
  @results = {}
10
11
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module DevSuite
4
4
  module Performance
5
- module Reportor
6
- class Base
5
+ module Reporter
6
+ class Base < Utils::Construct::Component::Base
7
7
  def generate
8
8
  raise NotImplementedError, "Subclasses must implement the generate method"
9
9
  end
@@ -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"
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Performance
5
+ module Reporter
6
+ include Utils::Construct::Component::Manager
7
+
8
+ require_relative "base"
9
+ require_relative "simple"
10
+ require_relative "helpers"
11
+
12
+ register_component(Simple)
13
+ end
14
+ end
15
+ end
@@ -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,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Performance
5
+ module Reporter
6
+ require_relative "reporter/reporter"
7
+ end
8
+ end
9
+ 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,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Adapter
6
+ include Utils::Construct::Component::Manager
7
+
8
+ require_relative "base"
9
+
10
+ class << self
11
+ def handle_missing_dependencies(missing_dependencies)
12
+ Config.configuration.delete_option_on_failure(:adapters, :faraday, *missing_dependencies)
13
+ end
14
+ end
15
+
16
+ # Load and register `net/http` adapter
17
+ require "net/http"
18
+ require_relative "net_http"
19
+ register_component(NetHttp)
20
+
21
+ # Load and register `faraday` adapter
22
+ Utils::DependencyLoader.safe_load_dependencies(
23
+ "faraday",
24
+ on_failure: method(:handle_missing_dependencies),
25
+ ) do
26
+ require_relative "faraday"
27
+ register_component(Faraday)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Adapter
6
+ class Base < Utils::Construct::Component::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,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Adapter
6
+ require_relative "middleware/faraday"
7
+
8
+ class Faraday < Base
9
+ def enable
10
+ ::Faraday::Connection.class_eval do
11
+ alias_method(:_original_run_request, :run_request)
12
+
13
+ def run_request(method, url, body, headers, &block)
14
+ env = ::Faraday::Env.new(method, url, body, headers)
15
+ env.request = @request
16
+ env.params = @params
17
+ env.request_body = @request_body
18
+ env.ssl = @ssl
19
+ env.response = @response
20
+
21
+ Middleware::Faraday.new(lambda do |e|
22
+ _original_run_request(e.method, e.url, e.body, e.request_headers, &block)
23
+ end).call(env)
24
+ end
25
+ end
26
+ end
27
+
28
+ def disable
29
+ ::Faraday::Connection.class_eval do
30
+ alias_method(:run_request, :_original_run_request)
31
+ remove_method(:_original_run_request)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Adapter
6
+ module Middleware
7
+ class Faraday < ::Faraday::Middleware
8
+ def call(env)
9
+ # Log the request details
10
+ Logger.log_request(self, env)
11
+
12
+ # Perform the actual request
13
+ @app.call(env).on_complete do |response_env|
14
+ # Log the response details
15
+ Logger.log_response(self, response_env)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,43 @@
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
+ remove_method(:_original_request)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Adapters
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::Manager
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 < Utils::Construct::Config::Base
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.build_components(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,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Extractor
6
+ class Base < Utils::Construct::Component::Base
7
+ def extract_request(native_request)
8
+ raise NotImplementedError
9
+ end
10
+
11
+ def extract_response(native_response)
12
+ raise NotImplementedError
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Extractor
6
+ include Utils::Construct::Component::Manager
7
+
8
+ require_relative "base"
9
+ require_relative "net_http"
10
+
11
+ register_component(NetHttp)
12
+
13
+ Utils::DependencyLoader.safe_load_dependencies(
14
+ "faraday",
15
+ on_failure: ->(_) {}, # Empty lambda to do nothing on failure
16
+ ) do
17
+ require_relative "faraday"
18
+ register_component(Faraday)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Extractor
6
+ class Faraday < Base
7
+ COMPONENT_KEY = ::Faraday::Middleware
8
+
9
+ def extract_request(native_request)
10
+ Request.new(
11
+ method: native_request.method.to_s.upcase,
12
+ url: native_request.url.to_s,
13
+ headers: native_request.request_headers.to_h,
14
+ cookies: extract_cookies(native_request.request_headers),
15
+ body: native_request.body,
16
+ )
17
+ end
18
+
19
+ def extract_response(native_response)
20
+ Response.new(
21
+ status: native_response.status,
22
+ message: native_response.reason_phrase || "",
23
+ headers: native_response.response_headers.to_h,
24
+ body: native_response.body,
25
+ )
26
+ end
27
+
28
+ private
29
+
30
+ def extract_cookies(headers)
31
+ headers = headers.to_h
32
+ headers["Cookie"] ? [headers["Cookie"]] : []
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module RequestLogger
5
+ module Extractor
6
+ class NetHttp < Base
7
+ COMPONENT_KEY = ::Net::HTTP
8
+
9
+ def extract_request(native_request)
10
+ Request.new(
11
+ method: native_request.method,
12
+ url: native_request.uri.to_s,
13
+ headers: native_request.each_header.to_h,
14
+ cookies: extract_cookies(native_request),
15
+ body: native_request.body,
16
+ )
17
+ end
18
+
19
+ def extract_response(native_response)
20
+ Response.new(
21
+ status: native_response.code.to_i,
22
+ message: native_response.message,
23
+ headers: native_response.each_header.to_h,
24
+ body: native_response.body,
25
+ )
26
+ end
27
+
28
+ private
29
+
30
+ def extract_cookies(request)
31
+ request.to_hash["cookie"] || []
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 RequestLogger
5
+ module Extractor
6
+ require_relative "extractor/extractor"
7
+ end
8
+ end
9
+ end