dev_suite 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/dev_suite/directory_tree/config.rb +39 -0
- data/lib/dev_suite/directory_tree/node/directory.rb +0 -2
- data/lib/dev_suite/directory_tree/node/file.rb +0 -2
- data/lib/dev_suite/directory_tree/node/permission_denied.rb +0 -2
- data/lib/dev_suite/directory_tree/node.rb +1 -0
- data/lib/dev_suite/directory_tree/renderer/base.rb +12 -5
- data/lib/dev_suite/directory_tree/renderer/simple.rb +45 -32
- data/lib/dev_suite/directory_tree/renderer.rb +12 -0
- data/lib/dev_suite/directory_tree/visualizer.rb +13 -11
- data/lib/dev_suite/directory_tree.rb +3 -0
- data/lib/dev_suite/performance/analyzer.rb +9 -15
- data/lib/dev_suite/performance/profiler/benchmark.rb +0 -1
- data/lib/dev_suite/performance/profiler/memory.rb +0 -3
- data/lib/dev_suite/performance/profiler.rb +1 -0
- data/lib/dev_suite/performance/reportor/simple.rb +0 -3
- data/lib/dev_suite/performance/reportor.rb +1 -0
- data/lib/dev_suite/performance.rb +3 -0
- data/lib/dev_suite/utils/color/colorizer.rb +28 -0
- data/lib/dev_suite/utils/color/config.rb +40 -0
- data/lib/dev_suite/utils/color/palette/base.rb +32 -0
- data/lib/dev_suite/utils/color/palette/default.rb +22 -0
- data/lib/dev_suite/utils/color/palette.rb +23 -0
- data/lib/dev_suite/utils/color/strategy/base.rb +15 -0
- data/lib/dev_suite/utils/color/strategy/basic.rb +25 -0
- data/lib/dev_suite/utils/color/strategy/rgb.rb +27 -0
- data/lib/dev_suite/utils/color/strategy/theme.rb +36 -0
- data/lib/dev_suite/utils/color/strategy.rb +31 -0
- data/lib/dev_suite/utils/color.rb +12 -0
- data/lib/dev_suite/utils/table/column.rb +6 -2
- data/lib/dev_suite/utils/table/config.rb +26 -2
- data/lib/dev_suite/utils/table/formatter.rb +12 -0
- data/lib/dev_suite/utils/table/renderer/simple.rb +1 -6
- data/lib/dev_suite/utils/table/row.rb +6 -2
- data/lib/dev_suite/utils/table/table.rb +0 -5
- data/lib/dev_suite/utils/table.rb +14 -0
- data/lib/dev_suite/utils.rb +2 -3
- data/lib/dev_suite/version.rb +1 -1
- data/lib/dev_suite.rb +1 -0
- metadata +15 -4
- data/lib/dev_suite/utils/table/column/column.rb +0 -15
- data/lib/dev_suite/utils/table/formatter/colorizer.rb +0 -33
- data/lib/dev_suite/utils/table/row/row.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76f0e8870b8fe2bb1c8af41e541bd09f792662f49c1a869d5ddcf5fd4ae94584
|
4
|
+
data.tar.gz: 17a921feedc29e07133ce357fbb3b37ecd15800cd30f4fd3087d62f4a810970d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a32bb7865ee17f49b639d687950cfafeecc51df0dc9e2e7a7ef62018ea185fd522081f8c7b70c0346d0b77ec4d119030c7e9464cf38f4928dad11ee756baa01a
|
7
|
+
data.tar.gz: 668586bdbd2339888ef486a5e2fb424aa0f3532d8fa80e27f92f569e59506b2237852683725560e55109eb93c5af63d51e6333aceea5dcb018604574733be5ef
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -51,7 +51,7 @@ DevSuite::SomeUtility.do_something
|
|
51
51
|
```ruby
|
52
52
|
require 'dev_suite'
|
53
53
|
|
54
|
-
DevSuite::Performance
|
54
|
+
DevSuite::Performance.analyze(description: "My Code Block") do
|
55
55
|
sum = 0
|
56
56
|
1_000_000.times do |i|
|
57
57
|
sum += i
|
@@ -93,7 +93,7 @@ DevSuite::SomeUtility.do_something
|
|
93
93
|
base_path = "/path/to/your/directory"
|
94
94
|
|
95
95
|
# Perform the visualization
|
96
|
-
DevSuite::DirectoryTree
|
96
|
+
DevSuite::DirectoryTree.visualize(base_path)
|
97
97
|
```
|
98
98
|
|
99
99
|
**Example output**
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module DirectoryTree
|
5
|
+
class Config
|
6
|
+
attr_reader :renderer
|
7
|
+
|
8
|
+
def initialize(renderer: :simple)
|
9
|
+
@renderer = Renderer.create(renderer)
|
10
|
+
freeze # Make the instance of this class immutable as well
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
#
|
15
|
+
# Provide global access to a single instance of Config
|
16
|
+
#
|
17
|
+
def configuration
|
18
|
+
@configuration ||= new
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Allow block-based configuration
|
23
|
+
#
|
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
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -6,17 +6,24 @@ module DevSuite
|
|
6
6
|
module DirectoryTree
|
7
7
|
module Renderer
|
8
8
|
class Base
|
9
|
-
def
|
10
|
-
|
11
|
-
end
|
9
|
+
def render(path)
|
10
|
+
raise ArgumentError, "Invalid path" unless valid_path?(path)
|
12
11
|
|
13
|
-
|
14
|
-
root = build_tree(@base_path)
|
12
|
+
root = build_tree(Pathname.new(path))
|
15
13
|
render_node(root, "", true)
|
16
14
|
end
|
17
15
|
|
18
16
|
private
|
19
17
|
|
18
|
+
def valid_path?(path)
|
19
|
+
[
|
20
|
+
path.is_a?(String),
|
21
|
+
::File.exist?(path),
|
22
|
+
::File.directory?(path),
|
23
|
+
::File.readable?(path),
|
24
|
+
].all?
|
25
|
+
end
|
26
|
+
|
20
27
|
# Builds the tree structure
|
21
28
|
# @param path [Pathname] The path to build the tree from
|
22
29
|
# @return [Node::Base] The root node of the tree
|
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "base"
|
4
|
-
require_relative "../node"
|
5
|
-
|
6
3
|
module DevSuite
|
7
4
|
module DirectoryTree
|
8
5
|
module Renderer
|
@@ -10,51 +7,67 @@ module DevSuite
|
|
10
7
|
private
|
11
8
|
|
12
9
|
def build_tree(path)
|
13
|
-
return
|
10
|
+
return permission_denied_node(path) unless path.readable?
|
14
11
|
|
15
|
-
|
16
|
-
dir = Node::Directory.new(path.basename.to_s)
|
17
|
-
children = path.children.sort_by { |child| child.basename.to_s.downcase }
|
18
|
-
children.each do |child|
|
19
|
-
dir.add_child(build_tree(child))
|
20
|
-
end
|
21
|
-
dir
|
22
|
-
else
|
23
|
-
Node::File.new(path.basename.to_s)
|
24
|
-
end
|
12
|
+
path.directory? ? directory_node(path) : file_node(path)
|
25
13
|
rescue Errno::EACCES
|
26
|
-
|
14
|
+
permission_denied_node(path)
|
27
15
|
end
|
28
16
|
|
29
17
|
def render_node(node, prefix = "", is_last = true)
|
30
|
-
# Determine if this is the root node based on the prefix content
|
31
18
|
is_root = prefix.empty?
|
19
|
+
connector = determine_connector(is_root, is_last)
|
20
|
+
new_prefix = update_prefix(prefix, is_last)
|
32
21
|
|
33
|
-
|
34
|
-
|
35
|
-
""
|
36
|
-
else
|
37
|
-
(is_last ? "└── " : "├── ")
|
38
|
-
end
|
39
|
-
|
40
|
-
# Compute the new prefix for children
|
41
|
-
new_prefix = "#{prefix}#{is_last ? " " : "| "}"
|
42
|
-
|
43
|
-
# Construct the output for the current node, avoiding the connector for the root
|
44
|
-
output = "#{prefix}#{connector}#{node.name}"
|
45
|
-
output += "/\n" if node.directory?
|
22
|
+
output = construct_output(node, prefix, connector)
|
23
|
+
output += node_suffix(node)
|
46
24
|
|
47
|
-
# Recursively render children if it's a directory
|
48
25
|
if node.directory? && node.children.any?
|
49
26
|
node.children.each_with_index do |child, index|
|
50
27
|
output += render_node(child, new_prefix, index == node.children.size - 1)
|
51
28
|
end
|
52
|
-
elsif !node.directory?
|
53
|
-
output += "\n"
|
54
29
|
end
|
55
30
|
|
56
31
|
output
|
57
32
|
end
|
33
|
+
|
34
|
+
def determine_connector(is_root, is_last)
|
35
|
+
return "" if is_root
|
36
|
+
|
37
|
+
is_last ? "└── " : "├── "
|
38
|
+
end
|
39
|
+
|
40
|
+
def update_prefix(prefix, is_last)
|
41
|
+
"#{prefix}#{is_last ? " " : "| "}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def construct_output(node, prefix, connector)
|
45
|
+
"#{prefix}#{connector}#{node.name}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def node_suffix(node)
|
49
|
+
node.directory? ? "/\n" : "\n"
|
50
|
+
end
|
51
|
+
|
52
|
+
def directory_node(path)
|
53
|
+
dir = Node::Directory.new(path.basename.to_s)
|
54
|
+
sorted_children(path).each do |child|
|
55
|
+
dir.add_child(build_tree(child))
|
56
|
+
end
|
57
|
+
dir
|
58
|
+
end
|
59
|
+
|
60
|
+
def file_node(path)
|
61
|
+
Node::File.new(path.basename.to_s)
|
62
|
+
end
|
63
|
+
|
64
|
+
def permission_denied_node(path)
|
65
|
+
Node::PermissionDenied.new(path.basename.to_s, path.directory?)
|
66
|
+
end
|
67
|
+
|
68
|
+
def sorted_children(path)
|
69
|
+
path.children.sort_by { |child| child.basename.to_s.downcase }
|
70
|
+
end
|
58
71
|
end
|
59
72
|
end
|
60
73
|
end
|
@@ -3,7 +3,19 @@
|
|
3
3
|
module DevSuite
|
4
4
|
module DirectoryTree
|
5
5
|
module Renderer
|
6
|
+
require_relative "renderer/base"
|
6
7
|
require_relative "renderer/simple"
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def create(type)
|
11
|
+
case type
|
12
|
+
when :simple
|
13
|
+
Simple.new
|
14
|
+
else
|
15
|
+
raise ArgumentError, "Unknown renderer type: #{type}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
7
19
|
end
|
8
20
|
end
|
9
21
|
end
|
@@ -1,25 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "pathname"
|
4
|
-
require_relative "renderer"
|
5
4
|
|
6
5
|
module DevSuite
|
7
6
|
module DirectoryTree
|
8
7
|
class Visualizer
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
new(base_path).visualize
|
14
|
-
end
|
8
|
+
attr_reader :config
|
9
|
+
|
10
|
+
def initialize(config = Config.configuration)
|
11
|
+
@config = config
|
15
12
|
end
|
16
13
|
|
17
|
-
|
18
|
-
|
14
|
+
# Visualizes the directory tree
|
15
|
+
# @param path [String] The base path of the directory
|
16
|
+
def visualize(path)
|
17
|
+
puts @config.renderer.render(path)
|
19
18
|
end
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
class << self
|
22
|
+
def visualize(path)
|
23
|
+
visualizer = Visualizer.new
|
24
|
+
visualizer.visualize(path)
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
@@ -1,23 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "reportor"
|
4
|
-
require_relative "profiler"
|
5
|
-
|
6
3
|
module DevSuite
|
7
4
|
module Performance
|
8
5
|
class Analyzer
|
9
|
-
class << self
|
10
|
-
# Generates a performance report
|
11
|
-
# @param benchmark_result [Benchmark::Tms] The benchmark result
|
12
|
-
# @param memory_stats [Hash] The memory statistics
|
13
|
-
def analyze(description: "Block", &block)
|
14
|
-
raise ArgumentError, "No block given" unless block_given?
|
15
|
-
|
16
|
-
analyzer = new(description: description)
|
17
|
-
analyzer.analyze(&block)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
6
|
def initialize(description: "Block")
|
22
7
|
@description = description
|
23
8
|
@benchmark_profiler = Profiler::Benchmark.new
|
@@ -29,6 +14,8 @@ module DevSuite
|
|
29
14
|
# @param block [Proc] The block to be analyzed
|
30
15
|
# @raise [ArgumentError] If no block is given
|
31
16
|
def analyze(&block)
|
17
|
+
raise ArgumentError, "No block given" unless block_given?
|
18
|
+
|
32
19
|
memory_before = @memory_usage.current
|
33
20
|
benchmark_result = profile_benchmark(&block)
|
34
21
|
memory_after = @memory_usage.current
|
@@ -61,5 +48,12 @@ module DevSuite
|
|
61
48
|
reportor.generate
|
62
49
|
end
|
63
50
|
end
|
51
|
+
|
52
|
+
class << self
|
53
|
+
def analyze(description: "Block", &block)
|
54
|
+
analyzer = Analyzer.new(description: description)
|
55
|
+
analyzer.analyze(&block)
|
56
|
+
end
|
57
|
+
end
|
64
58
|
end
|
65
59
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
class Colorizer
|
7
|
+
attr_reader :config
|
8
|
+
|
9
|
+
def initialize(config = Config.configuration)
|
10
|
+
@config = config
|
11
|
+
end
|
12
|
+
|
13
|
+
def colorize(text, **kargs)
|
14
|
+
puts @config.strategy.colorize(text, **kargs)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def colorize(text, **kargs)
|
20
|
+
raise ArgumentError, "Text to colorize must be a string" unless text.is_a?(String)
|
21
|
+
|
22
|
+
colorizer = Colorizer.new
|
23
|
+
colorizer.colorize(text, **kargs)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
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
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
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
|
+
|
21
|
+
def colors
|
22
|
+
unless self.class.const_defined?(:COLORS)
|
23
|
+
raise NotImplementedError, "#{self.class} must define COLORS constant"
|
24
|
+
end
|
25
|
+
|
26
|
+
self.class::COLORS
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Palette
|
7
|
+
class Default < Base
|
8
|
+
COLORS = {
|
9
|
+
red: 31,
|
10
|
+
green: 32,
|
11
|
+
yellow: 33,
|
12
|
+
blue: 34,
|
13
|
+
magenta: 35,
|
14
|
+
cyan: 36,
|
15
|
+
white: 37,
|
16
|
+
default: 39,
|
17
|
+
}.freeze
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Palette
|
7
|
+
require_relative "palette/base"
|
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
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Strategy
|
7
|
+
class Basic < Base
|
8
|
+
def colorize(text, color: :default)
|
9
|
+
unless valid_color_code?(color)
|
10
|
+
raise ArgumentError, "Invalid color code"
|
11
|
+
end
|
12
|
+
|
13
|
+
"\e[#{color}m#{text}\e[0m"
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def valid_color_code?(color_code)
|
19
|
+
color_code.is_a?(Integer) && color_code.between?(0, 255)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Strategy
|
7
|
+
class Rgb < Base
|
8
|
+
def colorize(text, **kwargs)
|
9
|
+
r, g, b = kwargs.values_at(:r, :g, :b)
|
10
|
+
|
11
|
+
unless valid_rgb?(r, g, b)
|
12
|
+
raise ArgumentError, "RGB values must be integers between 0 and 255"
|
13
|
+
end
|
14
|
+
|
15
|
+
"\e[38;2;#{r};#{g};#{b}m#{text}\e[0m"
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def valid_rgb?(r, g, b)
|
21
|
+
[r, g, b].all? { |value| value.is_a?(Integer) && value.between?(0, 255) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Strategy
|
7
|
+
class Theme < Base
|
8
|
+
def initialize(palette)
|
9
|
+
super()
|
10
|
+
@palette = palette
|
11
|
+
end
|
12
|
+
|
13
|
+
def colorize(text, color: :default)
|
14
|
+
unless @palette.colors.key?(color)
|
15
|
+
raise ArgumentError, "Invalid color key"
|
16
|
+
end
|
17
|
+
|
18
|
+
color_code = @palette.colors[color]
|
19
|
+
|
20
|
+
unless valid_color_code?(color_code)
|
21
|
+
raise ArgumentError, "Invalid color code"
|
22
|
+
end
|
23
|
+
|
24
|
+
"\e[#{color_code}m#{text}\e[0m"
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def valid_color_code?(color_code)
|
30
|
+
color_code.is_a?(Integer) && color_code.between?(0, 255)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Strategy
|
7
|
+
require_relative "strategy/base"
|
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
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -17,8 +17,32 @@ module DevSuite
|
|
17
17
|
},
|
18
18
|
}.freeze
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
attr_reader :settings
|
21
|
+
|
22
|
+
def initialize(settings = {})
|
23
|
+
@settings = deep_merge(DEFAULTS, settings)
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
#
|
28
|
+
# Provide global access to a single instance of Config
|
29
|
+
#
|
30
|
+
def configuration
|
31
|
+
@configuration ||= new
|
32
|
+
end
|
33
|
+
|
34
|
+
# Allow block-based configuration
|
35
|
+
def configure
|
36
|
+
yield(configuration)
|
37
|
+
rescue StandardError => e
|
38
|
+
handle_configuration_error(e)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def handle_configuration_error(error)
|
44
|
+
puts "Configuration error: #{error.message}"
|
45
|
+
end
|
22
46
|
end
|
23
47
|
|
24
48
|
def color_for(key)
|
@@ -1,10 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "base"
|
4
|
-
require_relative "../formatter/text_aligner"
|
5
|
-
require_relative "../formatter/column_width_calculator"
|
6
|
-
require_relative "../formatter/colorizer"
|
7
|
-
|
8
3
|
module DevSuite
|
9
4
|
module Utils
|
10
5
|
module Table
|
@@ -35,7 +30,7 @@ module DevSuite
|
|
35
30
|
# Colorizes the given string with the specified color
|
36
31
|
#
|
37
32
|
def colorize(str, color)
|
38
|
-
|
33
|
+
Utils::Color.colorize(str, color: color)
|
39
34
|
end
|
40
35
|
|
41
36
|
#
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Table
|
6
|
+
require_relative "table/table"
|
7
|
+
require_relative "table/column"
|
8
|
+
require_relative "table/row"
|
9
|
+
require_relative "table/config"
|
10
|
+
require_relative "table/formatter"
|
11
|
+
require_relative "table/renderer"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/dev_suite/utils.rb
CHANGED
data/lib/dev_suite/version.rb
CHANGED
data/lib/dev_suite.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev_suite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Huy Nguyen
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- dev_suite.gemspec
|
63
63
|
- lib/dev_suite.rb
|
64
64
|
- lib/dev_suite/directory_tree.rb
|
65
|
+
- lib/dev_suite/directory_tree/config.rb
|
65
66
|
- lib/dev_suite/directory_tree/node.rb
|
66
67
|
- lib/dev_suite/directory_tree/node/base.rb
|
67
68
|
- lib/dev_suite/directory_tree/node/directory.rb
|
@@ -83,17 +84,27 @@ files:
|
|
83
84
|
- lib/dev_suite/performance/reportor/base.rb
|
84
85
|
- lib/dev_suite/performance/reportor/simple.rb
|
85
86
|
- lib/dev_suite/utils.rb
|
87
|
+
- lib/dev_suite/utils/color.rb
|
88
|
+
- lib/dev_suite/utils/color/colorizer.rb
|
89
|
+
- lib/dev_suite/utils/color/config.rb
|
90
|
+
- lib/dev_suite/utils/color/palette.rb
|
91
|
+
- lib/dev_suite/utils/color/palette/base.rb
|
92
|
+
- lib/dev_suite/utils/color/palette/default.rb
|
93
|
+
- lib/dev_suite/utils/color/strategy.rb
|
94
|
+
- lib/dev_suite/utils/color/strategy/base.rb
|
95
|
+
- lib/dev_suite/utils/color/strategy/basic.rb
|
96
|
+
- lib/dev_suite/utils/color/strategy/rgb.rb
|
97
|
+
- lib/dev_suite/utils/color/strategy/theme.rb
|
98
|
+
- lib/dev_suite/utils/table.rb
|
86
99
|
- lib/dev_suite/utils/table/column.rb
|
87
|
-
- lib/dev_suite/utils/table/column/column.rb
|
88
100
|
- lib/dev_suite/utils/table/config.rb
|
89
|
-
- lib/dev_suite/utils/table/formatter
|
101
|
+
- lib/dev_suite/utils/table/formatter.rb
|
90
102
|
- lib/dev_suite/utils/table/formatter/column_width_calculator.rb
|
91
103
|
- lib/dev_suite/utils/table/formatter/text_aligner.rb
|
92
104
|
- lib/dev_suite/utils/table/renderer.rb
|
93
105
|
- lib/dev_suite/utils/table/renderer/base.rb
|
94
106
|
- lib/dev_suite/utils/table/renderer/simple.rb
|
95
107
|
- lib/dev_suite/utils/table/row.rb
|
96
|
-
- lib/dev_suite/utils/table/row/row.rb
|
97
108
|
- lib/dev_suite/utils/table/table.rb
|
98
109
|
- lib/dev_suite/version.rb
|
99
110
|
homepage: https://patrick204nqh.github.io
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module DevSuite
|
4
|
-
module Utils
|
5
|
-
module Table
|
6
|
-
module Formatter
|
7
|
-
class Colorizer
|
8
|
-
COLORS = {
|
9
|
-
red: 31,
|
10
|
-
green: 32,
|
11
|
-
yellow: 33,
|
12
|
-
blue: 34,
|
13
|
-
magenta: 35,
|
14
|
-
cyan: 36,
|
15
|
-
white: 37,
|
16
|
-
default: 39,
|
17
|
-
}.freeze
|
18
|
-
|
19
|
-
class << self
|
20
|
-
def code_for(color)
|
21
|
-
COLORS[color] || COLORS[:default]
|
22
|
-
end
|
23
|
-
|
24
|
-
def colorize(text, color = :default)
|
25
|
-
color_code = code_for(color)
|
26
|
-
"\e[#{color_code}m#{text}\e[0m"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|