activesupport-operation_logger 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_support/operation_logger.rb +16 -11
- data/lib/active_support/operation_logger/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86fc8326b29fd8e4f6a275738ce0fee8d352d62b
|
4
|
+
data.tar.gz: c94ebe876eb90aefa8d4ed1dce3fce4a316e0b2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4725e5bf47a83f552a8fc81df3615e1b07c07d9517dbcd578d5b4c9860ee570c7ece3eee2f2743c13cf5ad04d835880a4b2082565e67f06b6a5b1d71f1b5d2f
|
7
|
+
data.tar.gz: 1c0f0521dc870b048541d9c61425d6ede792a1e8f8c9522711f97fde9874252ebbe14c91014de90d51144e147975ccfad40116af1c854b2936425950162ef4ff
|
@@ -19,19 +19,24 @@ module ActiveSupport
|
|
19
19
|
# @param [Class] klass
|
20
20
|
# @param [Array<Symbol>] methods
|
21
21
|
# @param [Symbol] event_namespace
|
22
|
+
# @param [#call] filter
|
22
23
|
# @return [Module] a module for prepending
|
23
|
-
def self.instrumenter_for(klass, methods, event_namespace)
|
24
|
+
def self.instrumenter_for(klass, methods, event_namespace, filter = nil)
|
24
25
|
Module.new do
|
25
26
|
methods.each do |m|
|
26
27
|
define_method m do |*args, &block|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
if !filter || filter.call(m, *args, &block)
|
29
|
+
command_str = if args.size == 1 && args.first.is_a?(Array)
|
30
|
+
args.first.map(&:inspect).join(', ')
|
31
|
+
else
|
32
|
+
args.map(&:inspect).join(' ')
|
33
|
+
end
|
34
|
+
event_id = "call.#{event_namespace}"
|
35
|
+
name = "#{event_namespace.to_s.camelize} #{m}"
|
36
|
+
ActiveSupport::Notifications.instrument(event_id, name: name, command: command_str) do
|
37
|
+
super *args, &block
|
38
|
+
end
|
39
|
+
else
|
35
40
|
super *args, &block
|
36
41
|
end
|
37
42
|
end
|
@@ -75,12 +80,12 @@ module ActiveSupport
|
|
75
80
|
# instrumenters and ActiveSupport::LogSubscribers
|
76
81
|
#
|
77
82
|
# TODO: @jbodah 2016-04-30: just use one shared event subscriber
|
78
|
-
def self.log_calls_on!(klass, only: nil, event_namespace: nil)
|
83
|
+
def self.log_calls_on!(klass, only: nil, event_namespace: nil, filter: nil)
|
79
84
|
methods = only || MethodHelper.public_owned_instance_methods(klass)
|
80
85
|
event_namespace ||= klass.name.demodulize.underscore
|
81
86
|
event_namespace = event_namespace.to_sym
|
82
87
|
|
83
|
-
klass.prepend EventInstrumenterFactory.instrumenter_for(klass, methods, event_namespace)
|
88
|
+
klass.prepend EventInstrumenterFactory.instrumenter_for(klass, methods, event_namespace, filter)
|
84
89
|
|
85
90
|
EventSubscriberFactory.subscriber_for(klass).attach_to(event_namespace)
|
86
91
|
end
|