class EacRubyUtils::Fs::ClearableDirectory
Constants
- CLEARABLE_BASENAME
Public Instance Methods
clear()
click to toggle source
# File lib/eac_ruby_utils/fs/clearable_directory.rb, line 11 def clear validate_clearable directory? ? clear_directory : clear_no_directory mkpath ::FileUtils.touch(clearable_note_file.to_path) self end
clearable?()
click to toggle source
# File lib/eac_ruby_utils/fs/clearable_directory.rb, line 19 def clearable? clearable_negate_message ? true : false end
clearable_negate_message()
click to toggle source
# File lib/eac_ruby_utils/fs/clearable_directory.rb, line 23 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
clearable_note_file()
click to toggle source
# File lib/eac_ruby_utils/fs/clearable_directory.rb, line 31 def clearable_note_file join(CLEARABLE_BASENAME) end
validate_clearable()
click to toggle source
# File lib/eac_ruby_utils/fs/clearable_directory.rb, line 35 def validate_clearable message = clearable_negate_message raise message if message end
Private Instance Methods
clear_directory()
click to toggle source
# File lib/eac_ruby_utils/fs/clearable_directory.rb, line 42 def clear_directory children.each do |child| if child.directory? child.rmtree elsif child.file? child.unlink end end end
clear_no_directory()
click to toggle source
# File lib/eac_ruby_utils/fs/clearable_directory.rb, line 52 def clear_no_directory ::FileUtils.rm_rf(to_path) end