Module: HelperClasses::DPuts
- Extended by:
- DPuts
- Defined in:
- lib/helperclasses/dputs.rb
Instance Attribute Summary collapse
-
#log_file ⇒ Object
Returns the value of attribute log_file.
-
#mutex ⇒ Object
Returns the value of attribute mutex.
-
#show_time ⇒ Object
Returns the value of attribute show_time.
-
#silent ⇒ Object
Returns the value of attribute silent.
-
#terminal_width ⇒ Object
Returns the value of attribute terminal_width.
Instance Method Summary collapse
- #ddputs(n, &s) ⇒ Object
- #dp(s) ⇒ Object
- #dputs(n, &s) ⇒ Object
- #dputs_func ⇒ Object
- #dputs_getcaller ⇒ Object
- #dputs_out(n, s, call) ⇒ Object
- #dputs_unfunc ⇒ Object
- #log_msg(mod, msg) ⇒ Object
Instance Attribute Details
#log_file ⇒ Object
Returns the value of attribute log_file.
7 8 9 |
# File 'lib/helperclasses/dputs.rb', line 7 def log_file @log_file end |
#mutex ⇒ Object
Returns the value of attribute mutex.
7 8 9 |
# File 'lib/helperclasses/dputs.rb', line 7 def mutex @mutex end |
#show_time ⇒ Object
Returns the value of attribute show_time.
7 8 9 |
# File 'lib/helperclasses/dputs.rb', line 7 def show_time @show_time end |
#silent ⇒ Object
Returns the value of attribute silent.
7 8 9 |
# File 'lib/helperclasses/dputs.rb', line 7 def silent @silent end |
#terminal_width ⇒ Object
Returns the value of attribute terminal_width.
7 8 9 |
# File 'lib/helperclasses/dputs.rb', line 7 def terminal_width @terminal_width end |
Instance Method Details
#ddputs(n, &s) ⇒ Object
83 84 85 86 87 |
# File 'lib/helperclasses/dputs.rb', line 83 def ddputs(n, &s) s = yield s #dp caller(0) dputs_out(-n, s, caller(0)[1]) end |
#dp(s) ⇒ Object
89 90 91 92 |
# File 'lib/helperclasses/dputs.rb', line 89 def dp(s) dputs_out(0, s.class == String ? s : s.inspect, caller(0)[1]) s end |
#dputs(n, &s) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/helperclasses/dputs.rb', line 74 def dputs(n, &s) n *= -1 if ($DPUTS_FUNCS and $DPUTS_FUNCS.index(dputs_getcaller)) if !self.class.const_defined?(:DEBUG_LVL) or self.class.const_get(:DEBUG_LVL) >= n s = yield s dputs_out(n, s, caller(0)[1]) end end |
#dputs_func ⇒ Object
64 65 66 67 |
# File 'lib/helperclasses/dputs.rb', line 64 def dputs_func $DPUTS_FUNCS ||= [] $DPUTS_FUNCS.push(dputs_getcaller) unless $DPUTS_FUNCS.index(dputs_getcaller) end |
#dputs_getcaller ⇒ Object
60 61 62 |
# File 'lib/helperclasses/dputs.rb', line 60 def dputs_getcaller caller(0)[2].sub(/:.*:in/, '').sub(/block .*in /, '') end |
#dputs_out(n, s, call) ⇒ Object
15 16 17 18 19 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 |
# File 'lib/helperclasses/dputs.rb', line 15 def dputs_out(n, s, call) return if DPuts.silent if precision = DPuts.show_time $dputs_time ||= Time.now - 120 now = Time.now show = false case precision when /sec/ show = now.to_i != $dputs_time.to_i when /min/ show = (now.to_i / 60).floor != ($dputs_time.to_i / 60).floor end show and puts "\n *** It is now: " + Time.now.strftime("%Y-%m-%d %H:%M:%S") $dputs_time = now end DPuts.mutex.synchronize do width = DPuts.terminal_width width -= 30.0 file, func = call.split(" ") file = file[/^.*\/([^.]*)/, 1] who = (":" + n.to_s + ":" + file.to_s + func.to_s).ljust(30, ["X", "x", "*", "-", ".", " "][n]) lines = [] pos = 0 while (pos < s.length) len = width if s.length - pos > width len = s.rindex(/[, .;=&>]/, pos + width) len and len = len - pos + 1 if len < width / 2 len = width end end lines.push s.slice(pos, len) pos += len end puts who + " " + lines.shift.to_s lines.each { |l| puts " " * (32) + l } end end |
#dputs_unfunc ⇒ Object
69 70 71 72 |
# File 'lib/helperclasses/dputs.rb', line 69 def dputs_unfunc $DPUTS_FUNCS ||= [] $DPUTS_FUNCS.index(dputs_getcaller) and $DPUTS_FUNCS.delete(dputs_getcaller) end |
#log_msg(mod, msg) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/helperclasses/dputs.rb', line 94 def log_msg(mod, msg) dputs(1) { "Info from #{mod}: #{msg}" } return if not DPuts.log_file File.open(DPuts.log_file, "a") { |f| str = Time.now.strftime("%a %y.%m.%d-%H:%M:%S #{mod}: #{msg}") f.puts str } end |