Class: Ubalo::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/ubalo/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(tty) ⇒ Logger

Returns a new instance of Logger.



3
4
5
6
# File 'lib/ubalo/logger.rb', line 3

def initialize tty
  @incomplete_line = false
  @tty = tty
end

Instance Method Details

#complete_lineObject



22
23
24
25
# File 'lib/ubalo/logger.rb', line 22

def complete_line
  $stderr.print("\n") if @incomplete_line
  @incomplete_line = false
end

#pollObject

Raises:



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ubalo/logger.rb', line 27

def poll
  600.times do
    if result = yield
      return result
    end
    sleep 0.5
  end

  self.complete_line
  raise Ubalo::Error, "timed-out while waiting"
end

#poll_on(message) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/ubalo/logger.rb', line 39

def poll_on(message)
  self.print message
  result = poll do
    self.print '.'
    yield
  end

  self.puts " done."
  result
end


12
13
14
15
# File 'lib/ubalo/logger.rb', line 12

def print(str)
  @incomplete_line = true
  $stderr.print(str)
end

#puts(str = "") ⇒ Object



17
18
19
20
# File 'lib/ubalo/logger.rb', line 17

def puts(str="")
  @incomplete_line = false
  $stderr.print(str + "\n")
end

#tty?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/ubalo/logger.rb', line 8

def tty?
  @tty
end