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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e27d7f722db3cd6ecd4a3caf10c060f98ef19522
4
- data.tar.gz: cc07cb70ae8b1f10fff49af5ef4486221384f1e2
3
+ metadata.gz: 86fc8326b29fd8e4f6a275738ce0fee8d352d62b
4
+ data.tar.gz: c94ebe876eb90aefa8d4ed1dce3fce4a316e0b2a
5
5
  SHA512:
6
- metadata.gz: a6a7eaf403137407638e924328a5f35e0601bf4be2096c4519317bcd4e3812208e23af76c5f44d2ed98d32e61494482e02ad99d1e5128f5379068c972de5b5e3
7
- data.tar.gz: 64c6fc06b8c0cef3b80b45facfe04a164d23423ce47829eef36a77a2baed8abccafe941880bd150fb1f6ba02230ac28814d6f4b57798a757d1cc81a02e0da8d6
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
- command_str = if args.size == 1 && args.first.is_a?(Array)
28
- args.first.map(&:inspect).join(', ')
29
- else
30
- args.map(&:inspect).join(' ')
31
- end
32
- ActiveSupport::Notifications.instrument("call.#{event_namespace}",
33
- name: "#{event_namespace.to_s.camelize} #{m}",
34
- command: command_str) do
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
@@ -1,5 +1,5 @@
1
1
  module ActiveSupport
2
2
  module OperationLogger
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport-operation_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Bodah