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.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -5
- data/.vscode/extensions.json +8 -0
- data/.vscode/launch.json +39 -0
- data/.vscode/settings.json +28 -0
- data/Gemfile +6 -1
- data/Gemfile.lock +28 -2
- data/README.md +69 -8
- data/bin/rspec +27 -0
- data/dev_suite.gemspec +0 -4
- data/lib/dev_suite/cli/commands/base.rb +0 -2
- data/lib/dev_suite/cli/commands/tree.rb +3 -3
- data/lib/dev_suite/cli/commands/version.rb +1 -1
- data/lib/dev_suite/cli/main.rb +1 -1
- data/lib/dev_suite/dev_suite.rb +12 -0
- data/lib/dev_suite/directory_tree/builder/base.rb +1 -1
- data/lib/dev_suite/directory_tree/builder/builder.rb +13 -0
- data/lib/dev_suite/directory_tree/builder.rb +1 -12
- data/lib/dev_suite/directory_tree/config/config.rb +11 -0
- data/lib/dev_suite/directory_tree/config/configuration.rb +34 -0
- data/lib/dev_suite/directory_tree/config.rb +2 -36
- data/lib/dev_suite/directory_tree/directory_tree.rb +0 -3
- data/lib/dev_suite/directory_tree/node/node.rb +12 -0
- data/lib/dev_suite/directory_tree/node.rb +1 -4
- data/lib/dev_suite/directory_tree/renderer/base.rb +1 -7
- data/lib/dev_suite/directory_tree/renderer/renderer.rb +14 -0
- data/lib/dev_suite/directory_tree/renderer.rb +1 -13
- data/lib/dev_suite/directory_tree/visualizer/base.rb +1 -1
- data/lib/dev_suite/directory_tree/visualizer/visualizer.rb +16 -0
- data/lib/dev_suite/directory_tree/visualizer.rb +1 -15
- data/lib/dev_suite/performance/analyzer.rb +1 -1
- data/lib/dev_suite/performance/config/config.rb +11 -0
- data/lib/dev_suite/performance/config/configuration.rb +30 -0
- data/lib/dev_suite/performance/config.rb +2 -30
- data/lib/dev_suite/performance/data/data.rb +9 -0
- data/lib/dev_suite/performance/data.rb +1 -1
- data/lib/dev_suite/performance/profiler/base.rb +1 -1
- data/lib/dev_suite/performance/profiler/profiler.rb +16 -0
- data/lib/dev_suite/performance/profiler.rb +1 -20
- data/lib/dev_suite/performance/profiler_manager.rb +1 -0
- data/lib/dev_suite/performance/{reportor → reporter}/base.rb +2 -2
- data/lib/dev_suite/performance/{reportor → reporter}/helpers/stat_mappings.rb +1 -1
- data/lib/dev_suite/performance/{reportor → reporter}/helpers/table_builder.rb +1 -1
- data/lib/dev_suite/performance/{reportor → reporter}/helpers.rb +1 -1
- data/lib/dev_suite/performance/reporter/reporter.rb +15 -0
- data/lib/dev_suite/performance/{reportor → reporter}/simple.rb +1 -1
- data/lib/dev_suite/performance/reporter.rb +9 -0
- data/lib/dev_suite/performance.rb +1 -1
- data/lib/dev_suite/request_logger/adapter/adapter.rb +31 -0
- data/lib/dev_suite/request_logger/adapter/base.rb +17 -0
- data/lib/dev_suite/request_logger/adapter/faraday.rb +37 -0
- data/lib/dev_suite/request_logger/adapter/middleware/faraday.rb +22 -0
- data/lib/dev_suite/request_logger/adapter/net_http.rb +43 -0
- data/lib/dev_suite/request_logger/adapter.rb +9 -0
- data/lib/dev_suite/request_logger/config/config.rb +11 -0
- data/lib/dev_suite/request_logger/config/configuration.rb +24 -0
- data/lib/dev_suite/request_logger/config.rb +9 -0
- data/lib/dev_suite/request_logger/extractor/base.rb +17 -0
- data/lib/dev_suite/request_logger/extractor/extractor.rb +22 -0
- data/lib/dev_suite/request_logger/extractor/faraday.rb +37 -0
- data/lib/dev_suite/request_logger/extractor/net_http.rb +36 -0
- data/lib/dev_suite/request_logger/extractor.rb +9 -0
- data/lib/dev_suite/request_logger/logger.rb +87 -0
- data/lib/dev_suite/request_logger/request.rb +19 -0
- data/lib/dev_suite/request_logger/request_logger.rb +32 -0
- data/lib/dev_suite/request_logger/response.rb +28 -0
- data/lib/dev_suite/request_logger.rb +7 -0
- data/lib/dev_suite/utils/color/color.rb +12 -0
- data/lib/dev_suite/utils/color/config/config.rb +13 -0
- data/lib/dev_suite/utils/color/config/configuration.rb +31 -0
- data/lib/dev_suite/utils/color/config.rb +2 -31
- data/lib/dev_suite/utils/color/palette/base.rb +1 -14
- data/lib/dev_suite/utils/color/palette/palette.rb +16 -0
- data/lib/dev_suite/utils/color/palette.rb +1 -13
- data/lib/dev_suite/utils/color/strategy/base.rb +1 -1
- data/lib/dev_suite/utils/color/strategy/strategy.rb +20 -0
- data/lib/dev_suite/utils/color/strategy/theme.rb +6 -7
- data/lib/dev_suite/utils/color/strategy.rb +1 -21
- data/lib/dev_suite/utils/color.rb +1 -4
- data/lib/dev_suite/utils/construct/component/base.rb +30 -0
- data/lib/dev_suite/utils/construct/component/component.rb +12 -0
- data/lib/dev_suite/utils/construct/component/initializer.rb +28 -0
- data/lib/dev_suite/utils/construct/component/manager.rb +57 -0
- data/lib/dev_suite/utils/construct/component.rb +11 -0
- data/lib/dev_suite/utils/construct/config/attribute/attr_definition.rb +76 -0
- data/lib/dev_suite/utils/construct/config/attribute/attr_initialization.rb +22 -0
- data/lib/dev_suite/utils/construct/config/attribute/attr_resolving.rb +80 -0
- data/lib/dev_suite/utils/construct/config/attribute/attribute.rb +24 -0
- data/lib/dev_suite/utils/construct/config/attribute/validator.rb +55 -0
- data/lib/dev_suite/utils/construct/config/attribute.rb +13 -0
- data/lib/dev_suite/utils/construct/config/base.rb +25 -0
- data/lib/dev_suite/utils/construct/config/config.rb +16 -0
- data/lib/dev_suite/utils/construct/config/dependency_handler.rb +56 -0
- data/lib/dev_suite/utils/construct/config/hook/hook.rb +22 -0
- data/lib/dev_suite/utils/construct/config/hook/hook_registry.rb +24 -0
- data/lib/dev_suite/utils/construct/config/hook/hook_runner.rb +20 -0
- data/lib/dev_suite/utils/construct/config/hook/manager.rb +36 -0
- data/lib/dev_suite/utils/construct/config/hook.rb +13 -0
- data/lib/dev_suite/utils/construct/config/manager.rb +41 -0
- data/lib/dev_suite/utils/construct/config/settings/base.rb +59 -0
- data/lib/dev_suite/utils/construct/config/settings/manager.rb +38 -0
- data/lib/dev_suite/utils/construct/config/settings/settings.rb +14 -0
- data/lib/dev_suite/utils/construct/config/settings.rb +13 -0
- data/lib/dev_suite/utils/construct/config.rb +11 -0
- data/lib/dev_suite/utils/construct/construct.rb +10 -0
- data/lib/dev_suite/utils/construct.rb +16 -0
- data/lib/dev_suite/utils/dependency_loader.rb +71 -0
- data/lib/dev_suite/utils/emoji.rb +71 -0
- data/lib/dev_suite/utils/error_handler.rb +24 -0
- data/lib/dev_suite/utils/file_loader/config/config.rb +13 -0
- data/lib/dev_suite/utils/file_loader/config/configuration.rb +33 -0
- data/lib/dev_suite/utils/file_loader/config.rb +11 -0
- data/lib/dev_suite/utils/file_loader/file_loader.rb +23 -0
- data/lib/dev_suite/utils/file_loader/loader/base.rb +21 -0
- data/lib/dev_suite/utils/file_loader/loader/json.rb +21 -0
- data/lib/dev_suite/utils/file_loader/loader/loader.rb +41 -0
- data/lib/dev_suite/utils/file_loader/loader/text.rb +21 -0
- data/lib/dev_suite/utils/file_loader/loader/yaml.rb +38 -0
- data/lib/dev_suite/utils/file_loader/loader.rb +13 -0
- data/lib/dev_suite/utils/file_loader/loader_manager.rb +34 -0
- data/lib/dev_suite/utils/file_loader/loader_registry.rb +36 -0
- data/lib/dev_suite/utils/file_loader.rb +9 -0
- data/lib/dev_suite/utils/logger.rb +58 -0
- data/lib/dev_suite/utils/path_matcher/matcher.rb +31 -0
- data/lib/dev_suite/utils/path_matcher/path_matcher.rb +17 -0
- data/lib/dev_suite/utils/path_matcher/pattern.rb +35 -0
- data/lib/dev_suite/utils/path_matcher.rb +9 -0
- data/lib/dev_suite/utils/table/config/config.rb +13 -0
- data/lib/dev_suite/utils/table/config/configuration.rb +32 -0
- data/lib/dev_suite/utils/table/config.rb +2 -23
- data/lib/dev_suite/utils/table/formatter/formatter.rb +12 -0
- data/lib/dev_suite/utils/table/formatter.rb +1 -2
- data/lib/dev_suite/utils/table/renderer/base.rb +1 -7
- data/lib/dev_suite/utils/table/renderer/renderer.rb +16 -0
- data/lib/dev_suite/utils/table/renderer/simple.rb +9 -5
- data/lib/dev_suite/utils/table/renderer.rb +1 -13
- data/lib/dev_suite/utils/table/table.rb +6 -0
- data/lib/dev_suite/utils/table.rb +0 -6
- data/lib/dev_suite/utils/utils.rb +15 -0
- data/lib/dev_suite/utils.rb +1 -3
- data/lib/dev_suite/version.rb +3 -1
- data/lib/dev_suite.rb +1 -10
- metadata +101 -44
- data/lib/dev_suite/directory_tree/settings.rb +0 -18
- data/lib/dev_suite/emoji.rb +0 -33
- data/lib/dev_suite/error_handler.rb +0 -22
- data/lib/dev_suite/logger.rb +0 -56
- data/lib/dev_suite/performance/reportor.rb +0 -22
- data/lib/dev_suite/utils/config_tools/configuration.rb +0 -134
- data/lib/dev_suite/utils/config_tools/settings.rb +0 -67
- data/lib/dev_suite/utils/config_tools.rb +0 -10
- data/lib/dev_suite/utils/table/settings.rb +0 -34
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module RequestLogger
|
5
|
+
module Logger
|
6
|
+
class << self
|
7
|
+
def log_request(instance, request)
|
8
|
+
request = extract_request(instance, request)
|
9
|
+
log_entry(format_request_line(instance, request), :start)
|
10
|
+
log_headers(request) if settings.get(:log_headers)
|
11
|
+
log_cookies(request) if settings.get(:log_cookies)
|
12
|
+
log_body(request.body, "Request") if settings.get(:log_body)
|
13
|
+
end
|
14
|
+
|
15
|
+
def log_response(instance, response)
|
16
|
+
response = extract_response(instance, response)
|
17
|
+
status_emoji = determine_status_emoji(response)
|
18
|
+
log_level = determine_log_level(response)
|
19
|
+
|
20
|
+
log_entry(format_response_line(instance, response), status_emoji, log_level)
|
21
|
+
log_headers(response) if settings.get(:log_headers)
|
22
|
+
log_body(response.body, "Response") if settings.get(:log_body)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def config
|
28
|
+
Config.configuration
|
29
|
+
end
|
30
|
+
|
31
|
+
def settings
|
32
|
+
config.settings
|
33
|
+
end
|
34
|
+
|
35
|
+
def extract_request(instance, request)
|
36
|
+
extractor = Extractor.build_component_from_instance(instance)
|
37
|
+
extractor.extract_request(request)
|
38
|
+
end
|
39
|
+
|
40
|
+
def extract_response(instance, response)
|
41
|
+
extractor = Extractor.build_component_from_instance(instance)
|
42
|
+
extractor.extract_response(response)
|
43
|
+
end
|
44
|
+
|
45
|
+
def log_entry(message, emoji, level = settings.get(:log_level))
|
46
|
+
Utils::Logger.log(message, level: level, emoji: emoji)
|
47
|
+
end
|
48
|
+
|
49
|
+
def determine_status_emoji(response)
|
50
|
+
response.success? ? :success : :error
|
51
|
+
end
|
52
|
+
|
53
|
+
def determine_log_level(response)
|
54
|
+
response.success? ? settings.get(:log_level) : :error
|
55
|
+
end
|
56
|
+
|
57
|
+
def format_request_line(adapter, request)
|
58
|
+
"#{adapter.class} Request: #{request.method} #{request.url}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def format_response_line(adapter, response)
|
62
|
+
"#{adapter.class} Response: #{response.status} #{response.message}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def log_headers(request)
|
66
|
+
headers = request.headers
|
67
|
+
log_entry("Headers: #{headers}", :document) unless headers.empty?
|
68
|
+
end
|
69
|
+
|
70
|
+
def log_cookies(request)
|
71
|
+
cookies = request.cookies
|
72
|
+
if cookies.any?
|
73
|
+
log_entry("Cookies: #{cookies.join("; ")}", :cookie)
|
74
|
+
else
|
75
|
+
log_entry("Cookies: None", :cookie)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def log_body(body, type)
|
80
|
+
return unless body && !body.empty?
|
81
|
+
|
82
|
+
log_entry("#{type} Body: #{body}", :code)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# request_logger/request.rb
|
4
|
+
|
5
|
+
module DevSuite
|
6
|
+
module RequestLogger
|
7
|
+
class Request
|
8
|
+
attr_reader :method, :url, :headers, :cookies, :body
|
9
|
+
|
10
|
+
def initialize(method:, url:, headers:, cookies:, body:)
|
11
|
+
@method = method
|
12
|
+
@url = url
|
13
|
+
@headers = headers
|
14
|
+
@cookies = cookies
|
15
|
+
@body = body
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module RequestLogger
|
5
|
+
require_relative "request"
|
6
|
+
require_relative "response"
|
7
|
+
require_relative "config"
|
8
|
+
require_relative "adapter"
|
9
|
+
require_relative "logger"
|
10
|
+
require_relative "extractor"
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def with_logging(&block)
|
14
|
+
enable_adapters
|
15
|
+
block.call
|
16
|
+
ensure
|
17
|
+
# Ensure that adapters are disabled even if an exception is raised
|
18
|
+
disable_adapters
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def enable_adapters
|
24
|
+
Config.configuration.adapters.each(&:enable)
|
25
|
+
end
|
26
|
+
|
27
|
+
def disable_adapters
|
28
|
+
Config.configuration.adapters.each(&:disable)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# request_logger/response.rb
|
4
|
+
|
5
|
+
module DevSuite
|
6
|
+
module RequestLogger
|
7
|
+
class Response
|
8
|
+
attr_reader :status, :message, :headers, :body
|
9
|
+
|
10
|
+
def initialize(status:, message:, headers:, body:)
|
11
|
+
@status = status.to_i # Ensure status is always an integer
|
12
|
+
@message = message
|
13
|
+
@headers = headers || {} # Default to an empty hash if headers are nil
|
14
|
+
@body = body || "" # Default to an empty string if body is nil
|
15
|
+
end
|
16
|
+
|
17
|
+
# Check if the response is successful (2xx status codes)
|
18
|
+
def success?
|
19
|
+
status.between?(200, 299)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Helper method to fetch specific headers in a case-insensitive way
|
23
|
+
def header(key)
|
24
|
+
headers[key.to_s.downcase] || headers[key.to_s]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
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 < Utils::Construct::Config::Base
|
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.build_component(value)
|
22
|
+
end
|
23
|
+
|
24
|
+
def resolve_palette(value)
|
25
|
+
Palette.build_component(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
|
-
|
7
|
-
|
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
|
@@ -4,20 +4,7 @@ module DevSuite
|
|
4
4
|
module Utils
|
5
5
|
module Color
|
6
6
|
module Palette
|
7
|
-
class Base
|
8
|
-
# Define COLORS constant in subclass
|
9
|
-
# Example:
|
10
|
-
# COLORS = {
|
11
|
-
# red: 31,
|
12
|
-
# green: 32,
|
13
|
-
# yellow: 33,
|
14
|
-
# blue: 34,
|
15
|
-
# pink: 35,
|
16
|
-
# light_blue: 36,
|
17
|
-
# white: 37
|
18
|
-
# }
|
19
|
-
#
|
20
|
-
|
7
|
+
class Base < Utils::Construct::Component::Base
|
21
8
|
def colors
|
22
9
|
unless self.class.const_defined?(:COLORS)
|
23
10
|
raise NotImplementedError, "#{self.class} must define COLORS constant"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Palette
|
7
|
+
include Construct::Component::Manager
|
8
|
+
|
9
|
+
require_relative "base"
|
10
|
+
require_relative "default"
|
11
|
+
|
12
|
+
register_component(Default)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -4,19 +4,7 @@ module DevSuite
|
|
4
4
|
module Utils
|
5
5
|
module Color
|
6
6
|
module Palette
|
7
|
-
require_relative "palette/
|
8
|
-
require_relative "palette/default"
|
9
|
-
|
10
|
-
class << self
|
11
|
-
def create(type)
|
12
|
-
case type
|
13
|
-
when :default
|
14
|
-
Default.new
|
15
|
-
else
|
16
|
-
raise ArgumentError, "Unknown palette type: #{type}"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
7
|
+
require_relative "palette/palette"
|
20
8
|
end
|
21
9
|
end
|
22
10
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Strategy
|
7
|
+
include Construct::Component::Manager
|
8
|
+
|
9
|
+
require_relative "base"
|
10
|
+
require_relative "basic"
|
11
|
+
require_relative "rgb"
|
12
|
+
require_relative "theme"
|
13
|
+
|
14
|
+
register_component(Basic)
|
15
|
+
register_component(Rgb)
|
16
|
+
register_component(Theme)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
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
|
9
|
+
unless palette.colors.key?(color)
|
15
10
|
raise ArgumentError, "Invalid color key"
|
16
11
|
end
|
17
12
|
|
18
|
-
color_code =
|
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
|
@@ -4,27 +4,7 @@ module DevSuite
|
|
4
4
|
module Utils
|
5
5
|
module Color
|
6
6
|
module Strategy
|
7
|
-
require_relative "strategy/
|
8
|
-
require_relative "strategy/basic"
|
9
|
-
require_relative "strategy/rgb"
|
10
|
-
require_relative "strategy/theme"
|
11
|
-
|
12
|
-
class << self
|
13
|
-
def create(type, palette: nil)
|
14
|
-
case type
|
15
|
-
when :basic
|
16
|
-
Basic.new
|
17
|
-
when :rgb
|
18
|
-
Rgb.new
|
19
|
-
when :theme
|
20
|
-
raise ArgumentError, "Palette is required for theme strategy" unless palette
|
21
|
-
|
22
|
-
Theme.new(palette)
|
23
|
-
else
|
24
|
-
raise ArgumentError, "Unknown strategy type: #{type}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
7
|
+
require_relative "strategy/strategy"
|
28
8
|
end
|
29
9
|
end
|
30
10
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Construct
|
6
|
+
module Component
|
7
|
+
class Base
|
8
|
+
class << self
|
9
|
+
# Returns the key for the class. If the COMPONENT_KEY constant is defined, it returns its value.
|
10
|
+
# Otherwise, it generates a key based on the class name.
|
11
|
+
def component_key
|
12
|
+
return const_get(:COMPONENT_KEY) if const_defined?(:COMPONENT_KEY)
|
13
|
+
|
14
|
+
generate_key_from_class_name
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# Generates a key from the class name by converting it to snake_case and symbolizing it.
|
20
|
+
def generate_key_from_class_name
|
21
|
+
class_name = name.split("::").last
|
22
|
+
snake_case_class_name = class_name.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
|
23
|
+
snake_case_class_name.to_sym
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Construct
|
6
|
+
module Component
|
7
|
+
module Initializer
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def define_constants(base)
|
11
|
+
structure_module = ensure_structure_module(base)
|
12
|
+
define_structure_component(structure_module)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def ensure_structure_module(base)
|
18
|
+
base.const_defined?(:Structure) ? base.const_get(:Structure) : base.const_set(:Structure, Module.new)
|
19
|
+
end
|
20
|
+
|
21
|
+
def define_structure_component(structure_module)
|
22
|
+
structure_module.const_set(:Component, Base) unless structure_module.const_defined?(:Component)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Construct
|
6
|
+
module Component
|
7
|
+
module Manager
|
8
|
+
class << self
|
9
|
+
def included(base)
|
10
|
+
base.extend(ClassMethods)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
# Stores a mapping of component symbols to their respective classes
|
16
|
+
def registered_components
|
17
|
+
@registered_components ||= {}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Register a new component
|
21
|
+
def register_component(component_class)
|
22
|
+
raise ArgumentError,
|
23
|
+
"#{component_class} must define a component_key" unless component_class.respond_to?(:component_key)
|
24
|
+
|
25
|
+
registered_components[component_class.component_key] = component_class
|
26
|
+
end
|
27
|
+
|
28
|
+
# Build a single component
|
29
|
+
def build_component(component_key)
|
30
|
+
component_class = registered_components[component_key]
|
31
|
+
|
32
|
+
raise ArgumentError, "Component not found for key: #{component_key}" unless component_class
|
33
|
+
|
34
|
+
component_class.new
|
35
|
+
end
|
36
|
+
|
37
|
+
# Build multiple components
|
38
|
+
def build_components(component_keys)
|
39
|
+
component_keys.map { |key| build_component(key) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_component_from_instance(instance)
|
43
|
+
component_class = registered_components.find do |klass, _|
|
44
|
+
instance.is_a?(klass)
|
45
|
+
end
|
46
|
+
|
47
|
+
raise ArgumentError,
|
48
|
+
"Component not found for instance: #{instance.class}" unless component_class
|
49
|
+
|
50
|
+
component_class.last.new
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Construct
|
6
|
+
module Config
|
7
|
+
module Attribute
|
8
|
+
module AttrDefinition
|
9
|
+
def config_attr(attr, default_value: nil, type: nil, resolver: nil)
|
10
|
+
config_attrs[attr] = build_attr_details(
|
11
|
+
default_value: default_value,
|
12
|
+
type: type,
|
13
|
+
resolver: resolver,
|
14
|
+
)
|
15
|
+
define_config_attr_methods(attr)
|
16
|
+
end
|
17
|
+
|
18
|
+
def config_attrs
|
19
|
+
@config_attrs ||= {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def config_attr_present?(attr)
|
23
|
+
config_attrs.key?(attr)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def build_attr_details(default_value:, type:, resolver:)
|
29
|
+
{
|
30
|
+
default_value: default_value,
|
31
|
+
type: type,
|
32
|
+
resolver: resolver,
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def define_config_attr_methods(attr)
|
37
|
+
define_getter_methods(attr)
|
38
|
+
define_setter_methods(attr)
|
39
|
+
define_delete_method(attr)
|
40
|
+
end
|
41
|
+
|
42
|
+
def define_getter_methods(attr)
|
43
|
+
define_method(attr) do
|
44
|
+
instance_variable_get("@#{attr}")
|
45
|
+
end
|
46
|
+
|
47
|
+
define_method("original_#{attr}") do
|
48
|
+
instance_variable_get("@original_#{attr}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def define_setter_methods(attr)
|
53
|
+
define_method("#{attr}=") do |value|
|
54
|
+
set_config_attr(attr: attr, value: value)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def define_delete_method(attr)
|
59
|
+
define_method("#{attr}.delete") do |*keys|
|
60
|
+
current_value = instance_variable_get("@#{attr}")
|
61
|
+
original_value = instance_variable_get("@original_#{attr}")
|
62
|
+
|
63
|
+
if original_value.is_a?(Array) && current_value.is_a?(Array)
|
64
|
+
keys.each do |key|
|
65
|
+
original_value.delete(key)
|
66
|
+
set_config_attr(attr: attr, value: original_value)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Construct
|
6
|
+
module Config
|
7
|
+
module Attribute
|
8
|
+
module AttrInitialization
|
9
|
+
private
|
10
|
+
|
11
|
+
# Initializes all configuration attributes with their default values
|
12
|
+
def initialize_config_attrs
|
13
|
+
self.class.config_attrs.each do |attr, details|
|
14
|
+
send("#{attr}=", details[:default_value]) unless instance_variable_defined?("@#{attr}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|