Class: FileCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/file_creator.rb

Overview

Responsible for creating a file and creating error messages which we can present back to the user if it failed

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



4
5
6
# File 'lib/file_creator.rb', line 4

def error
  @error
end

Instance Method Details

#create(file_name) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/file_creator.rb', line 5

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