# Responsible for creating a file and creating error messages which we can present back to the user if it failed class FileCreator class Error < StandardError; end attr_reader :error def create(file_name) File.new(file_name, 'w') rescue Errno::EACCES raise Error, "You do not have permission to write to that location (#{file_name})" rescue Errno::EISDIR raise Error, "File name is a directory (#{file_name})" rescue Errno::ENOTDIR raise Error, "File name refers to a directory which does not exist (#{file_name})" end # Errno errors handle error numbers returned by the operating system and translate them into rubyish errors # Therefore there may be slightly different errors on different operating systems, # but hopefully the ones we care about are generally applicable: http://ruby-doc.org/core/Errno.html end