Module: File_Checking
- Included in:
- ConfDialog, Configuration, EmlFile
- Defined in:
- lib/file_checking.rb
Overview
A module to facilitate frequently occuring checks on file-system objects
Constant Summary collapse
- @@text_messages =
{ :exist? => "does not exist!", :exist => "does not exist!", :readable? => "is not readable!", :readable => "is not readable!", :executable? => "is not executable!", :executable => "is not executable!", :writable? => "is not writable!", :writable => "is not writable!", :directory? => "is not a directory!", :directory => "is not a directory!", :file? => "is not a file!", :file => "is not a file!", }
Class Method Summary collapse
-
.file_check(file, *messages) ⇒ Object
Checks if the file with the name from the first parameter has the properties, listed in the second.
Instance Method Summary collapse
-
#file_check(file, *messages) ⇒ Object
Checks if the file with the name from the first parameter has the properties, listed in the second.
Class Method Details
.file_check(file, *messages) ⇒ Object
Checks if the file with the name from the first parameter has the properties, listed in the second. The messages parameter is an array of one or all of :exist?, :readable?, :writable?, :directory? or their string-representations, respectively. Returns nil in case of success, otherwise an informative message, describing the first negative test-result.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/file_checking.rb', line 59 def self.file_check(file, *) msg = nil if(file && .respond_to?(:to_ary) && !.empty?) .each do |k| if(! k.to_s.end_with?('?')) k = (k.to_s << '?').to_sym end @log.debug ('checking ' << k.to_s) if @log if(msg == nil && File.respond_to?(k) && ! File.send(k, file.to_s)) msg = "#{file} #{@@text_messages[k.to_sym]}" end end end msg end |
Instance Method Details
#file_check(file, *messages) ⇒ Object
Checks if the file with the name from the first parameter has the properties, listed in the second. The messages parameter is an array of one or several of :exist?, :readable?, :writable?, :directory? or their string-representations, respectively. Returns nil in case of success, otherwise an informative message, describing the first negative test-result.
47 48 49 |
# File 'lib/file_checking.rb', line 47 def file_check(file, *) File_Checking.file_check(file, *) end |