Module: DebugLogging::ClassNotifier

Defined in:
lib/debug_logging/class_notifier.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



4
5
6
# File 'lib/debug_logging/class_notifier.rb', line 4

def extended(base)
  base.extend(LambDartable::Note)
end

Instance Method Details

#notified(*methods_to_notify) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/debug_logging/class_notifier.rb', line 9

def notified(*methods_to_notify)
  methods_to_notify, payload, config_opts = DebugLogging::Util.extract_payload_and_config(
    method_names: methods_to_notify,
    payload: nil,
    config: nil,
  )
  Array(methods_to_notify).each do |decorated_method|
    decorated_method, method_payload, method_config_opts = DebugLogging::Util.extract_payload_and_config(
      method_names: decorated_method,
      payload: payload,
      config: config_opts,
    )
    original_method = method(decorated_method)
    (class << self; self; end).class_eval do
      define_method(decorated_method) do |*args, **kwargs, &block|
        lamb_dart = LambDart::Note.new(
          klass: self,
          method_config_opts:,
          method_payload:,
          args:,
          kwargs:,
          decorated_method:,
        )
        _dl_ld_notify(lamb_dart) do
          _dl_ld_error_handle(lamb_dart) do
            original_method.call(*args, **kwargs, &block)
          end
        end
      end
    end
  end
end