query_counter 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/query_counter.rb +12 -2
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 287f722b0315a6c58aaf972b350675f5109b00e86c74bf77066f77e1dc206946
|
4
|
+
data.tar.gz: 8611d58903ea5f9f4157ddba804d28fb72702408bbcfbaa9b004a49c80adfe07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a45341c89a30c7e65fe7d31c8a43d921cb9ae33f9b1f261cc2278cd5bd7ac74fff16bc1f3e8f66ebd99e621af2dec8bb5348514550d7b5ff1e16ab879e471c70
|
7
|
+
data.tar.gz: dd6e67759841de70a6acb4b7980da38081cb25b6afe6d8e6bf7f0a550c3d75e7555aa3157c86aaf2ab585043a30566498154e84fde42197f361b6f04fb0bd1c6
|
data/lib/query_counter.rb
CHANGED
@@ -5,6 +5,11 @@ module QueryCounter
|
|
5
5
|
autoload :RequestHelper, 'query_counter/request_helper'
|
6
6
|
autoload :Stat, 'query_counter/stat'
|
7
7
|
|
8
|
+
@@callbacks = {}
|
9
|
+
def self.callbacks
|
10
|
+
@@callbacks
|
11
|
+
end
|
12
|
+
|
8
13
|
def self.global_collector
|
9
14
|
::QueryCounter::Global.instance
|
10
15
|
end
|
@@ -60,14 +65,16 @@ module QueryCounter
|
|
60
65
|
current_collector.count(resource)
|
61
66
|
end
|
62
67
|
|
63
|
-
def self.auto_subscribe!(resource, event_name)
|
68
|
+
def self.auto_subscribe!(resource, event_name, &block)
|
64
69
|
require 'active_support/notifications'
|
65
70
|
ActiveSupport::Notifications.subscribe(event_name) do |*args|
|
66
71
|
::QueryCounter.record_event(resource, ActiveSupport::Notifications::Event.new(*args))
|
67
72
|
end
|
68
73
|
end
|
69
74
|
|
70
|
-
def self.auto_instrument!(resource, kls, method_name)
|
75
|
+
def self.auto_instrument!(resource, kls, method_name, &block)
|
76
|
+
callback_name = "#{resource}.#{method_name}"
|
77
|
+
|
71
78
|
method_name = method_name.to_s
|
72
79
|
if method_name =~ /^(.*?)([!\?])$/
|
73
80
|
method_name = $1
|
@@ -76,10 +83,13 @@ module QueryCounter
|
|
76
83
|
punctuation = ''
|
77
84
|
end
|
78
85
|
|
86
|
+
callbacks[callback_name] = block if block
|
87
|
+
|
79
88
|
original_method_name_with_alias = "#{method_name}_without_instrumentation#{punctuation}"
|
80
89
|
new_method_name = "#{method_name}_with_instrumentation#{punctuation}"
|
81
90
|
kls.class_eval <<STR
|
82
91
|
def #{new_method_name}(*args)
|
92
|
+
QueryCounter.callbacks[#{callback_name.inspect}].call(args) if QueryCounter.callbacks.has_key?(#{callback_name})
|
83
93
|
started_at = Time.now
|
84
94
|
result = #{original_method_name_with_alias}(*args)
|
85
95
|
::QueryCounter.record(#{resource.inspect}, (Time.now - started_at) * 1_000.0)
|
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doug Youch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Used for monitoring number of external calls
|
14
14
|
email: dougyouch@gmail.com
|
@@ -40,8 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
requirements: []
|
43
|
-
|
44
|
-
rubygems_version: 2.5.2.3
|
43
|
+
rubygems_version: 3.0.3
|
45
44
|
signing_key:
|
46
45
|
specification_version: 4
|
47
46
|
summary: Count requests to external systems
|