class Dust::Message

Attributes

status[R]
text[R]

Public Class Methods

new(msg = '', options = {}) click to toggle source
# File lib/dust/messaging.rb, line 71
def initialize(msg = '', options = {})
  # merge default options
  @options = { :quiet => false, :indent => 1 }.merge options

  # autoflush
  $stdout.sync = true

  # just return if quiet mode is on
  unless @options[:quiet]
    # default status is 'message'
    @status = 'none'

    @text = indent + msg
    print @text unless $parallel
  end
end

Public Instance Methods

failed(msg = '') click to toggle source
# File lib/dust/messaging.rb, line 108
def failed(msg = '')
  unless @options[:quiet]
    @text << msg + ' [ failed ]'.red + "\n"
    puts msg + ' [ failed ]'.red unless $parallel
    @status = 'failed'
  end

  false
end
ok(msg = '') click to toggle source
# File lib/dust/messaging.rb, line 88
def ok(msg = '')
  unless @options[:quiet]
    @text << msg + ' [ ok ]'.green + "\n"
    puts msg + ' [ ok ]'.green unless $parallel
    @status = 'ok'
  end

  true
end
parse_result(ret) click to toggle source
# File lib/dust/messaging.rb, line 118
def parse_result(ret)
  return ok if ret == 0 or ret.is_a? TrueClass
  failed
end
print_output(ret) click to toggle source

prints stdout in grey and stderr in red (if existend)

warning(msg = '') click to toggle source
# File lib/dust/messaging.rb, line 98
def warning(msg = '')
  unless @options[:quiet]
    @text << msg + ' [ warning ]'.yellow + "\n"
    puts msg + ' [ warning ]'.yellow unless $parallel
    @status = 'warning'
  end

  true
end

Private Instance Methods

indent() click to toggle source

indent according to @options indent 0

- indent 1
  - indent 2
# File lib/dust/messaging.rb, line 138
def indent
  return '' if @options[:quiet] or @options[:indent] == 0
  ' ' + '  ' * (@options[:indent] - 1) + '- '
end