Class: Megam::Dumpout

Inherits:
Object
  • Object
show all
Defined in:
lib/megam/scmmanager/dumpout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout, stderr, stdin) ⇒ Dumpout

Returns a new instance of Dumpout.



8
9
10
# File 'lib/megam/scmmanager/dumpout.rb', line 8

def initialize(stdout, stderr, stdin)
  @stdout, @stderr, @stdin = stdout, stderr, stdin
end

Instance Attribute Details

#stderrObject (readonly)

Returns the value of attribute stderr.



5
6
7
# File 'lib/megam/scmmanager/dumpout.rb', line 5

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



6
7
8
# File 'lib/megam/scmmanager/dumpout.rb', line 6

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



4
5
6
# File 'lib/megam/scmmanager/dumpout.rb', line 4

def stdout
  @stdout
end

Instance Method Details

#color(string, *colors) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/megam/scmmanager/dumpout.rb', line 51

def color(string, *colors)
  if color?
    highline.color(string, *colors)
  else
  string
  end
end

#color?Boolean

Should colored output be used ?. When output is not to a terminal, colored output is never used

Returns:

  • (Boolean)


61
62
63
# File 'lib/megam/scmmanager/dumpout.rb', line 61

def color?
  stdout.tty?
end

#err(message) ⇒ Object

Prints a msg to stderr. Used for warn, error, and fatal.



32
33
34
# File 'lib/megam/scmmanager/dumpout.rb', line 32

def err(message)
  stderr.puts message
end

#error(message) ⇒ Object

Print an error message



42
43
44
# File 'lib/megam/scmmanager/dumpout.rb', line 42

def error(message)
  err("#{color('ERROR:', :red, :bold)} #{message}")
end

#fatal(message) ⇒ Object

Print a message describing a fatal error.



47
48
49
# File 'lib/megam/scmmanager/dumpout.rb', line 47

def fatal(message)
  err("#{color('FATAL:', :red, :bold)} #{message}")
end

#highlineObject



12
13
14
15
16
17
# File 'lib/megam/scmmanager/dumpout.rb', line 12

def highline
  @highline ||= begin
  require 'highline'
  HighLine.new
  end
end

#info(message) ⇒ Object

Prints a message to stdout. Aliased as info for compatibility with the logger API.



27
28
29
# File 'lib/megam/scmmanager/dumpout.rb', line 27

def info(message)
  stdout.puts("#{color('INFO:', :green, :bold)} #{message}")
end

#list(*args) ⇒ Object



65
66
67
# File 'lib/megam/scmmanager/dumpout.rb', line 65

def list(*args)
  highline.list(*args)
end

#msg(message) ⇒ Object



20
21
22
# File 'lib/megam/scmmanager/dumpout.rb', line 20

def msg(message)
  stdout.puts message
end

#pretty_print(data) ⇒ Object



69
70
71
# File 'lib/megam/scmmanager/dumpout.rb', line 69

def pretty_print(data)
  stdout.puts data
end

#warn(message) ⇒ Object

Print a warning message



37
38
39
# File 'lib/megam/scmmanager/dumpout.rb', line 37

def warn(message)
  err("#{color('WARNING:', :yellow, :bold)} #{message}")
end