class Darko::Delegator

Public Class Methods

new(object, log_to_file) click to toggle source
Calls superclass method
# File lib/darko/delegator.rb, line 6
def initialize object, log_to_file
  @initialized = false
  @log_to_file = log_to_file
  @logger = log_to_file ? Logger.new(File.new("#{object.class}-#{Time.now.to_i}.darko.log", "w")) : Logger.new(STDOUT)
  super(object)
  @initialized = true
  @logger.debug('Darko delegator initialized')
end

Public Instance Methods

__getobj__() click to toggle source

TODO: Differentiate between access and mutation - this should be a filter passed through the watcher init

# File lib/darko/delegator.rb, line 17
def __getobj__
  called(:access) if @initialized # not fan
  darko__getobj__
end
Also aliased as: darko__getobj__
__setobj__(new_obj) click to toggle source
Calls superclass method
# File lib/darko/delegator.rb, line 22
def __setobj__ new_obj
  called(:mutation) if @initialized # not fan
  super(new_obj)
end
called(action_type) click to toggle source

Anything we want to do on watcher object access do it here

# File lib/darko/delegator.rb, line 28
def called action_type
  begin
    stack_without_darko = Kernel.caller(3..-1).join("\n")
    @logger.debug("Object: #{action_type} detected at: ")
    @logger.debug "\t#{stack_without_darko}"
  rescue
    @logger.error('Unable to collect a stack trace')
  end
end
darko__getobj__()
Alias for: __getobj__