complexity_checker_ruby 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +34 -0
- data/lib/complexity_checker_ruby/alerts.rb +7 -0
- data/lib/complexity_checker_ruby/version.rb +5 -0
- data/lib/complexity_checker_ruby.rb +27 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1f696cd3a530501a7493770d9f7941691ef6efdd6635bf3cab4a0eeb066a7a3d
|
4
|
+
data.tar.gz: b1a29cbb26150467d1dd0d1e3d2419280d1030bff46619ef2e4d3ee1cb390128
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 24456b23acde0d58b0c2360024607cdf431abf7fd7288373ddd977111cc62a1c76c3b14b655a224ace457f8d2187f81aab5b4074a5cc0d09df202302619d9cb4
|
7
|
+
data.tar.gz: b58dc3d3d5507cacab873621af16188f979791a6371d4429fd84614fe06c1b34afc36d4a591bb259cec8d9d9b6b47b1ec6ef80abc385d2b270ccb987470f301d
|
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,34 @@
|
|
1
|
+
# ComplexityCheckerRuby
|
2
|
+
|
3
|
+
`ComplexityCheckerRuby` is a Ruby gem that helps analyze the time complexity of your Ruby code by profiling execution time.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
gem install complexity_checker_ruby
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
```bash
|
13
|
+
require 'complexity_checker_ruby'
|
14
|
+
|
15
|
+
# Set custom threshold (optional)
|
16
|
+
ComplexityCheckerRuby.threshold = 0.5 # seconds
|
17
|
+
|
18
|
+
class Example
|
19
|
+
extend ComplexityCheckerRuby
|
20
|
+
|
21
|
+
def self.example_method(arr)
|
22
|
+
arr.each do |i|
|
23
|
+
# Simulating some work
|
24
|
+
sleep(0.6) # Example to trigger alert
|
25
|
+
puts i
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Monitor method for execution time
|
30
|
+
ComplexityCheckerRuby.monitor_method(self, :example_method)
|
31
|
+
end
|
32
|
+
|
33
|
+
Example.example_method((1..10).to_a)
|
34
|
+
```
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# lib/complexity_checker_ruby.rb
|
2
|
+
require 'benchmark'
|
3
|
+
require 'complexity_checker_ruby/alerts'
|
4
|
+
|
5
|
+
module ComplexityCheckerRuby
|
6
|
+
@threshold = 0.1 # Default threshold in seconds
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :threshold
|
10
|
+
|
11
|
+
def monitor_method(obj, method_name)
|
12
|
+
original_method = obj.method(method_name)
|
13
|
+
|
14
|
+
obj.define_singleton_method(method_name) do |*args, &block|
|
15
|
+
start_time = Time.now
|
16
|
+
result = original_method.call(*args, &block)
|
17
|
+
duration = Time.now - start_time
|
18
|
+
|
19
|
+
if duration > @threshold
|
20
|
+
Alerts.notify(method_name, duration)
|
21
|
+
end
|
22
|
+
|
23
|
+
result
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: complexity_checker_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Umair Dar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-10-31 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'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: This gem profiles Ruby code to estimate its time complexity.
|
28
|
+
email:
|
29
|
+
- umairdar.work@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE.txt
|
35
|
+
- README.md
|
36
|
+
- lib/complexity_checker_ruby.rb
|
37
|
+
- lib/complexity_checker_ruby/alerts.rb
|
38
|
+
- lib/complexity_checker_ruby/version.rb
|
39
|
+
homepage: https://github.com/umairdar12/complexity_checker_ruby
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.4.10
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: A gem to analyze time complexity of Ruby code.
|
62
|
+
test_files: []
|