Module: Uncouple::Action::Instrumentation

Defined in:
lib/uncouple/action/instrumentation.rb

Instance Method Summary collapse

Instance Method Details

#alias_with_instrumentation(method) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/uncouple/action/instrumentation.rb', line 12

def alias_with_instrumentation(method)

  method_without_instrumentation = "#{method}_without_instrumentation".to_sym
  method_with_instrumentation = "#{method}_with_instrumentation".to_sym

  return if instance_methods.include?(method_with_instrumentation)

  define_method method_with_instrumentation do
    ActiveSupport::Notifications.instrument "#{self.class.to_s}##{method}", params do
      send(method_without_instrumentation)
    end
  end

  alias_method method_without_instrumentation, method
  alias_method method, method_with_instrumentation

end

#method_added(method) ⇒ Object



5
6
7
8
9
10
# File 'lib/uncouple/action/instrumentation.rb', line 5

def method_added(method)
  case method
  when :perform, :authorize!
    alias_with_instrumentation(method)
  end
end