module RubyBreaker::Runtime

This module contains things that are needed at runtime.

Constants

BLACKLIST

Prohibit these module/class+method from being overriden.

BREAKABLES

This set keeps track of modules/classes that will be monitored. DEPRECATED : Use breakable method instead.

CONTEXT

This context is used for keeping track of context in the user code. This will ignore the context within the RubyBreaker code, so it is easy to pinpoint program locations without distraction from the RubyBreaker code.

DEFAULT_TYPE_SYSTEM

The default type system for RubyBreaker

GLOBAL_MONITOR_SWITCH

TODO:For now, we use a global switch; but in future, a switch per object should be used for multi-process apps. However, there is still a concern for module tracking in which case, there isn’t really a way to do this unless we track with the process or some unique id for that process.

MONITOR_MAP

This hash maps a (breakable) module to a type monitor

OVERRIDE_PREFIX

This constant holds the string used internally by RubyBreaker to indicate overridden methods.

TYPE_MAP

This hash maps a module to a nested hash that maps a method name to a method type. This hash is shared between breakable modules/classes and non-breakable modules/classes.

WHITELIST

Allow certain methods of these classes/modules to be overrriden. That is, they will take unwrapped arguments whatsoever.

WRAPPED_INDICATOR

This constant is used to determine if an object is a wrapped object.

Public Class Methods

break(*mods) click to toggle source

This method instruments the specified modules/classes at the time of the call so they are monitored for type documentation.

# File lib/rubybreaker/runtime.rb, line 54
def self.break(*mods)
  self.install(:break, *mods)
end
breakable(*mods) click to toggle source

This method modifies specified modules/classes at the very moment (instead of registering them for later). DEPRECATED: Use +break()+ method instead

# File lib/rubybreaker/runtime.rb, line 76
def self.breakable(*mods)
  self.install(:break, *mods)
end
check(*mods) click to toggle source

This method instruments the specified modules/classes at the time of the call so that they are type checked during runtime.

# File lib/rubybreaker/runtime.rb, line 60
def self.check(*mods)
  self.install(:check, *mods)
end
instrument() click to toggle source

This method installs a monitor for each breakable module. DEPRECATED: Use +breakable()+ method instead.

# File lib/rubybreaker/runtime.rb, line 66
def self.instrument() 
  BREAKABLES.each do |mod|
    # Duplicate checks in place in these calls.
    MonitorInstaller.install_monitor(:break, mod)
  end
end

Private Class Methods

eigen_class(mod) click to toggle source

This returns the eigen class of the given module.

# File lib/rubybreaker/runtime/util.rb, line 12
def self.eigen_class(mod)
  return mod.module_eval("class << self; self end")
end
install(monitor_type=:break, *mods) click to toggle source

Instruments the monitor to the specified modules/classes.

TODO: monitor_type is currently not in use. Plan on using it in future

to do type checker instrumentation
# File lib/rubybreaker/runtime.rb, line 26
def self.install(monitor_type=:break, *mods)
  mods.each do |mod|
    case mod
    when Array
      self.install(monitor_type, *mod)
    when Module, Class
      # Install both instance and its eigen class
      MonitorInstaller.install_monitor(monitor_type, mod)
      eigen_class = self.eigen_class(mod)
      MonitorInstaller.install_monitor(monitor_type, eigen_class)
    when String, Symbol
      begin
        # Get the actual module and install it right now
        mod = eval("#{mod}", TOPLEVEL_BINDING)
        self.install(monitor_type, mod) if mod
      rescue NameError => e
        RubyBreaker.error("#{mod} cannot be found.")
      end
    else
      RubyBreaker.error("You must specify a module/class or its name.")
    end
  end
end