Module: CallbackSupport

Included in:
RubyAgent::Agent
Defined in:
lib/ruby_agent/callback_support.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
# File 'lib/ruby_agent/callback_support.rb', line 2

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#run_callbacks(event_data) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ruby_agent/callback_support.rb', line 49

def run_callbacks(event_data)
  # Run general on_event callbacks
  self.class.on_event_callbacks.each do |callback|
    if callback.is_a?(Proc)
      instance_exec(event_data, &callback)
    else
      send(callback, event_data)
    end
  end

  # Run event-specific callbacks
  event_type = event_data["type"]
  return unless event_type

  self.class.specific_event_callbacks(event_type).each do |callback|
    if callback.is_a?(Proc)
      instance_exec(event_data, &callback)
    else
      send(callback, event_data)
    end
  end
end