module ChaosDetector::Utils::FSUtil
Public Class Methods
ensure_dirpath(dirpath)
click to toggle source
Ensure directory and all its parents exist, like (mkdir -p):
# File lib/chaos_detector/utils/fs_util.rb, line 18 def ensure_dirpath(dirpath) raise ArgumentError, '#ensure_paths_to_file requires dirpath' if nay? dirpath FileUtils.mkdir_p(dirpath) end
ensure_paths_to_file(filepath)
click to toggle source
Ensure file's directory and all its parents exist, like (mkdir -p):
# File lib/chaos_detector/utils/fs_util.rb, line 34 def ensure_paths_to_file(filepath) raise ArgumentError, '#ensure_paths_to_file requires filepath' if nay? filepath dirpath = File.split(filepath).first raise "dirpath couldn't be obtained from #{filepath}" if nay? dirpath ensure_dirpath(dirpath) end
nay?(obj)
click to toggle source
# File lib/chaos_detector/utils/fs_util.rb, line 43 def nay?(obj) ChaosDetector::Utils::CoreUtil.naught?(obj) end
rel_path(dir_path, from_path:)
click to toggle source
Relative path:
# File lib/chaos_detector/utils/fs_util.rb, line 11 def rel_path(dir_path, from_path:) pathname = Pathname.new(dir_path) base_path = Pathname.new(from_path).cleanpath pathname.relative_path_from(base_path).to_s end
safe_file_write(filepath, content: nil)
click to toggle source
Ensure file's directory and all its parents exist, then write given string to it:
# File lib/chaos_detector/utils/fs_util.rb, line 25 def safe_file_write(filepath, content: nil) raise ArgumentError, '#write_to_file requires filepath' if nay? filepath ensure_paths_to_file(filepath) File.write(filepath, content) filepath end