Top Level Namespace

Defined Under Namespace

Modules: Formatter, GlobalHelpers Classes: HTML, Livetext, Object, Processor, StringParser

Instance Method Summary collapse

Instance Method Details

#checkpoint(msg = nil) ⇒ Object



12
13
14
15
# File 'lib/livetext/errors.rb', line 12

def checkpoint(msg = nil)
  file, line, meth = whence(1)
  display(file, line, meth, msg)
end

#checkpoint!(msg = nil) ⇒ Object

with pause



22
23
24
25
26
27
# File 'lib/livetext/errors.rb', line 22

def checkpoint!(msg = nil)        # with pause
  file, line, meth = whence(1)
  display(file, line, meth, msg)
  print "::: Pause..."
  gets
end

#checkpoint?(msg = nil) ⇒ Boolean

with sleep 3

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/livetext/errors.rb', line 17

def checkpoint?(msg = nil)        # with sleep 3
  file, line, meth = whence(1)
  display(file, line, meth, msg)
end

#fatal(err) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/livetext/errors.rb', line 37

def fatal(err)
  file, line, meth = whence(2)  # 2 = skip rescue
  puts "Error in #{meth} in #{file}"
  puts "WTF??"
  puts  "     err = #{err.inspect}"
  if err.respond_to?(:backtrace)
    context = err.backtrace.map {|x| "     " + x + "\n" }
    puts context
  end
  abort "Terminated."
end

#make_exception(sym, str, target_class = Object) ⇒ Object

More later?



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/livetext/errors.rb', line 52

def make_exception(sym, str, target_class = Object)
  return if target_class.constants.include?(sym)
  klass = sym   # :"#{sym}_Class"
  target_class.const_set(klass, StandardError.dup)
  define_method(sym) do |*args|
    args = [] unless args.first
    msg = str.dup
    args.each.with_index {|arg, i| msg.sub!("%#{i+1}", arg.to_s) }
    target_class.class_eval(klass.to_s).new(msg)
  end
end

#warning(err) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/livetext/errors.rb', line 29

def warning(err)
  file, line, meth = whence(2)  # 2 = skip rescue
  puts "Error in #{meth} in #{file} (non-fatal?)"
  puts "      err = #{err.inspect}"
  puts "      #{err.backtrace[0]}" if err.respond_to?(:backtrace)
  puts
end