Class: Out

Inherits:
Object
  • Object
show all
Extended by:
Term::ANSIColor
Defined in:
lib/ro_commands/helpers/out.rb

Class Method Summary collapse

Class Method Details

.msgsObject



72
73
74
75
76
# File 'lib/ro_commands/helpers/out.rb', line 72

def msgs
  @msgs.flatten! if @msgs.respond_to?(:flatten!)
  @msgs = [] if @msgs and @msgs.length > 999
  @msgs ||= []
end

.out(msg, color = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/ro_commands/helpers/out.rb', line 7

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

.resetObject



68
69
70
# File 'lib/ro_commands/helpers/out.rb', line 68

def reset
  @msgs = []
end

.saveObject



48
49
50
# File 'lib/ro_commands/helpers/out.rb', line 48

def save
  @save ||= false
end

.save?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/ro_commands/helpers/out.rb', line 33

def save?
  @save
end

.save_offObject



42
43
44
45
46
# File 'lib/ro_commands/helpers/out.rb', line 42

def save_off
  File.write(tmp_path, "save_on at #{Time.now}")

  @save = false
end

.save_onObject



37
38
39
40
# File 'lib/ro_commands/helpers/out.rb', line 37

def save_on
  File.write(tmp_path, "save_on at #{Time.now}")
  @save = true
end

.tmpObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/ro_commands/helpers/out.rb', line 57

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_pathObject



52
53
54
55
# File 'lib/ro_commands/helpers/out.rb', line 52

def tmp_path
  FileUtils.touch "/tmp/ro_out"
  @tmp_path ||= "/tmp/ro_out"
end

.write_tmp(ctn) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ro_commands/helpers/out.rb', line 18

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