module MachineConfigure::Helpers::Message

This helper provides useful error methods, which may abort the script with an error message and a stack traceback.

Constants

MESSAGE_PADDING
STACK_TRACE_PADDING
STACK_TRACE_SIZE

Public Class Methods

error_no_stack_trace!() click to toggle source

Disable stack trace output on error method.

# File lib/machine_configure/helpers/message.rb, line 14
def error_no_stack_trace!
  @@_error_stack_trace = false
end
error_yes_stack_trace!() click to toggle source

Enable stack trace output on error method, if it was disabled.

# File lib/machine_configure/helpers/message.rb, line 20
def error_yes_stack_trace!
  @@_error_stack_trace = true
end

Private Instance Methods

_get_message_header() click to toggle source
# File lib/machine_configure/helpers/message.rb, line 72
def _get_message_header
  return DIR[:caller].basename
end
_get_warning_message_from(*messages) click to toggle source
# File lib/machine_configure/helpers/message.rb, line 64
def _get_warning_message_from *messages
  message = messages.flatten.join(?\n).gsub(/^/, MESSAGE_PADDING)
  return [
    "#{_get_message_header} WARNING:",
    message
  ].flatten.join(?\n)
end
error(*messages) click to toggle source
# File lib/machine_configure/helpers/message.rb, line 27
def error *messages  #:doc:
  message = messages.flatten.join(?\n).gsub(/^/, MESSAGE_PADDING)
  output = [
    "#{_get_message_header} ERROR:",
    message,
    "#{MESSAGE_PADDING}Exiting."
  ]
  if (@@_error_stack_trace)
    stack_trace = caller[STACK_TRACE_PADDING ... (STACK_TRACE_SIZE + STACK_TRACE_PADDING)].map do |line|
      next "#{MESSAGE_PADDING}#{line}"
    end .reverse
    output.unshift([
      "Stack traceback (most recent call last):",
      stack_trace,
    ])
  end
  abort output.flatten.join(?\n)
end
message(*messages) click to toggle source
# File lib/machine_configure/helpers/message.rb, line 56
def message *messages  #:doc:
  message = messages.flatten.join(?\n).gsub(/^/, MESSAGE_PADDING)
  puts([
    "#{_get_message_header}",
    message
  ].flatten.join(?\n))
end
warning(*messages) click to toggle source
# File lib/machine_configure/helpers/message.rb, line 46
def warning *messages  #:doc:
  message = _get_warning_message_from(*messages.flatten)
  puts message
end
warning_print(*messages) click to toggle source
# File lib/machine_configure/helpers/message.rb, line 51
def warning_print *messages  #:doc:
  message = _get_warning_message_from(*messages.flatten)
  print message
end