Sha256: 688eb67990ffdfb8e48eb4fb2697849ca2028e3e31d69472eabc23c55b535c5c
Contents?: true
Size: 1.26 KB
Versions: 308
Compression:
Stored size: 1.26 KB
Contents
# frozen_string_literal: true require 'fileutils' require 'pathname' module EacRubyUtils module Fs class ClearableDirectory < ::Pathname CLEARABLE_BASENAME = '.clearable_directory' def clear validate_clearable directory? ? clear_directory : clear_no_directory mkpath ::FileUtils.touch(clearable_note_file.to_path) self end def clearable? clearable_negate_message ? true : false end def clearable_negate_message return if !exist? || empty? return "Path \"#{self}\" exists, is not empty and is not a directory" unless directory? return if clearable_note_file.exist? "Directory \"#{self}\" is not empty and does not have a #{CLEARABLE_BASENAME} file" end def clearable_note_file join(CLEARABLE_BASENAME) end def validate_clearable message = clearable_negate_message raise message if message end private def clear_directory children.each do |child| if child.directory? child.rmtree elsif child.file? child.unlink end end end def clear_no_directory ::FileUtils.rm_rf(to_path) end end end end
Version data entries
308 entries across 308 versions & 4 rubygems