Module: FunWith::Files::FileRequirements
- Defined in:
- lib/fun_with/files/file_requirements.rb
Instance Method Summary collapse
- #needs_to_be(*requirements) ⇒ Object
- #needs_to_be_a_directory(error_msg = "Path is not a directory") ⇒ Object
- #needs_to_be_a_file(error_msg = "Path is not a file") ⇒ Object
-
#needs_to_be_empty(error_msg = "Path needs to be empty") ⇒ Object
returns a different code depending on whether the path is a file or a directory.
- #needs_to_be_executable(error_msg = "Path is not executable") ⇒ Object
- #needs_to_be_readable(error_msg = "Path is not readable") ⇒ Object
- #needs_to_be_writable(error_msg = "Path is not writable") ⇒ Object
- #needs_to_exist(error_msg = "Path does not exist") ⇒ Object
Instance Method Details
#needs_to_be(*requirements) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fun_with/files/file_requirements.rb', line 44 def needs_to_be( *requirements ) for requirement in requirements case requirement when :exist self.needs_to_exist when :readable self.needs_to_be_readable when :writable self.needs_to_be_writable when :executable self.needs_to_be_executable when :empty self.needs_to_be_empty when :directory self.needs_to_be_a_directory when :file self.needs_to_be_a_file else warn "Did not understand file.needs_to_be constraint: #{arg}" end end end |
#needs_to_be_a_directory(error_msg = "Path is not a directory") ⇒ Object
39 40 41 42 |
# File 'lib/fun_with/files/file_requirements.rb', line 39 def needs_to_be_a_directory error_msg = "Path is not a directory" self.needs_to_exist( error_msg + " (does not exist)" ) _raise_error_if_not self.directory?, error_msg, Errno::ENOTDIR end |
#needs_to_be_a_file(error_msg = "Path is not a file") ⇒ Object
8 9 10 11 |
# File 'lib/fun_with/files/file_requirements.rb', line 8 def needs_to_be_a_file error_msg = "Path is not a file" self.needs_to_exist( error_msg + " (does not exist)" ) _raise_error_if_not self.file?, error_msg, Errno::ENOENT end |
#needs_to_be_empty(error_msg = "Path needs to be empty") ⇒ Object
returns a different code depending on whether the path is a file or a directory.
30 31 32 33 34 35 36 37 |
# File 'lib/fun_with/files/file_requirements.rb', line 30 def needs_to_be_empty error_msg = "Path needs to be empty" self.needs_to_exist( error_msg + " (does not exist)" ) error_class = Errno::EOWNERDEAD # it's as good a code as any error_class = Errno::ENOTEMPTY if self.directory? error_class = Errors::FileNotEmpty if self.file? # there's no libc error for "file oughta be empty" _raise_error_if_not self.empty?, error_msg, error_class end |
#needs_to_be_executable(error_msg = "Path is not executable") ⇒ Object
23 24 25 26 |
# File 'lib/fun_with/files/file_requirements.rb', line 23 def needs_to_be_executable error_msg = "Path is not executable" self.needs_to_exist( error_msg + " (does not exist)" ) _raise_error_if_not self.executable?, error_msg, Errno::ENOEXEC end |
#needs_to_be_readable(error_msg = "Path is not readable") ⇒ Object
13 14 15 16 |
# File 'lib/fun_with/files/file_requirements.rb', line 13 def needs_to_be_readable error_msg = "Path is not readable" self.needs_to_exist( error_msg + " (does not exist)" ) _raise_error_if_not self.writable?, error_msg, Errno::EPERM end |
#needs_to_be_writable(error_msg = "Path is not writable") ⇒ Object
18 19 20 21 |
# File 'lib/fun_with/files/file_requirements.rb', line 18 def needs_to_be_writable error_msg = "Path is not writable" self.needs_to_exist( error_msg + " (does not exist)" ) _raise_error_if_not self.writable?, error_msg, Errno::EPERM end |
#needs_to_exist(error_msg = "Path does not exist") ⇒ Object
4 5 6 |
# File 'lib/fun_with/files/file_requirements.rb', line 4 def needs_to_exist error_msg = "Path does not exist" _raise_error_if_not self.exist?, error_msg, Errno::ENOENT end |