Module: DebugMe
- Defined in:
- lib/debug_me.rb,
lib/debug_me/version.rb
Constant Summary collapse
- DEBUG_ME_VERSION =
I know. Its weird to duplicate the name space; but, doing this allows you to include DebugMe in your code to get direct access to the debug_me method without poluting your code with an object name that is so common.
'1.0.6'
Instance Method Summary collapse
Instance Method Details
#debug_me(options = {}, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/debug_me.rb', line 20 def debug_me( = {}, &block) if 'Hash' == .class.to_s = DebugMeDefaultOptions.merge() else = DebugMeDefaultOptions.merge(tag: ) end out_string = '' f = [:file] l = [:logger] s = '' s += Time.now.strftime([:strftime])+' ' if [:time] s += "#{[:tag]}" bt = caller # where_from under 1.8.6 its a stack trace array under 1.8.7+ as a string if [:header] cf = bt.is_a?(Array) ? bt[0] : bt out_string = sprintf("%s Source: %s\n", s, cf) if [:levels] > 0 levels = [:levels].to_i bt[1..levels].each_with_index do |cff, level| out_string += sprintf("%s Source: FROM (%02d) : %s\n", s, level, cff) end end end if block_given? block_value = [block.call].flatten.compact if block_value.empty? block_value = [] block_value += [eval('local_variables', block.binding)] if [:lvar] block_value += [eval('instance_variables', block.binding)] if [:ivar] block_value += [self.class.send('class_variables')] if [:cvar] block_value += [self.class.constants] if [:cconst] block_value = block_value.flatten.compact end block_value.map!(&:to_s) block_value.each do |v| ev = eval("defined?(#{v})",block.binding).nil? ? '<undefined>' : eval(v, block.binding) out_string += sprintf( "%s %s -=> %s", s,v,ev.pretty_inspect) end end ## if block_given? unless f.nil? f.puts out_string f.flush end unless l.nil? l.debug(out_string) if l.respond_to? :debug end return out_string end |