langda 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b45008f13ae56ee2ae505fdf1fc551ad57bcbbf276187ee0c18514a7df713b23
4
+ data.tar.gz: ea8d92f235f9ade134def26368a35b1bf559f161162b36dd583b5470e59e3837
5
+ SHA512:
6
+ metadata.gz: a9b7e62d8337a902777f55b181a94032169f9fc82b16d1e594cc78d31f5403fb4233bf67fd4a9aa1a15ac98be3d22c506546dafc61f72ba840517fedf85ebf4e
7
+ data.tar.gz: 4af4462b9dc36fb19d83f88185eb9e7379fc6b364ce65b1eaf200894b1bf5b51e5da54810100a0fc51f3b218391d2fe66223692a3f4ebab6e798f02824a3bd12
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.4.5
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in langda.gemspec
6
+ gemspec
7
+
8
+ gem "irb"
9
+ gem "rake", "~> 13.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,231 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ langda (0.1.0)
5
+ debug
6
+ logger
7
+ rails
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ action_text-trix (2.1.15)
13
+ railties
14
+ actioncable (8.1.1)
15
+ actionpack (= 8.1.1)
16
+ activesupport (= 8.1.1)
17
+ nio4r (~> 2.0)
18
+ websocket-driver (>= 0.6.1)
19
+ zeitwerk (~> 2.6)
20
+ actionmailbox (8.1.1)
21
+ actionpack (= 8.1.1)
22
+ activejob (= 8.1.1)
23
+ activerecord (= 8.1.1)
24
+ activestorage (= 8.1.1)
25
+ activesupport (= 8.1.1)
26
+ mail (>= 2.8.0)
27
+ actionmailer (8.1.1)
28
+ actionpack (= 8.1.1)
29
+ actionview (= 8.1.1)
30
+ activejob (= 8.1.1)
31
+ activesupport (= 8.1.1)
32
+ mail (>= 2.8.0)
33
+ rails-dom-testing (~> 2.2)
34
+ actionpack (8.1.1)
35
+ actionview (= 8.1.1)
36
+ activesupport (= 8.1.1)
37
+ nokogiri (>= 1.8.5)
38
+ rack (>= 2.2.4)
39
+ rack-session (>= 1.0.1)
40
+ rack-test (>= 0.6.3)
41
+ rails-dom-testing (~> 2.2)
42
+ rails-html-sanitizer (~> 1.6)
43
+ useragent (~> 0.16)
44
+ actiontext (8.1.1)
45
+ action_text-trix (~> 2.1.15)
46
+ actionpack (= 8.1.1)
47
+ activerecord (= 8.1.1)
48
+ activestorage (= 8.1.1)
49
+ activesupport (= 8.1.1)
50
+ globalid (>= 0.6.0)
51
+ nokogiri (>= 1.8.5)
52
+ actionview (8.1.1)
53
+ activesupport (= 8.1.1)
54
+ builder (~> 3.1)
55
+ erubi (~> 1.11)
56
+ rails-dom-testing (~> 2.2)
57
+ rails-html-sanitizer (~> 1.6)
58
+ activejob (8.1.1)
59
+ activesupport (= 8.1.1)
60
+ globalid (>= 0.3.6)
61
+ activemodel (8.1.1)
62
+ activesupport (= 8.1.1)
63
+ activerecord (8.1.1)
64
+ activemodel (= 8.1.1)
65
+ activesupport (= 8.1.1)
66
+ timeout (>= 0.4.0)
67
+ activestorage (8.1.1)
68
+ actionpack (= 8.1.1)
69
+ activejob (= 8.1.1)
70
+ activerecord (= 8.1.1)
71
+ activesupport (= 8.1.1)
72
+ marcel (~> 1.0)
73
+ activesupport (8.1.1)
74
+ base64
75
+ bigdecimal
76
+ concurrent-ruby (~> 1.0, >= 1.3.1)
77
+ connection_pool (>= 2.2.5)
78
+ drb
79
+ i18n (>= 1.6, < 2)
80
+ json
81
+ logger (>= 1.4.2)
82
+ minitest (>= 5.1)
83
+ securerandom (>= 0.3)
84
+ tzinfo (~> 2.0, >= 2.0.5)
85
+ uri (>= 0.13.1)
86
+ base64 (0.3.0)
87
+ bigdecimal (3.3.1)
88
+ builder (3.3.0)
89
+ concurrent-ruby (1.3.5)
90
+ connection_pool (3.0.2)
91
+ crass (1.0.6)
92
+ date (3.5.1)
93
+ debug (1.11.0)
94
+ irb (~> 1.10)
95
+ reline (>= 0.3.8)
96
+ drb (2.2.3)
97
+ erb (6.0.0)
98
+ erubi (1.13.1)
99
+ globalid (1.3.0)
100
+ activesupport (>= 6.1)
101
+ i18n (1.14.7)
102
+ concurrent-ruby (~> 1.0)
103
+ io-console (0.8.1)
104
+ irb (1.15.3)
105
+ pp (>= 0.6.0)
106
+ rdoc (>= 4.0.0)
107
+ reline (>= 0.4.2)
108
+ json (2.17.1)
109
+ logger (1.7.0)
110
+ loofah (2.24.1)
111
+ crass (~> 1.0.2)
112
+ nokogiri (>= 1.12.0)
113
+ mail (2.9.0)
114
+ logger
115
+ mini_mime (>= 0.1.1)
116
+ net-imap
117
+ net-pop
118
+ net-smtp
119
+ marcel (1.1.0)
120
+ mini_mime (1.1.5)
121
+ minitest (5.26.2)
122
+ net-imap (0.5.12)
123
+ date
124
+ net-protocol
125
+ net-pop (0.1.2)
126
+ net-protocol
127
+ net-protocol (0.2.2)
128
+ timeout
129
+ net-smtp (0.5.1)
130
+ net-protocol
131
+ nio4r (2.7.5)
132
+ nokogiri (1.18.10-aarch64-linux-gnu)
133
+ racc (~> 1.4)
134
+ nokogiri (1.18.10-aarch64-linux-musl)
135
+ racc (~> 1.4)
136
+ nokogiri (1.18.10-arm-linux-gnu)
137
+ racc (~> 1.4)
138
+ nokogiri (1.18.10-arm-linux-musl)
139
+ racc (~> 1.4)
140
+ nokogiri (1.18.10-arm64-darwin)
141
+ racc (~> 1.4)
142
+ nokogiri (1.18.10-x86_64-darwin)
143
+ racc (~> 1.4)
144
+ nokogiri (1.18.10-x86_64-linux-gnu)
145
+ racc (~> 1.4)
146
+ nokogiri (1.18.10-x86_64-linux-musl)
147
+ racc (~> 1.4)
148
+ pp (0.6.3)
149
+ prettyprint
150
+ prettyprint (0.2.0)
151
+ psych (5.3.0)
152
+ date
153
+ stringio
154
+ racc (1.8.1)
155
+ rack (3.2.4)
156
+ rack-session (2.1.1)
157
+ base64 (>= 0.1.0)
158
+ rack (>= 3.0.0)
159
+ rack-test (2.2.0)
160
+ rack (>= 1.3)
161
+ rackup (2.3.1)
162
+ rack (>= 3)
163
+ rails (8.1.1)
164
+ actioncable (= 8.1.1)
165
+ actionmailbox (= 8.1.1)
166
+ actionmailer (= 8.1.1)
167
+ actionpack (= 8.1.1)
168
+ actiontext (= 8.1.1)
169
+ actionview (= 8.1.1)
170
+ activejob (= 8.1.1)
171
+ activemodel (= 8.1.1)
172
+ activerecord (= 8.1.1)
173
+ activestorage (= 8.1.1)
174
+ activesupport (= 8.1.1)
175
+ bundler (>= 1.15.0)
176
+ railties (= 8.1.1)
177
+ rails-dom-testing (2.3.0)
178
+ activesupport (>= 5.0.0)
179
+ minitest
180
+ nokogiri (>= 1.6)
181
+ rails-html-sanitizer (1.6.2)
182
+ loofah (~> 2.21)
183
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
184
+ railties (8.1.1)
185
+ actionpack (= 8.1.1)
186
+ activesupport (= 8.1.1)
187
+ irb (~> 1.13)
188
+ rackup (>= 1.0.0)
189
+ rake (>= 12.2)
190
+ thor (~> 1.0, >= 1.2.2)
191
+ tsort (>= 0.2)
192
+ zeitwerk (~> 2.6)
193
+ rake (13.3.1)
194
+ rdoc (6.17.0)
195
+ erb
196
+ psych (>= 4.0.0)
197
+ tsort
198
+ reline (0.6.3)
199
+ io-console (~> 0.5)
200
+ securerandom (0.4.1)
201
+ stringio (3.1.9)
202
+ thor (1.4.0)
203
+ timeout (0.5.0)
204
+ tsort (0.2.0)
205
+ tzinfo (2.0.6)
206
+ concurrent-ruby (~> 1.0)
207
+ uri (1.1.1)
208
+ useragent (0.16.11)
209
+ websocket-driver (0.8.0)
210
+ base64
211
+ websocket-extensions (>= 0.1.0)
212
+ websocket-extensions (0.1.5)
213
+ zeitwerk (2.7.3)
214
+
215
+ PLATFORMS
216
+ aarch64-linux-gnu
217
+ aarch64-linux-musl
218
+ arm-linux-gnu
219
+ arm-linux-musl
220
+ arm64-darwin
221
+ x86_64-darwin
222
+ x86_64-linux-gnu
223
+ x86_64-linux-musl
224
+
225
+ DEPENDENCIES
226
+ irb
227
+ langda!
228
+ rake (~> 13.0)
229
+
230
+ BUNDLED WITH
231
+ 2.7.1
data/LICENCE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 mrmalvi
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,33 @@
1
+ # Langda
2
+
3
+ **Langda** is a lightweight Ruby performance helper that automatically detects loops,
4
+ counts their iterations, measures execution time, and logs slow loops — all without
5
+ changing your application code.
6
+
7
+ It is designed for Rails and Ruby developers who want instant visibility into slow
8
+ loops such as `each`, `map`, `select`, `reject`, etc.
9
+
10
+ ---
11
+
12
+ ## ✨ Features
13
+
14
+ - 🟢 Auto-detects common Ruby loop methods
15
+ - 🔢 Counts loop iterations
16
+ - ⏱ Measures execution time using high-precision monotonic clock
17
+ - ⚠ Logs loops that cross the configurable slow threshold
18
+ - 🛡 Safe fallback — **never crashes your app**
19
+ - 🚀 Works in Rails, plain Ruby, Sidekiq, and background jobs
20
+ - 🔌 Zero configuration — install and use instantly
21
+
22
+ ---
23
+ ---
24
+ ## ✨ Examples
25
+ - [Langda] Array#each → 42 iterations → 12.37 ms at app/models/user.rb:25
26
+ - [Langda] Hash#map → 8 iterations → 6.19 ms at app/services/report_builder.rb:12
27
+ ---
28
+ ## 📦 Installation
29
+
30
+ Add this line to your **Gemfile**:
31
+
32
+ ```ruby
33
+ gem "langda"
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "langda"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ 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
@@ -0,0 +1,20 @@
1
+ module Langda
2
+ module Log
3
+ APP_ROOT = Rails.root.to_s
4
+ def self.warn(msg)
5
+
6
+ loc = caller.find { |c| c.start_with?(APP_ROOT) }
7
+
8
+ loc = caller.find do |c|
9
+ c.include?("#{APP_ROOT}/app/")
10
+ end
11
+ return unless loc
12
+ file = loc.split(":")
13
+ if defined?(Rails) && Rails.logger
14
+ super("[Langda] #{msg} at #{file}")
15
+ else
16
+ puts ("[Langda] #{msg} at #{file}")
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,105 @@
1
+ module Langda
2
+ module LoopPatch
3
+
4
+ #########################################################
5
+ # UNIVERSAL LOOP WRAPPER (SAFE)
6
+ #########################################################
7
+ def _safe_loop(kind, args, block)
8
+ # No block → run original method
9
+ return yield unless Langda.enabled? && block
10
+
11
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
12
+ count = 0
13
+
14
+ begin
15
+ inner = proc do |*yield_args|
16
+ count += 1
17
+ block.call(*yield_args)
18
+ end
19
+
20
+ result = yield(inner)
21
+
22
+ _langda_log(kind, count, start)
23
+ result
24
+
25
+ rescue => e
26
+ Langda::Log.warn("Langda fallback for #{kind}: #{e.class} #{e.message}")
27
+ yield(block) # fallback super
28
+ end
29
+ end
30
+
31
+
32
+ #########################################################
33
+ # ARRAY / ENUMERABLE LOOP METHODS
34
+ #########################################################
35
+
36
+ def each(*args, &block)
37
+ _safe_loop(:each, args, block) { |inner| super(*args, &inner) }
38
+ end
39
+
40
+ def map(*args, &block)
41
+ _safe_loop(:map, args, block) { |inner| super(*args, &inner) }
42
+ end
43
+
44
+ def select(*args, &block)
45
+ _safe_loop(:select, args, block) { |inner| super(*args, &inner) }
46
+ end
47
+
48
+ def reject(*args, &block)
49
+ _safe_loop(:reject, args, block) { |inner| super(*args, &inner) }
50
+ end
51
+
52
+ def each_with_index(*args, &block)
53
+ _safe_loop(:each_with_index, args, block) { |inner| super(*args, &inner) }
54
+ end
55
+
56
+ def each_with_object(obj, &block)
57
+ _safe_loop(:each_with_object, [obj], block) { |inner| super(obj, &inner) }
58
+ end
59
+
60
+
61
+ #########################################################
62
+ # INTEGER LOOP METHODS
63
+ #########################################################
64
+
65
+ def times(&block)
66
+ _safe_loop(:times, [], block) { |inner| super(&inner) }
67
+ end
68
+
69
+ def upto(limit, &block)
70
+ _safe_loop(:upto, [limit], block) { |inner| super(limit, &inner) }
71
+ end
72
+
73
+ def downto(limit, &block)
74
+ _safe_loop(:downto, [limit], block) { |inner| super(limit, &inner) }
75
+ end
76
+
77
+ def step(limit = nil, step = nil, &block)
78
+ _safe_loop(:step, [limit, step], block) do |inner|
79
+ super(limit, step, &inner)
80
+ end
81
+ end
82
+
83
+
84
+ #########################################################
85
+ # LOGGER
86
+ #########################################################
87
+ def _langda_log(kind, count, start)
88
+ ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000
89
+ return unless ms > Langda.threshold_ms
90
+
91
+ Langda::Log.warn("#{kind} → #{count} iterations → #{ms.round(3)} ms")
92
+ end
93
+
94
+ end
95
+ end
96
+
97
+
98
+ #########################################################
99
+ # APPLY PATCHES
100
+ #########################################################
101
+
102
+ Array.prepend(Langda::LoopPatch)
103
+ Hash.prepend(Langda::LoopPatch)
104
+ Enumerable.prepend(Langda::LoopPatch)
105
+ Integer.prepend(Langda::LoopPatch)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Langda
4
+ VERSION = "0.1.0"
5
+ end
data/lib/langda.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "langda/logger"
2
+
3
+ module Langda
4
+ class << self
5
+ attr_accessor :enabled, :threshold_ms
6
+ end
7
+
8
+ self.enabled = true
9
+ self.threshold_ms = 2.0
10
+
11
+ def self.enabled?
12
+ !!enabled
13
+ end
14
+ end
15
+ require "langda/patches"
data/sig/langda.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Langda
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: langda
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mrmalvi
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ description: |-
27
+ Langda monitors Ruby loop operations (each, map, select, etc.), counts their iterations,
28
+ measures execution time, and logs slow loops. It helps developers quickly identify
29
+ performance bottlenecks in real application code with zero configuration and no breaking changes.
30
+ email:
31
+ - malviyak00@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".ruby-version"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENCE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - lib/langda.rb
45
+ - lib/langda/logger.rb
46
+ - lib/langda/patches.rb
47
+ - lib/langda/version.rb
48
+ - sig/langda.rbs
49
+ homepage: https://github.com/mrmalvi/langda
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ allowed_push_host: https://rubygems.org
54
+ homepage_uri: https://github.com/mrmalvi/langda
55
+ source_code_uri: https://github.com/mrmalvi/langda
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '2.5'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.6.9
71
+ specification_version: 4
72
+ summary: Automatically detects Ruby loops, counts iterations, and logs slow loop performance.
73
+ test_files: []