Class: Zeusd::Log::Status
- Inherits:
-
Object
- Object
- Zeusd::Log::Status
- Defined in:
- lib/zeusd/log/status.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line_print_count ⇒ Object
readonly
Returns the value of attribute line_print_count.
-
#processes ⇒ Object
readonly
Returns the value of attribute processes.
-
#tailer ⇒ Object
readonly
Returns the value of attribute tailer.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #finished? ⇒ Boolean
-
#initialize(file) ⇒ Status
constructor
A new instance of Status.
- #on_update(&block) ⇒ Object
- #pause! ⇒ Object
- #paused? ⇒ Boolean
- #process(line) ⇒ Object
- #record! ⇒ Object
- #recording? ⇒ Boolean
- #started? ⇒ Boolean
- #to_cli ⇒ Object
Constructor Details
#initialize(file) ⇒ Status
Returns a new instance of Status.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/zeusd/log/status.rb', line 11 def initialize(file) @line_print_count = 0 @file = File.new(file) @updated_at = Time.now @errors = LastLineArray.new @commands = LastLineArray.new @processes = LastLineArray.new @tailer = Tailer.new(file) file.each {|line| process(line)} unless file.size.zero? end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
8 9 10 |
# File 'lib/zeusd/log/status.rb', line 8 def commands @commands end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/zeusd/log/status.rb', line 7 def errors @errors end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/zeusd/log/status.rb', line 6 def file @file end |
#line_print_count ⇒ Object (readonly)
Returns the value of attribute line_print_count.
6 7 8 |
# File 'lib/zeusd/log/status.rb', line 6 def line_print_count @line_print_count end |
#processes ⇒ Object (readonly)
Returns the value of attribute processes.
9 10 11 |
# File 'lib/zeusd/log/status.rb', line 9 def processes @processes end |
#tailer ⇒ Object (readonly)
Returns the value of attribute tailer.
6 7 8 |
# File 'lib/zeusd/log/status.rb', line 6 def tailer @tailer end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
6 7 8 |
# File 'lib/zeusd/log/status.rb', line 6 def updated_at @updated_at end |
Instance Method Details
#empty? ⇒ Boolean
68 69 70 |
# File 'lib/zeusd/log/status.rb', line 68 def empty? [errors, commands, processes].all?(&:empty?) end |
#finished? ⇒ Boolean
62 63 64 65 66 |
# File 'lib/zeusd/log/status.rb', line 62 def finished? return true if errors.any? return true if [commands, processes].map(&:to_a).flatten.all?(&:done?) false end |
#on_update(&block) ⇒ Object
53 54 55 56 |
# File 'lib/zeusd/log/status.rb', line 53 def on_update(&block) @on_update = block if block_given? @on_update end |
#pause! ⇒ Object
29 30 31 32 |
# File 'lib/zeusd/log/status.rb', line 29 def pause! tailer.stop! self end |
#paused? ⇒ Boolean
34 35 36 |
# File 'lib/zeusd/log/status.rb', line 34 def paused? !tailer.following? end |
#process(line) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/zeusd/log/status.rb', line 42 def process(line) line = Line.create(line) case line when Line::Command then @commands << line when Line::Process then @processes << line when Line::Error then @errors << line end @updated_at = Time.now on_update.call(self, line) if on_update end |
#record! ⇒ Object
23 24 25 26 27 |
# File 'lib/zeusd/log/status.rb', line 23 def record! tailer.on_update {|line| process(line)} tailer.start! self end |
#recording? ⇒ Boolean
38 39 40 |
# File 'lib/zeusd/log/status.rb', line 38 def recording? tailer.following? end |
#started? ⇒ Boolean
58 59 60 |
# File 'lib/zeusd/log/status.rb', line 58 def started? commands.any? end |
#to_cli ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/zeusd/log/status.rb', line 72 def to_cli output = [ "\e[36mZeusd Status\e[0m - Updated: #{updated_at.to_s}\e[K\e[0m\n", "\e[K\e[0m\n", "Legend: \e[32m[ready] \e[31m[crashed] \e[34m[running] \e[35m[connecting] \e[33m[waiting]\e[K\e[0m\n", "\e[K\e[0m\n", "\e[4mProcess Tree\e[K\e[0m\n", [processes.map(&:to_s)], "\e[K\e[0m\n", "\e[4mCommands\e[K\e[0m\n", [commands.map(&:to_s)], ].tap do |x| if errors.any? x << "\e[K" x << "\e[4mErrors\e[K\e[0m\n" x << errors.map(&:to_s) end end.flatten if line_print_count > 0 output = output.unshift("\e[#{line_print_count}A\e[K\e[0m\n") end @line_print_count = output.length output end |