Class: Out
- Extended by:
- Term::ANSIColor, Thor::Shell
- Defined in:
- lib/ro_helpers/out.rb
Class Attribute Summary collapse
-
.msg ⇒ Object
Returns the value of attribute msg.
-
.output ⇒ Object
Returns the value of attribute output.
Class Method Summary collapse
- .debug(msg, color = nil) ⇒ Object
- .handle_msg(msg) ⇒ Object
- .out(msg, color = nil) ⇒ Object
- .raw_out(msg, color = nil) ⇒ Object
- .reset ⇒ Object
- .save ⇒ Object
- .save? ⇒ Boolean
- .save_off ⇒ Object
- .save_on ⇒ Object
- .say(*args) ⇒ Object
- .say_with_color(status, new_msg, other, color = nil) ⇒ Object
- .table(status, msg, other = nil, color = nil) ⇒ Object
- .time_now ⇒ Object
- .time_say(*args) ⇒ Object
- .tmp ⇒ Object
- .tmp_path ⇒ Object
-
.warn(msg, other = nil) ⇒ Object
%w(say say_status).each do |m| define_method(:“#m”) do |*args| shell.send(:“#m”, *args) end end.
- .write_tmp(ctn) ⇒ Object
Class Attribute Details
.msg ⇒ Object
Returns the value of attribute msg.
8 9 10 |
# File 'lib/ro_helpers/out.rb', line 8 def msg @msg end |
.output ⇒ Object
Returns the value of attribute output.
31 32 33 |
# File 'lib/ro_helpers/out.rb', line 31 def output @output end |
Class Method Details
.debug(msg, color = nil) ⇒ Object
50 51 52 53 54 |
# File 'lib/ro_helpers/out.rb', line 50 def debug(msg, color=nil) if $RODEBUG out(msg, color) end end |
.handle_msg(msg) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/ro_helpers/out.rb', line 66 def handle_msg(msg) if msg.is_a?(Array) msg.join("\n") else msg end end |
.out(msg, color = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/ro_helpers/out.rb', line 56 def out(msg, color=nil) reset if color say send(:"#{color}", bold(msg)) else say msg end @msg = handle_msg(msg) end |
.raw_out(msg, color = nil) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ro_helpers/out.rb', line 74 def raw_out(msg, color=nil) reset if color p send(color.to_sym, msg) else p msg end #write_tmp(m) @msg = msg end |
.reset ⇒ Object
136 137 138 |
# File 'lib/ro_helpers/out.rb', line 136 def reset @msg = '' end |
.save ⇒ Object
116 117 118 |
# File 'lib/ro_helpers/out.rb', line 116 def save @save ||= false end |
.save? ⇒ Boolean
101 102 103 |
# File 'lib/ro_helpers/out.rb', line 101 def save? @save end |
.save_off ⇒ Object
110 111 112 113 114 |
# File 'lib/ro_helpers/out.rb', line 110 def save_off File.write(tmp_path, "save_on at #{Time.now}") @save = false end |
.save_on ⇒ Object
105 106 107 108 |
# File 'lib/ro_helpers/out.rb', line 105 def save_on File.write(tmp_path, "save_on at #{Time.now}") @save = true end |
.say(*args) ⇒ Object
45 46 47 48 |
# File 'lib/ro_helpers/out.rb', line 45 def say(*args) output.puts "#{args.flatten.join(" ")}" output.flush end |
.say_with_color(status, new_msg, other, color = nil) ⇒ Object
26 27 28 29 |
# File 'lib/ro_helpers/out.rb', line 26 def say_with_color(status, new_msg, other, color=nil) color ||= "green" say "#{time_now}#{send(:"#{color}", bold(status))} #{new_msg} #{other}" end |
.table(status, msg, other = nil, color = nil) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/ro_helpers/out.rb', line 19 def table(status, msg, other=nil, color=nil) status = status.ljust(7) new_msg = msg.ljust(20) say_with_color(status, new_msg, other, color) end |
.time_now ⇒ Object
37 38 39 |
# File 'lib/ro_helpers/out.rb', line 37 def time_now Time.now.strftime("%H:%M:%S - ") end |
.time_say(*args) ⇒ Object
41 42 43 |
# File 'lib/ro_helpers/out.rb', line 41 def time_say(*args) say([time.now, args]) end |
.tmp ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ro_helpers/out.rb', line 125 def tmp if test(?f, tmp_path) File.readlines(tmp_path).delete_if do |l| l.blank? end else FileUtils.touch tmp_path [] end end |
.tmp_path ⇒ Object
120 121 122 123 |
# File 'lib/ro_helpers/out.rb', line 120 def tmp_path FileUtils.touch "/tmp/ro_out" @tmp_path ||= "/tmp/ro_out" end |
.warn(msg, other = nil) ⇒ Object
%w(say say_status).each do |m|
define_method(:"#{m}") do |*args|
shell.send(:"#{m}", *args)
end
end
15 16 17 |
# File 'lib/ro_helpers/out.rb', line 15 def warn(msg, other=nil) table("WARNING", msg, other, "red") end |
.write_tmp(ctn) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ro_helpers/out.rb', line 86 def write_tmp(ctn) if save? unless ctn.match(%r{^\s*$}) tmp_ctn = tmp tmp_ctn << "At #{Time.now}" tmp_ctn << ctn File.write(tmp_path, tmp_ctn.join("\n")) end else if test(?s, tmp_path) and test(?s, tmp_path) > 10_000 FileUtils.rm_f(tmp_path) end end end |