Class: Tracebin::Patches

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/tracebin/patches.rb

Overview

This singleton class handles patching for any given library we wish to instrument. To create a new patch for a library, just create a file in the lib/patches directory with any name. These files typically contain code that will monkeypatch a given library. When you wish to execute the code in that file, just call its corresponding patch_ method. For example, if we have a file lib/patches/foo.rb, then we would just call:

::Tracebin::Patches.patch_foo

Constant Summary collapse

PATCH_METHOD_REGEX =
/^patch_(.*)$/

Class Method Summary collapse

Methods included from Helpers

#deserialize_time_string, #milliseconds_between, #time_to_string, #timestamp_string, #to_milliseconds

Class Method Details

.handle_event(handler_name, event_data) ⇒ Object



20
21
22
23
# File 'lib/tracebin/patches.rb', line 20

def handle_event(handler_name, event_data)
  handler = instance_variable_get "@#{handler_name}_event_handler"
  handler.call event_data unless handler.nil?
end

.method_missing(method_sym, *args, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/tracebin/patches.rb', line 25

def method_missing(method_sym, *args, &block)
  if method_sym.to_s =~ PATCH_METHOD_REGEX
    patch_name = $1
    instance_variable_set "@#{patch_name}_event_handler", block
    require "tracebin/patches/#{patch_name}"
  else
    super
  end
end

.respond_to?(method_sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
# File 'lib/tracebin/patches.rb', line 35

def respond_to?(method_sym, include_private = false)
  if method_sym.to_s =~ PATCH_METHOD_REGEX
    true
  else
    super
  end
end