Module: AdventureRL::Helpers::Error
- Included in:
- FileGroup, FileGroupPlayer, Image, Layer, Rectangle, Settings, TimingHandler
- Defined in:
- lib/AdventureRL/Helpers/Error.rb
Constant Summary collapse
- PADDING =
' '- STACK_TRACE_SIZE =
20- STACK_TRACE_PADDING =
1
Class Method Summary collapse
- .directory_exists?(directory) ⇒ Boolean
- .error(*messages) ⇒ Object
- .error_no_directory(directory) ⇒ Object
- .error_no_file(file) ⇒ Object
- .file_exists?(file) ⇒ Boolean
Class Method Details
.directory_exists?(directory) ⇒ Boolean
40 41 42 43 |
# File 'lib/AdventureRL/Helpers/Error.rb', line 40 def self.directory_exists? directory return false unless (directory) return File.directory? directory end |
.error(*messages) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/AdventureRL/Helpers/Error.rb', line 8 def self.error * = .join ?\n .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:", , "#{PADDING}Exiting.", "Stack traceback (most recent call last):", stack_trace_lines ].flatten.join(?\n)) end |
.error_no_directory(directory) ⇒ Object
29 30 31 32 33 |
# 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) ⇒ Object
23 24 25 26 27 |
# 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) ⇒ Boolean
35 36 37 38 |
# File 'lib/AdventureRL/Helpers/Error.rb', line 35 def self.file_exists? file return false unless (file) return File.file? file end |