Sha256: 60d74b650a80271913c1a93bc9cc06d947d9cc3c9f04c52f7c4756b9cf1fd7c5
Contents?: true
Size: 1.49 KB
Versions: 2
Compression:
Stored size: 1.49 KB
Contents
require "fileutils" require "term/ansicolor" class Out class << self include ::Term::ANSIColor def out(msg, color=nil) m = msg if color puts send(color.to_sym, m) else puts m end #write_tmp(m) msgs << m end 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 def save? @save end def save_on File.write(tmp_path, "save_on at #{Time.now}") @save = true end def save_off File.write(tmp_path, "save_on at #{Time.now}") @save = false end def save @save ||= false end def tmp_path FileUtils.touch "/tmp/ro_out" @tmp_path ||= "/tmp/ro_out" end 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 def reset @msgs = [] end def msgs @msgs.flatten! if @msgs.respond_to?(:flatten!) @msgs = [] if @msgs and @msgs.length > 999 @msgs ||= [] end #class Msg # def initialize(msg) # @msg = msg # end # # def to_s # @msg # end #end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ro_commands-0.0.3 | lib/ro_commands/helpers/out.rb |
ro_commands-0.0.2 | lib/ro_commands/helpers/out.rb |