Class: OkComputer::DirectoryCheck
- Defined in:
- lib/ok_computer/built_in_checks/directory_check.rb
Overview
Check if a file system directory exists and has the correct access. This may prove useful if the application relies on a mounted shared file system.
Constant Summary collapse
- ConnectionFailed =
Class.new(StandardError)
Constants inherited from Check
Instance Attribute Summary collapse
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#writable ⇒ Object
Returns the value of attribute writable.
Attributes inherited from Check
#failure_occurred, #message, #registrant_name, #time
Instance Method Summary collapse
-
#check ⇒ Object
Public: Return the status of the directory check.
-
#initialize(directory, writable = true) ⇒ DirectoryCheck
constructor
Public: Initialize a new directory check.
Methods inherited from Check
#<=>, #clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text, #with_benchmarking
Constructor Details
#initialize(directory, writable = true) ⇒ DirectoryCheck
Public: Initialize a new directory check.
directory - the path of the directory. Can be relative or absolute. writable - true if directory should allow writes; false if not.
13 14 15 16 17 18 |
# File 'lib/ok_computer/built_in_checks/directory_check.rb', line 13 def initialize(directory, writable = true) raise ArgumentError if directory.blank? self.directory = directory self.writable = writable end |
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
7 8 9 |
# File 'lib/ok_computer/built_in_checks/directory_check.rb', line 7 def directory @directory end |
#writable ⇒ Object
Returns the value of attribute writable.
7 8 9 |
# File 'lib/ok_computer/built_in_checks/directory_check.rb', line 7 def writable @writable end |
Instance Method Details
#check ⇒ Object
Public: Return the status of the directory check
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ok_computer/built_in_checks/directory_check.rb', line 21 def check stat = File.stat(directory) if File.exist?(directory) if stat if stat.directory? if !stat.readable? "Directory '#{directory}' is not readable." mark_failure elsif writable && !stat.writable? "Directory '#{directory}' is not writable." mark_failure elsif !writable && stat.writable? "Directory '#{directory}' is writable (undesired)." mark_failure else "Directory '#{directory}' is #{writable ? nil : 'NOT '}writable (as expected)." end else "'#{directory}' is not a directory." mark_failure end else "Directory '#{directory}' does not exist." mark_failure end end |