Class ObjectMonitor
In: lib/object_monitor.rb
Parent: Object

Methods

Included Modules

Observable

Attributes

nb_method  [R] 

Public Class methods

[Source]

# File lib/object_monitor.rb, line 17
  def initialize(object, *observers)
    @object = object
    add_observers(*observers)
    @nb_method = 0
  end

Public Instance methods

[Source]

# File lib/object_monitor.rb, line 23
  def method_missing(meth, *args, &block)
    info = init_method_info(meth, *args, &block)
    start_method(info)
    result = nil
    begin
      result = @object.send(meth, *args, &block)
    rescue Exception => exc
      info[:stop_time] = Time.now
      info[:error] = exc
      stop_method(info)
      raise exc
    ensure
      @nb_method += 1
    end
    info[:stop_time] = Time.now
    info[:result] = result
    stop_method(info)
    result
  end

Protected Instance methods

[Source]

# File lib/object_monitor.rb, line 44
  def init_method_info(meth, *args, &block)
    {
      :num => @nb_method,
      :receiver => @object,
      :method => meth,
      :args => args,
      :block => block,
      :start_time => Time.now,
      :stop_time => nil,
      :thread => Thread.current,
      :error => nil,
      :result => nil,
    }
  end

[Source]

# File lib/object_monitor.rb, line 60
  def start_method(info)
    changed
    notify_observers(:start_method, info)
  end

[Source]

# File lib/object_monitor.rb, line 66
  def stop_method(info)
    changed
    notify_observers(:stop_method, info)
  end

[Validate]