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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/query_counter.rb +23 -0
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dde4c69db1dfdb26db42ab2dd2d549120db69565
4
- data.tar.gz: 46d0d9e9ba5593004d2fb9fe034a8b26a417fc28
3
+ metadata.gz: 338d09ed6a3c3c384287fe2fe8434b85880e1bf4
4
+ data.tar.gz: 5c7159ebd514a79282d77b5eeba7bf4db53bd07c
5
5
  SHA512:
6
- metadata.gz: 25870e36da7884d02c2b5bcf63011bf88233cf39979684a3684431019b302898e2b6fe90af6fbf9ff13cfc4e14ebc71bce10bcb6046a006e9fe45a6fdc00eb7e
7
- data.tar.gz: 476ad9e7953ce4e9012988e026b4fc2b3dbc608cf494a4e7be12d8aa923da95d012806a04814c97f268585848a97ed9e3866f8c30289d6c17cedd989992074da
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.0
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-18 00:00:00.000000000 Z
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