Module: RubyBreaker::Runtime::MonitorInstaller

Defined in:
lib/rubybreaker/runtime/monitor.rb

Overview

This module installs a monitor in the object.

Class Method Summary collapse

Class Method Details

.install_monitor(monitor_type, mod) ⇒ Object

Installs an module (class) monitor to the object.



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# 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) ⇒ Boolean

returns true if the receiver is a module or a class

Returns:

  • (Boolean)


220
221
222
# 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) ⇒ Object

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



226
227
228
229
230
231
232
233
234
235
236
# 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