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