Class: BuildOutput
Constant Summary collapse
- NOTE =
0
- WARNING =
1
- ERROR =
2
- FATAL =
3
- MESSAGES =
['NOTE', 'WARNING', 'ERROR', 'FATAL']
- LEVELS =
[NOTE, WARNING, ERROR, FATAL]
- @@mqueue =
[]
Class Method Summary collapse
- .col_message(level, message) ⇒ Object
- .decorate_message(message, title) ⇒ Object
- .error(message, title = nil) ⇒ Object
- .fatal(message, title = nil) ⇒ Object
- .getLogText ⇒ Object
- .log(level, message, title) ⇒ Object
- .merge_head_tail(src, msg) ⇒ Object
- .note(message, title = nil) ⇒ Object
- .prepare_message(message) ⇒ Object
- .put_log(level, message, title = nil) ⇒ Object
- .to_merge(s1, s2) ⇒ Object
- .warning(message, title = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ BuildOutput
constructor
A new instance of BuildOutput.
Constructor Details
#initialize ⇒ BuildOutput
Returns a new instance of BuildOutput.
22 23 |
# File 'lib/build/BuildOutput.rb', line 22 def initialize() end |
Class Method Details
.col_message(level, message) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/build/BuildOutput.rb', line 51 def (level, ) out = case level when FATAL .bold.red when ERROR .red when WARNING .cyan when NOTE .blue end out end |
.decorate_message(message, title) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/build/BuildOutput.rb', line 39 def ( , title ) = [] << ' **** ' + title + '*' * (105 - title.length) .concat( ().map{|el| ' ' * 3 + el }) << ' ' + '*' * (110) end |
.error(message, title = nil) ⇒ Object
154 155 156 |
# File 'lib/build/BuildOutput.rb', line 154 def error(, title = nil) log(ERROR, , title) end |
.fatal(message, title = nil) ⇒ Object
158 159 160 |
# File 'lib/build/BuildOutput.rb', line 158 def fatal(, title = nil) log(ERROR, , title) end |
.getLogText ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/build/BuildOutput.rb', line 162 def getLogText txt = [] @@mqueue.sort_by { |hsh| hsh[:level] } @@mqueue.each do || out = ( [:content], [:title] ).join($/) col = ([:level], out) [:output] = out [:color] = col txt << col end txt << '' unless txt.empty? txt.join($/) end |
.log(level, message, title) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/build/BuildOutput.rb', line 113 def log(level, , title) if !LEVELS.include?(level) return end title = MESSAGES[level] + (title.nil? ? " " : (": " + title + " ")) = { :level => level, :title => title, :content => () } last = @@mqueue.last if !last.nil? && (last[:level] == level) && (last[:title] == title) last[:content] = merge_head_tail(last[:content], [:content]) else @@mqueue << end end |
.merge_head_tail(src, msg) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/build/BuildOutput.rb', line 80 def merge_head_tail(src, msg) begining = [] ending = [] result = [] # find same headers b_len = to_merge(src.each, msg.each) if (b_len > 0) begining.concat(src.take(b_len)) src = src.drop(b_len) msg = msg.drop(b_len) end # find same footers e_len = to_merge(src.reverse_each, msg.reverse_each) if (e_len > 0) ending = src.drop(src.length - e_len) src = src.take(src.length - e_len) msg = msg.take(msg.length - e_len) end # special case about joining lines if src.length == 1 && msg.length == 1 if msg.first.length > src.first.length && msg.first.start_with?(src.first) # warning(["Build message '#{msg} appended from ", " * " + caller.join($/ + " ^ "),'instead of being added to error string'], 'Error in build script') src = [] end end begining.concat(src).concat(msg).concat(ending) end |
.note(message, title = nil) ⇒ Object
146 147 148 |
# File 'lib/build/BuildOutput.rb', line 146 def note(, title = nil) log(NOTE, , title) end |
.prepare_message(message) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/build/BuildOutput.rb', line 26 def () if .kind_of?(Array) out = [] .flatten(1).each do |line| out.concat( line.split($/) ) end else out = .split($/) end out end |
.put_log(level, message, title = nil) ⇒ Object
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/build/BuildOutput.rb', line 135 def put_log(level, , title = nil) if !LEVELS.include?(level) return end msg = (, MESSAGES[level] + (title.nil? ? " " : (": " + title + " "))) col = (level, msg.join($/)) puts col end |
.to_merge(s1, s2) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/build/BuildOutput.rb', line 66 def to_merge(s1, s2) i = 0 loop do e1 = s1.next rescue :eof e2 = s2.next rescue :eof if e1 == :eof || e2 == :eof || e1 != e2 break else i += 1 end end return i end |