query_counter 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/query_counter.rb +23 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 338d09ed6a3c3c384287fe2fe8434b85880e1bf4
|
4
|
+
data.tar.gz: 5c7159ebd514a79282d77b5eeba7bf4db53bd07c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b1dbdf4ba527c6bbf7d57dc2ad9a69f73ffb1f203080083f2348b0a5e60f9185ea33b1d9ca379a6df2241d69cea49b83cd8ccac37d0e4d5edf34e485a679592
|
7
|
+
data.tar.gz: 1e2457bb83ccd30ad253bcd86a9c0dfcb9adf1da430517582c9cad7da0987bdec07822e01b8b4b3e3ca5002b33f8ed419181937d781dcc77ec52d6d3222c7743
|
data/lib/query_counter.rb
CHANGED
@@ -58,4 +58,27 @@ module QueryCounter
|
|
58
58
|
::QueryCounter.record_event(resource, ActiveSupport::Notifications::Event.new(*args))
|
59
59
|
end
|
60
60
|
end
|
61
|
+
|
62
|
+
def self.auto_instrument!(resource, kls, method_name)
|
63
|
+
method_name = method_name.to_s
|
64
|
+
if method_name =~ /^(.*?)([!\?])$/
|
65
|
+
method_name = $1
|
66
|
+
punctuation = $2
|
67
|
+
else
|
68
|
+
punctuation = ''
|
69
|
+
end
|
70
|
+
|
71
|
+
original_method_name_with_alias = "#{method_name}_without_instrumentation#{punctuation}"
|
72
|
+
new_method_name = "#{method_name}_with_instrumentation#{punctuation}"
|
73
|
+
kls.class_eval <<STR
|
74
|
+
def #{new_method_name}(*args)
|
75
|
+
started_at = Time.now
|
76
|
+
result = #{original_method_name_with_alias}(*args)
|
77
|
+
::QueryCounter.record(#{resource.inspect}, (Time.now - started_at) / 1_000.0)
|
78
|
+
result
|
79
|
+
end
|
80
|
+
STR
|
81
|
+
kls.send(:alias_method, original_method_name_with_alias, method_name + punctuation)
|
82
|
+
kls.send(:alias_method, method_name + punctuation, new_method_name)
|
83
|
+
end
|
61
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query_counter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doug Youch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Used for monitoring number of external calls
|
14
14
|
email: dougyouch@gmail.com
|