module RubyBreaker::Runtime::MonitorInstaller

This module installs a monitor in the object.

Public Class Methods

install_monitor(monitor_type, mod) click to toggle source

Installs an module (class) monitor to the object.

# File lib/rubybreaker/runtime/monitor.rb, line 239
def self.install_monitor(monitor_type, mod)

  RubyBreaker.log("Installing #{monitor_type} monitor for #{mod} started.")

  # Do not re-install monitor if already done so.
  if MONITOR_MAP[mod] 
    RubyBreaker.log("#{mod} already has a monitor installed.")
    return
  end

  MONITOR_MAP[mod] = Monitor.new(DEFAULT_TYPE_SYSTEM)

  # Create the type map if it does not exist already. Remember, this
  # map could have been made by typesig().
  TYPE_MAP[mod] = {} unless TYPE_MAP[mod]

  # Get the list of instance methods but do not include inherited
  # methods. Those are part of the owner's not this module.
  meths = mod.instance_methods(false)  

  # See if any method is already documented (explicitly typesig'ed)
  doc_mt_map = Inspector.inspect_all(mod)
  doc_meths = doc_mt_map.keys

  meths.each do |m| 
    # Documented method will not be monkey-patched for "breaking"
    unless monitor_type == :break && doc_meths.include?(m)
      self.monkey_patch_meth(monitor_type, mod, m) 
    end
  end

  RubyBreaker.log("Installing #{monitor_type} monitor for #{mod} ended.")
end
is_module?(mod) click to toggle source

returns true if the receiver is a module or a class

# File lib/rubybreaker/runtime/monitor.rb, line 220
def self.is_module?(mod)
  return mod.respond_to?(:class) && mod.kind_of?(Module)
end
monkey_patch_meth(monitor_type, mod, meth_name) click to toggle source

renames the method in essence; this method also “installs” the module monitor for the class

# File lib/rubybreaker/runtime/monitor.rb, line 226
      def self.monkey_patch_meth(monitor_type, mod, meth_name)
        alt_meth_name = Monitor.get_alt_meth_name(meth_name)
        mod.module_eval("alias :\"#{alt_meth_name}\" :\"#{meth_name}\"")
        RubyBreaker.log("Adding alternate method for #{meth_name}")
        route_call = "RubyBreaker::Runtime::Monitor.route"
        mod.module_eval <<-EOF
          def #{meth_name}(*args, &blk)
            #{route_call}(:#{monitor_type}, self,"#{meth_name}",*args,&blk)
          end
        EOF
      end