dev_suite 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 368efd66d4aa6229bbb00ceac32f7c505f35543e2ba5834dc9dd3509f27e4c55
4
+ data.tar.gz: c2af717b31f413ea03ebdcbdc0b47f70b895c29d66e82f12e685d1b1f7e75657
5
+ SHA512:
6
+ metadata.gz: eb257b7bc6c8436de804fe32510380319d77d30656259739767fa2739885867df47e0c1a5d6cc1b6111214e272863b1ff0c235c053ff9b71056c622bc8324032
7
+ data.tar.gz: 4b568c9210885a684b4edfad0d07ddd4a7daab5f4dbcdb959fc4e30870b190e2d9f867fc4dc503b6264f59c4dd877bb1af1dd884f5776a7cbfeec1ef7bdd5076
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
1
+ inherit_gem:
2
+ rubocop-shopify: rubocop.yml
3
+
4
+ AllCops:
5
+ NewCops: enable
6
+ TargetRubyVersion: 2.7
7
+ Exclude:
8
+ - 'bin/**/*'
9
+ - 'db/schema.rb'
10
+ - 'node_modules/**/*'
11
+ - 'vendor/**/*'
12
+ - 'spec/**/*'
13
+ - 'test/**/*'
14
+ - 'lib/dev_suite/version.rb'
15
+
16
+ Metrics/LineLength:
17
+ Max: 120
18
+
19
+ Style/FrozenStringLiteralComment:
20
+ Enabled: true
21
+
22
+ Layout/IndentationWidth:
23
+ Width: 2
24
+
25
+ Metrics/BlockLength:
26
+ Exclude:
27
+ - 'lib/tasks/**/*.rake'
28
+ - 'spec/**/*'
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.3.0
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.5
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at TODO: Write your email address. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in dev_suite.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "rspec", "~> 3.9"
10
+ gem "rubocop", "~> 1.65"
11
+ gem "rubocop-shopify", "~> 2.15"
12
+ gem "pry", "~> 0.14"
data/Gemfile.lock ADDED
@@ -0,0 +1,98 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dev_suite (0.1.0)
5
+ benchmark (~> 0.1)
6
+ get_process_mem (~> 0.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ benchmark (0.3.0)
13
+ coderay (1.1.3)
14
+ diff-lcs (1.5.1)
15
+ ffi (1.17.0)
16
+ ffi (1.17.0-aarch64-linux-gnu)
17
+ ffi (1.17.0-aarch64-linux-musl)
18
+ ffi (1.17.0-arm-linux-gnu)
19
+ ffi (1.17.0-arm-linux-musl)
20
+ ffi (1.17.0-arm64-darwin)
21
+ ffi (1.17.0-x86-linux-gnu)
22
+ ffi (1.17.0-x86-linux-musl)
23
+ ffi (1.17.0-x86_64-darwin)
24
+ ffi (1.17.0-x86_64-linux-gnu)
25
+ ffi (1.17.0-x86_64-linux-musl)
26
+ get_process_mem (0.2.7)
27
+ ffi (~> 1.0)
28
+ json (2.7.2)
29
+ language_server-protocol (3.17.0.3)
30
+ method_source (1.1.0)
31
+ parallel (1.25.1)
32
+ parser (3.3.4.1)
33
+ ast (~> 2.4.1)
34
+ racc
35
+ pry (0.14.2)
36
+ coderay (~> 1.1)
37
+ method_source (~> 1.0)
38
+ racc (1.8.1)
39
+ rainbow (3.1.1)
40
+ rake (13.2.1)
41
+ regexp_parser (2.9.2)
42
+ rexml (3.3.4)
43
+ strscan
44
+ rspec (3.13.0)
45
+ rspec-core (~> 3.13.0)
46
+ rspec-expectations (~> 3.13.0)
47
+ rspec-mocks (~> 3.13.0)
48
+ rspec-core (3.13.0)
49
+ rspec-support (~> 3.13.0)
50
+ rspec-expectations (3.13.1)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.13.0)
53
+ rspec-mocks (3.13.1)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.13.0)
56
+ rspec-support (3.13.1)
57
+ rubocop (1.65.1)
58
+ json (~> 2.3)
59
+ language_server-protocol (>= 3.17.0)
60
+ parallel (~> 1.10)
61
+ parser (>= 3.3.0.2)
62
+ rainbow (>= 2.2.2, < 4.0)
63
+ regexp_parser (>= 2.4, < 3.0)
64
+ rexml (>= 3.2.5, < 4.0)
65
+ rubocop-ast (>= 1.31.1, < 2.0)
66
+ ruby-progressbar (~> 1.7)
67
+ unicode-display_width (>= 2.4.0, < 3.0)
68
+ rubocop-ast (1.32.0)
69
+ parser (>= 3.3.1.0)
70
+ rubocop-shopify (2.15.1)
71
+ rubocop (~> 1.51)
72
+ ruby-progressbar (1.13.0)
73
+ strscan (3.1.0)
74
+ unicode-display_width (2.5.0)
75
+
76
+ PLATFORMS
77
+ aarch64-linux-gnu
78
+ aarch64-linux-musl
79
+ arm-linux-gnu
80
+ arm-linux-musl
81
+ arm64-darwin
82
+ ruby
83
+ x86-linux-gnu
84
+ x86-linux-musl
85
+ x86_64-darwin
86
+ x86_64-linux-gnu
87
+ x86_64-linux-musl
88
+
89
+ DEPENDENCIES
90
+ dev_suite!
91
+ pry (~> 0.14)
92
+ rake (~> 13.0)
93
+ rspec (~> 3.9)
94
+ rubocop (~> 1.65)
95
+ rubocop-shopify (~> 2.15)
96
+
97
+ BUNDLED WITH
98
+ 2.5.17
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # DevSuite
2
+
3
+ Welcome to DevSuite! This gem provides a suite of utilities for developers to enhance their productivity.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dev_suite'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```sh
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```sh
22
+ $ gem install dev_suite
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ To use DevSuite, require it in your Ruby code:
28
+
29
+ ```ruby
30
+ require 'dev_suite'
31
+ ```
32
+
33
+ ### Example Usage
34
+
35
+ ```ruby
36
+ # Example of using a utility from DevSuite
37
+ DevSuite::SomeUtility.do_something
38
+ ```
39
+
40
+ ## Features
41
+
42
+ <details>
43
+ <summary><strong>Performance Analysis with DevSuite::Performance::Analyzer</strong></summary>
44
+
45
+ Analyze the performance of your code blocks with detailed benchmark and memory usage reports.
46
+
47
+ **Usage:**
48
+ ```ruby
49
+ require 'dev_suite'
50
+
51
+ DevSuite::Performance::Analyzer.analyze(description: "My Code Block") do
52
+ # Your code here
53
+ end
54
+ ```
55
+ </detail>
56
+
57
+ ## Development
58
+
59
+ After checking out the repo, run `bin/setup`for an interactive prompt that will allow you to experiment.
60
+
61
+ To install this gem onto your local machine, run:
62
+
63
+ ```sh
64
+ $ bundle exec rake install
65
+ ```
66
+
67
+ To release a new version, update the version number in `version.rb`, and then run:
68
+
69
+ ```sh
70
+ $ bundle exec rake release
71
+ ```
72
+
73
+ This will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
74
+
75
+
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/patrick204nqh/dev_suite. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/patrick204nqh/dev_suite/blob/master/CODE_OF_CONDUCT.md).
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
84
+
85
+ ## Code of Conduct
86
+
87
+ Everyone interacting in the DevSuite project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/patrick204nqh/dev_suite/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dev_suite"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/dev_suite.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/dev_suite/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "dev_suite"
7
+ spec.version = DevSuite::VERSION
8
+ spec.authors = ["Huy Nguyen"]
9
+ spec.email = ["patrick204nqh@gmail.com"]
10
+
11
+ spec.summary = "A suite of development tools."
12
+ spec.description = "Provides tools for performance analysis, folder structure visualization, " \
13
+ "and custom curl command generation."
14
+ spec.homepage = "https://patrick204nqh.github.io"
15
+ spec.license = "MIT"
16
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
17
+
18
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
19
+
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/patrick204nqh/dev_suite"
22
+ spec.metadata["changelog_uri"] = "https://github.com/patrick204nqh/dev_suite/blob/main/CHANGELOG.md"
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
27
+ %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency("benchmark", "~> 0.1")
34
+ spec.add_dependency("get_process_mem", "~> 0.2")
35
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "reporting/report_generator"
4
+ require_relative "profiling/benchmark_profiler"
5
+ require_relative "profiling/memory_profiler"
6
+
7
+ module DevSuite
8
+ module Performance
9
+ class Analyzer
10
+ class << self
11
+ # Generates a performance report
12
+ # @param benchmark_result [Benchmark::Tms] The benchmark result
13
+ # @param memory_stats [Hash] The memory statistics
14
+ def analyze(description: "Block", &block)
15
+ raise ArgumentError, "No block given" unless block_given?
16
+
17
+ analyzer = new(description: description)
18
+ analyzer.analyze(&block)
19
+ end
20
+ end
21
+
22
+ def initialize(description: "Block")
23
+ @description = description
24
+ @benchmark_profiler = Profiling::BenchmarkProfiler.new
25
+ @memory_profiler = Profiling::MemoryProfiler.new
26
+ @memory_usage = Data::MemoryUsage.new
27
+ end
28
+
29
+ # Analyzes the performance of the given block
30
+ # @param block [Proc] The block to be analyzed
31
+ # @raise [ArgumentError] If no block is given
32
+ def analyze(&block)
33
+ memory_before = @memory_usage.current
34
+ benchmark_result = profile_benchmark(&block)
35
+ memory_after = @memory_usage.current
36
+
37
+ memory_stats = @memory_profiler.stats(memory_before, memory_after)
38
+
39
+ generate_report(benchmark_result, memory_stats)
40
+ end
41
+
42
+ private
43
+
44
+ # Profiles the benchmark of the given block
45
+ # @param block [Proc] The block to be benchmarked
46
+ # @return [Benchmark::Tms] The benchmark result
47
+ def profile_benchmark(&block)
48
+ @benchmark_profiler.run do
49
+ @memory_profiler.profile(&block)
50
+ end
51
+ end
52
+
53
+ # Generates a performance report
54
+ # @param benchmark_result [Benchmark::Tms] The benchmark result
55
+ # @param memory_stats [Hash] The memory statistics
56
+ def generate_report(benchmark_result, memory_stats)
57
+ report_generator = Reporting::ReportGenerator.new(
58
+ @description,
59
+ benchmark_result,
60
+ memory_stats,
61
+ )
62
+ report_generator.generate
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "get_process_mem"
4
+
5
+ module DevSuite
6
+ module Performance
7
+ module Data
8
+ class MemoryUsage
9
+ def current
10
+ GetProcessMem.new.mb
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Performance
5
+ module Profiling
6
+ class BaseProfiler
7
+ def run(&block)
8
+ raise NotImplementedError, "Subclasses must implement the run method"
9
+ end
10
+
11
+ def stats
12
+ raise NotImplementedError, "Subclasses must implement the stats method"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "benchmark"
4
+ require_relative "base_profiler"
5
+
6
+ module DevSuite
7
+ module Performance
8
+ module Profiling
9
+ class BenchmarkProfiler < BaseProfiler
10
+ def run(&block)
11
+ Benchmark.measure do
12
+ block.call
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base_profiler"
4
+ require_relative "../data/memory_usage"
5
+
6
+ module DevSuite
7
+ module Performance
8
+ module Profiling
9
+ class MemoryProfiler < BaseProfiler
10
+ attr_reader :max_memory, :min_memory, :average_memory
11
+
12
+ def initialize
13
+ super
14
+ @memory_usage = Data::MemoryUsage.new
15
+ @memory_points = []
16
+ end
17
+
18
+ def profile(&block)
19
+ yield
20
+ record_memory
21
+ end
22
+
23
+ def stats(before, after)
24
+ memory_used = after - before
25
+ @average_memory = @memory_points.sum / @memory_points.size
26
+ {
27
+ before: before,
28
+ after: after,
29
+ used: memory_used,
30
+ max: @memory_points.max,
31
+ min: @memory_points.min,
32
+ avg: @average_memory,
33
+ }
34
+ end
35
+
36
+ private
37
+
38
+ def record_memory
39
+ current_mem = @memory_usage.current
40
+ @memory_points << current_mem
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../utils/table/table"
4
+ require_relative "../../utils/table/config"
5
+ require_relative "../../utils/table/renderer/simple"
6
+
7
+ module DevSuite
8
+ module Performance
9
+ module Reporting
10
+ class ReportGenerator
11
+ def initialize(description, benchmark_result, memory_stats)
12
+ @description = description
13
+ @benchmark_result = benchmark_result
14
+ @memory_stats = memory_stats
15
+ end
16
+
17
+ # Generates the performance report
18
+ def generate
19
+ table = create_table
20
+ populate_table(table)
21
+ render_table(table)
22
+ end
23
+
24
+ private
25
+
26
+ #
27
+ # Creates a new table with the specified configuration
28
+ #
29
+ def create_table
30
+ config = Utils::Table::Config.new
31
+ Utils::Table::Table.new(config).tap do |table|
32
+ table.title = "Performance Analysis"
33
+ table.add_columns("Metric", "Value")
34
+ end
35
+ end
36
+
37
+ #
38
+ # Populates the table with benchmark and memory statistics
39
+ #
40
+ def populate_table(table)
41
+ table.add_row(["Description", @description])
42
+ table.add_row(["Total Time (s)", format("%.6f", @benchmark_result.real)])
43
+ table.add_row(["User CPU Time (s)", format("%.6f", @benchmark_result.utime)])
44
+ table.add_row(["System CPU Time (s)", format("%.6f", @benchmark_result.stime)])
45
+ table.add_row(["User + System CPU Time (s)", format("%.6f", @benchmark_result.total)])
46
+ table.add_row(["Memory Before (MB)", format("%.2f", @memory_stats[:before])])
47
+ table.add_row(["Memory After (MB)", format("%.2f", @memory_stats[:after])])
48
+ table.add_row(["Memory Used (MB)", format("%.2f", @memory_stats[:used])])
49
+ table.add_row(["Max Memory Used (MB)", format("%.2f", @memory_stats[:max])])
50
+ table.add_row(["Min Memory Used (MB)", format("%.2f", @memory_stats[:min])])
51
+ table.add_row(["Avg Memory Used (MB)", format("%.2f", @memory_stats[:avg])])
52
+ end
53
+
54
+ #
55
+ # Renders the table using the specified renderer
56
+ #
57
+ def render_table(table)
58
+ renderer = Utils::Table::Renderer::Simple.new
59
+ puts table.render(renderer: renderer)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Table
6
+ class Column
7
+ attr_reader :name
8
+
9
+ def initialize(name)
10
+ @name = name
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Table
6
+ class Config
7
+ DEFAULTS = {
8
+ colors: {
9
+ title: :cyan,
10
+ column: :yellow,
11
+ row: :default,
12
+ border: :blue,
13
+ },
14
+ alignments: {
15
+ column: :left,
16
+ row: :left,
17
+ },
18
+ }.freeze
19
+
20
+ def initialize(custom_settings = {})
21
+ @settings = deep_merge(DEFAULTS, custom_settings)
22
+ end
23
+
24
+ def color_for(key)
25
+ @settings[:colors][key] || DEFAULTS[:colors][:row]
26
+ end
27
+
28
+ def alignment_for(key)
29
+ @settings[:alignments][key] || :left
30
+ end
31
+
32
+ private
33
+
34
+ def deep_merge(original, override)
35
+ original.merge(override) do |_key, oldval, newval|
36
+ oldval.is_a?(Hash) ? deep_merge(oldval, newval) : newval
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,33 @@
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
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Table
6
+ module Formatter
7
+ class ColumnWidthCalculator
8
+ class << self
9
+ def calculate(columns, rows)
10
+ column_widths = columns.map { |column| column.name.length }
11
+ rows.each do |row|
12
+ row.data.each_with_index do |cell, index|
13
+ column_widths[index] = [column_widths[index], cell.to_s.length].max
14
+ end
15
+ end
16
+ column_widths
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Table
6
+ module Formatter
7
+ class TextAligner
8
+ class << self
9
+ def align(text, width, alignment = :left)
10
+ case alignment
11
+ when :left
12
+ text.ljust(width)
13
+ when :right
14
+ text.rjust(width)
15
+ when :center
16
+ text.center(width)
17
+ else
18
+ text
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Table
6
+ module Renderer
7
+ class Base
8
+ def initialize(config = Config.new)
9
+ @config = config
10
+ end
11
+
12
+ def render(table)
13
+ raise NotImplementedError, "Render method must be implemented in subclasses"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
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
+ module DevSuite
9
+ module Utils
10
+ module Table
11
+ module Renderer
12
+ class Simple < Base
13
+ def render(table)
14
+ column_widths = calculate_column_widths(table)
15
+
16
+ [
17
+ render_title(table, column_widths),
18
+ render_separator(column_widths),
19
+ render_header(table, column_widths),
20
+ render_separator(column_widths),
21
+ render_rows(table, column_widths),
22
+ ].compact.join("\n")
23
+ end
24
+
25
+ private
26
+
27
+ #
28
+ # Calculates the widths of the columns
29
+ #
30
+ def calculate_column_widths(table)
31
+ Formatter::ColumnWidthCalculator.calculate(table.columns, table.rows)
32
+ end
33
+
34
+ #
35
+ # Colorizes the given string with the specified color
36
+ #
37
+ def colorize(str, color)
38
+ Formatter::Colorizer.colorize(str, color)
39
+ end
40
+
41
+ #
42
+ # Aligns the given string to the specified width
43
+ #
44
+ def text_align(str, width)
45
+ Formatter::TextAligner.align(str, width)
46
+ end
47
+
48
+ def render_title(table, column_widths)
49
+ return if table.title.nil? || table.title.strip.empty?
50
+
51
+ total_width = column_widths.sum + column_widths.size * 3 - 1
52
+ title_str = "| #{table.title.center(total_width - 2)} |"
53
+ colorize(title_str, @config.color_for(:title))
54
+ end
55
+
56
+ def render_header(table, column_widths)
57
+ return if table.columns.empty?
58
+
59
+ header = table.columns.map.with_index do |column, index|
60
+ text_align(column.name, column_widths[index])
61
+ end
62
+ header_str = "| #{header.join(" | ")} |"
63
+ colorize(header_str, @config.color_for(:column))
64
+ end
65
+
66
+ def render_separator(column_widths)
67
+ separator = column_widths.map { |width| "-" * width }.join("-+-")
68
+ separator_str = "+-#{separator}-+"
69
+ colorize(separator_str, @config.color_for(:border))
70
+ end
71
+
72
+ def render_rows(table, column_widths)
73
+ cells = table.rows.map do |row|
74
+ render_row(row, column_widths)
75
+ end
76
+ cells_str = cells.join("\n")
77
+ colorize(cells_str, @config.color_for(:row))
78
+ end
79
+
80
+ def render_row(row, column_widths)
81
+ cell = row.data.map.with_index do |cell, index|
82
+ text_align(cell.to_s, column_widths[index])
83
+ end
84
+ cell_str = "| #{cell.join(" | ")} |"
85
+ colorize(cell_str, @config.color_for(:row))
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Utils
5
+ module Table
6
+ class Row
7
+ attr_reader :data
8
+
9
+ def initialize(data)
10
+ @data = data
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "column/column"
4
+ require_relative "row/row"
5
+ require_relative "renderer/simple"
6
+ require_relative "config"
7
+
8
+ module DevSuite
9
+ module Utils
10
+ module Table
11
+ class Table
12
+ attr_accessor :title
13
+ attr_reader :columns, :rows, :config
14
+
15
+ def initialize(config = Config.new)
16
+ @columns = []
17
+ @rows = []
18
+ @title = ""
19
+ @config = config
20
+ end
21
+
22
+ def add_columns(*names)
23
+ names.each { |name| add_column(name) }
24
+ end
25
+
26
+ def add_column(name)
27
+ @columns << Column.new(name)
28
+ end
29
+
30
+ def add_row(data)
31
+ @rows << Row.new(data)
32
+ end
33
+
34
+ def render(renderer: Renderer::Simple.new(config))
35
+ renderer.render(self)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module DevSuite
2
+ VERSION = "0.1.0"
3
+ end
data/lib/dev_suite.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dev_suite/version"
4
+ require "dev_suite/performance/analyzer"
5
+
6
+ module DevSuite
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dev_suite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Huy Nguyen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: benchmark
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: get_process_mem
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
41
+ description: Provides tools for performance analysis, folder structure visualization,
42
+ and custom curl command generation.
43
+ email:
44
+ - patrick204nqh@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".rubocop.yml"
52
+ - ".tool-versions"
53
+ - ".travis.yml"
54
+ - CODE_OF_CONDUCT.md
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - bin/console
61
+ - bin/setup
62
+ - dev_suite.gemspec
63
+ - lib/dev_suite.rb
64
+ - lib/dev_suite/performance/analyzer.rb
65
+ - lib/dev_suite/performance/data/memory_usage.rb
66
+ - lib/dev_suite/performance/profiling/base_profiler.rb
67
+ - lib/dev_suite/performance/profiling/benchmark_profiler.rb
68
+ - lib/dev_suite/performance/profiling/memory_profiler.rb
69
+ - lib/dev_suite/performance/reporting/report_generator.rb
70
+ - lib/dev_suite/utils/table/column/column.rb
71
+ - lib/dev_suite/utils/table/config.rb
72
+ - lib/dev_suite/utils/table/formatter/colorizer.rb
73
+ - lib/dev_suite/utils/table/formatter/column_width_calculator.rb
74
+ - lib/dev_suite/utils/table/formatter/text_aligner.rb
75
+ - lib/dev_suite/utils/table/renderer/base.rb
76
+ - lib/dev_suite/utils/table/renderer/simple.rb
77
+ - lib/dev_suite/utils/table/row/row.rb
78
+ - lib/dev_suite/utils/table/table.rb
79
+ - lib/dev_suite/version.rb
80
+ homepage: https://patrick204nqh.github.io
81
+ licenses:
82
+ - MIT
83
+ metadata:
84
+ homepage_uri: https://patrick204nqh.github.io
85
+ source_code_uri: https://github.com/patrick204nqh/dev_suite
86
+ changelog_uri: https://github.com/patrick204nqh/dev_suite/blob/main/CHANGELOG.md
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 2.3.0
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 3.5.3
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: A suite of development tools.
106
+ test_files: []