module Ric::Debug

Public Instance Methods

deb(str) click to toggle source
   # File lib/ric/debug.rb
11 def deb(str)
12   puts "#DEB# #{str}" if $DEBUG
13 end
Also aliased as: debug
deb?() { || ... } click to toggle source

if DEBUG is true, then execute the code

   # File lib/ric/debug.rb
75 def deb?() 
76       yield if $DEBUG
77 end
Also aliased as: if_deb, if_deb?
debug(str)
Alias for: deb
debug2(s, opts = {} ) click to toggle source

shouldnt work right now yet..

   # File lib/ric/debug.rb
16 def debug2(s, opts = {} )
17   out = opts.fetch(:out, $stdout)
18   tag = opts.fetch(:tag, '_DFLT_')
19   really_write = opts.fetch(:really_write, true) # you can prevent ANY debug setting this to false
20   write_always = opts.fetch(:write_always, false)
21 
22   raise "ERROR: ':tags' must be an array in debug(), maybe you meant to use :tag?" if ( opts[:tags] && opts[:tags].class != Array )
23   final_str = "#RDeb#{write_always ? '!' : ''}[#{opts[:tag] || '-'}] #{s}"
24   final_str = "\033[1;30m" +final_str + "\033[0m" if opts.fetch(:coloured_debug, true) # color by gray by default
25   if (debug_tags_enabled? ) # tags
26     puts( final_str ) if debug_tag_include?( opts )
27   else # normal behaviour: if NOT tag
28     puts( final_str ) if ((really_write && $DEBUG) || write_always) && ! opts[:tag]
29   end
30 end
debug?() click to toggle source
   # File lib/ric/debug.rb
81 def debug?()
82   $DEBUG == true
83 end
debug_on(comment='Debug Activated (some lazy guys didnt provide a description :P)') click to toggle source
  # File lib/ric/debug.rb
7 def debug_on(comment='Debug Activated (some lazy guys didnt provide a description :P)')
8   $DEBUG = true
9 end
debug_tag_include?(opts) click to toggle source
   # File lib/ric/debug.rb
64 def debug_tag_include?(opts)
65   assert_array($_debug_tags, 'debug_tags')
66   assert_class( opts[:tag], Symbol, "tag must be a symbol, ", :dontdie => true ) if opts[:tag]
67   assert_array( opts[:tags] , 'opts[:tags]' ) if opts[:tags]
68   return $_debug_tags.include?(opts[:tag].to_sym) if opts[:tag]
69   return ($_debug_tags & opts[:tags]).size > 0    if opts[:tags]
70   #return $_debug_tags.include?(tag_or_tags.to_sym) if (tag.class == String || tag.class == Symbol)
71   return false
72 end
debug_tags_enabled?() click to toggle source
   # File lib/ric/debug.rb
61 def debug_tags_enabled?
62   $_debug_tags != []
63 end
debug_with_steroids(s, opts = {} ) click to toggle source
   # File lib/ric/debug.rb
46 def debug_with_steroids(s, opts = {} )
47   out = opts.fetch(:out, $stdout)
48   tag = opts.fetch(:tag, '_DFLT_')
49   really_write = opts.fetch(:really_write, true) # you can prevent ANY debug setting this to false
50   write_always = opts.fetch(:write_always, false)
51 
52   raise "ERROR: ':tags' must be an array in debug(), maybe you meant to use :tag?" if ( opts[:tags] && opts[:tags].class != Array )
53   final_str = "#RDeb#{write_always ? '!' : ''}[#{opts[:tag] || '-'}] #{s}"
54   final_str = "\033[1;30m" +final_str + "\033[0m" if opts.fetch(:coloured_debug, true) # color by gray by default
55   if (debug_tags_enabled? ) # tags
56     puts( final_str ) if debug_tag_include?( opts )
57   else # normal behaviour: if NOT tag
58     puts( final_str ) if ((really_write && $DEBUG) || write_always) && ! opts[:tag]
59   end
60 end
err(str) click to toggle source
   # File lib/ric/debug.rb
85 def err(str)
86       $stderr.puts "ERR[RicLib] #{$0}: '#{str}'"
87 end
fatal(ret,str) click to toggle source
   # File lib/ric/debug.rb
89 def fatal(ret,str)
90       err "#{get_red 'RubyFatal'}(#{ret}) #{str}"
91       exit ret
92 end
if_deb()
Alias for: deb?
if_deb?()
Alias for: deb?
tbd(comment="TODO") click to toggle source
    # File lib/ric/debug.rb
 98 def tbd(comment="TODO")
 99   puts "#{white :TBD} (#{__FILE__}:#{__LINE__}): #{comment}"
100   raise "TBD_EXCEPTION! ''#{comment}''"
101 end
warning(s) click to toggle source
   # File lib/ric/debug.rb
94 def warning(s)
95       err "#{yellow 'WARN'} #{s}"
96 end

Private Instance Methods

_manage_debug_tags(opts) click to toggle source
    # File lib/ric/debug.rb
104 def _manage_debug_tags(opts)
105   $_debug_tags ||= []
106   $_debug_tags += opts[:tags] if opts[:tags]
107   $_debug_tags = $_debug_tags.uniq
108   deb "_manage_debug_tags(): new tags are: #{$_debug_tags}", :tag => :debug
109 end