Class: EacRubyUtils::Fs::ClearableDirectory

Inherits:
Pathname show all
Defined in:
lib/eac_ruby_utils/fs/clearable_directory.rb

Constant Summary collapse

CLEARABLE_BASENAME =
'.clearable_directory'

Instance Method Summary collapse

Methods inherited from Pathname

#assert_parent, #basename_noext, #basename_sub, #child_of?, #if_exist, #mkpath_s, #parent_n, #readlink_r, #reqdir_glob

Instance Method Details

#clearObject



11
12
13
14
15
16
17
# 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?Boolean

Returns:



19
20
21
# File 'lib/eac_ruby_utils/fs/clearable_directory.rb', line 19

def clearable?
  clearable_negate_message ? true : false
end

#clearable_negate_messageObject



23
24
25
26
27
28
29
# 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_fileObject



31
32
33
# File 'lib/eac_ruby_utils/fs/clearable_directory.rb', line 31

def clearable_note_file
  join(CLEARABLE_BASENAME)
end

#validate_clearableObject



35
36
37
38
# File 'lib/eac_ruby_utils/fs/clearable_directory.rb', line 35

def validate_clearable
  message = clearable_negate_message
  raise message if message
end