class Object

Public Instance Methods

_require() click to toggle source
# File lib/ckuru-tools.rb, line 345
def _require ; each {|r| require r } ; end
calling_method() click to toggle source
# File lib/ckuru-tools.rb, line 457
def calling_method
  caller[1] ? caller[1].match(/`(.*?)'/)[1] : ""
end
calling_method2() click to toggle source
# File lib/ckuru-tools.rb, line 461
def calling_method2
  if caller[2]
    if matchdata = caller[2].match(/`(.*?)'/)
      matchdata[1]
    else
      ""
    end
  else
    ""
  end
end
calling_method3() click to toggle source
# File lib/ckuru-tools.rb, line 473
def calling_method3
  if caller[3]
    if matchdata = caller[3].match(/`(.*?)'/)
      matchdata[2]
    else
      ""
    end
  else
    ""
  end
end
calling_method_sig() click to toggle source
# File lib/ckuru-tools.rb, line 487
def calling_method_sig
  caller[1] ? caller[1] : ""
end
chatty_exec(level,name) { || ... } click to toggle source
# File lib/ckuru-tools.rb, line 526
def chatty_exec(level,name)
  ret = yield
  ckebug level, "#{name} is #{ret}"
  ret
end
ckebug(level,msg) click to toggle source
# File lib/ckuru-tools.rb, line 449
def ckebug(level,msg)      
  CkuruTools::Debug.instance.debug(level,msg)
end
current_method() click to toggle source
# File lib/ckuru-tools.rb, line 453
def current_method
  caller[0].match(/`(.*?)'/)[1]
end
docmd(cmd,dir=nil) click to toggle source
# File lib/ckuru-tools.rb, line 347
def docmd(cmd,dir=nil)
  ret = docmdi(cmd,dir)
  if ret.exitstatus != 0
    raise "cmd #{cmd} exitstatus #{ret.exitstatus} : #{ret}"
  end
  ret
end
docmd_dir(h={}) click to toggle source
# File lib/ckuru-tools.rb, line 403
def docmd_dir(h={})
  ret = nil
  if h[:dir]
    unless Dir.chdir(h[:dir]) 
      ckebug 0, "failed to cd to #{h[:dir]}"
      return nil
    end
  end
  if h[:commands]
    h[:commands].each do |cmd|
      ret = docmd(cmd)
      if ret.exitstatus != 0
        ckebug 0, "giving up"
        return ret
      end
    end
  end
  ret
end
docmdi(cmd,dir=nil) click to toggle source
# File lib/ckuru-tools.rb, line 364
def docmdi(cmd,dir=nil)
  if dir
    unless Dir.chdir(dir) 
      ckebug 0, "failed to cd to #{dir}"
      return nil
    end
  end
  ret = msg_exec "running #{cmd}" do
    cmd.gsub!(/\\/,"\\\\\\\\\\\\\\\\")
    cmd.gsub!(/\'/,"\\\\'")
    cmd.gsub!(/\"/,"\\\\\\\\\\\"")
    system("bash -c \"#{cmd}\"")
    if $?.exitstatus != 0 
      print " ** failed ** exit code #{$?.exitstatus} "
    end
  end
  $?
end
docmdq(cmd,dir=nil) click to toggle source
# File lib/ckuru-tools.rb, line 355
def docmdq(cmd,dir=nil)
  ret = docmdqi(cmd,dir)
  if ret.exitstatus != 0
    raise "cmd #{cmd} exitstatus #{ret.exitstatus} : #{ret}"
  end
  ret
end
docmdqi(cmd,dir=nil) click to toggle source
# File lib/ckuru-tools.rb, line 383
def docmdqi(cmd,dir=nil)
  if dir
    unless Dir.chdir(dir) 
      ckebug 0, "failed to cd to #{dir}"
      return nil
    end
  end
  cmd.gsub!(/\\/,"\\\\\\\\\\\\\\\\")
  cmd.gsub!(/\'/,"\\\\'")
  cmd.gsub!(/\"/,"\\\\\\\\\\\"")
  system("bash -c \"#{cmd}\"")
  if $?.exitstatus != 0 
    print " ** failed ** exit code #{$?.exitstatus} "
  end
  $?
end
emacs_trace() { || ... } click to toggle source
# File lib/ckuru-tools.rb, line 423
def emacs_trace
  begin
    yield
  rescue Exception => e
    puts e
    puts "... exception thrown from ..."
    e.backtrace.each do |trace|
      a = trace.split(/:/)
      if a[0].match(/^\//)
        puts "#{a[0]}:#{a[1]}: #{a[2..a.length].join(':')}"
      else
        d = File.dirname(a[0])
        f = File.basename(a[0])
        dir = `cd #{d}; pwd`.chomp
        goodpath = File.join(dir,f)

        puts "#{goodpath}:#{a[1]}: #{a[2..a.length].join(':')}"              
      end
      if $emacs_trace_debugger
        require 'ruby-debug'
      end
    end
    raise "sorry ...exiting"
  end
end
instance_inherits_from?(klass) click to toggle source

see if this object's class inherits from another class

# File lib/ckuru-tools.rb, line 341
def instance_inherits_from?(klass)
  self.class.inherits_from?(klass)
end
msg_exec(msg) { || ... } click to toggle source

module MlImportUtils

# File lib/ckuru-tools.rb, line 518
def msg_exec(msg)
  printmsg("#{msg} ... ",false)
  t1 = Time.new
  ret = yield
  puts "done (#{Time.new - t1})"
  ret
end
printmsg(msg,newline=true) click to toggle source
# File lib/ckuru-tools.rb, line 511
def printmsg(msg,newline=true)
  print "#{Time.new.ckuru_time_string}: #{msg}"
  puts if newline
end
this_is_an_abstract_constructor_for(klass) click to toggle source

this method allows a an 'initialize' method to define itself as a abstract class; yet still run some code.

To use effectively place at the last line of an initialize method like so:

class DataSource < ::CkuruTools::HashInitializerClass
  def initialize(h={})
    super h
    this_is_an_abstract_constructor_for AuraVisualize::DataSource
  end
end
# File lib/ckuru-tools.rb, line 324
    def this_is_an_abstract_constructor_for(klass)
      unless self.class.superclass.inherits_from? klass # abstract constructor
        str = ''
        self.class.decendants.each do |d|
          str += "#{d}\n"
        end
        raise <<"EOF" 
Do not call method of #{self.class}.#{calling_method} directly, you must instantiate a base class.

Maybe you want one of these?:

#{str}
EOF
      end
    end