module AdventureRL::Helpers::Error

Constants

PADDING
STACK_TRACE_PADDING
STACK_TRACE_SIZE

Public Class Methods

directory_exists?(directory) click to toggle source
# File lib/AdventureRL/Helpers/Error.rb, line 40
def self.directory_exists? directory
  return false  unless (directory)
  return File.directory? directory
end
error(*messages) click to toggle source
# File lib/AdventureRL/Helpers/Error.rb, line 8
def self.error *messages
  message = messages.join ?\n
  message.gsub! /^/, PADDING
  stack_trace_lines = caller[STACK_TRACE_PADDING ... (STACK_TRACE_SIZE + STACK_TRACE_PADDING)].map do |line|
    next "#{PADDING}#{line}"
  end .reverse
  abort([
    "#{DIR[:entry].to_s} Error:",
    message,
    "#{PADDING}Exiting.",
    "Stack traceback (most recent call last):",
    stack_trace_lines
  ].flatten.join(?\n))
end
error_no_directory(directory) click to toggle source
# File lib/AdventureRL/Helpers/Error.rb, line 29
def self.error_no_directory directory
  dirpath = directory
  dirpath = directory.to_path  if (directory.is_a? Pathname)
  error "Directory does not exist, or is a file:", "  '#{dirpath}'"
end
error_no_file(file) click to toggle source
# File lib/AdventureRL/Helpers/Error.rb, line 23
def self.error_no_file file
  filepath = file
  filepath = file.to_path  if (file.is_a? Pathname)
  error "File does not exist, or is a directory:", "  '#{filepath}'"
end
file_exists?(file) click to toggle source
# File lib/AdventureRL/Helpers/Error.rb, line 35
def self.file_exists? file
  return false  unless (file)
  return File.file? file
end

Private Instance Methods

directory_exists?(directory) click to toggle source
# File lib/AdventureRL/Helpers/Error.rb, line 63
def directory_exists? directory
  return AdventureRL::Helpers::Error.directory_exists? directory
end
error(*messages) click to toggle source
# File lib/AdventureRL/Helpers/Error.rb, line 47
def error *messages
  AdventureRL::Helpers::Error.error *messages
end
error_no_directory(directory) click to toggle source
# File lib/AdventureRL/Helpers/Error.rb, line 55
def error_no_directory directory
  AdventureRL::Helpers::Error.error_no_directory directory
end
error_no_file(file) click to toggle source
# File lib/AdventureRL/Helpers/Error.rb, line 51
def error_no_file file
  AdventureRL::Helpers::Error.error_no_file file
end
file_exists?(file) click to toggle source
# File lib/AdventureRL/Helpers/Error.rb, line 59
def file_exists? file
  return AdventureRL::Helpers::Error.file_exists? file
end