Module: XcodeTrashRemover::Core

Extended by:
Core
Included in:
Core
Defined in:
lib/xcode_trash_remover/core.rb

Constant Summary collapse

@@xcode_directories =
[
Dir.glob("#{File.expand_path('~')}/Library/Developer/Xcode/DerivedData/*"),
Dir.glob("#{File.expand_path('~')}/Library/Developer/Xcode/Archives/*"),
]

Instance Method Summary collapse

Instance Method Details

#dir_size(dir_path) ⇒ Object

Raises:

  • (RuntimeError)


15
16
17
18
19
20
21
22
23
24
# File 'lib/xcode_trash_remover/core.rb', line 15

def dir_size(dir_path)
  dir_path << '/' unless dir_path.end_with?('/')
  raise RuntimeError, "#{dir_path} is not a directory" unless File.directory?(dir_path)

  total_size = 0
  Dir["#{dir_path}**/*"].each do |f|
    total_size += File.size(f) if File.file?(f) && File.size?(f)
  end
  total_size
end

#get_trash_sizeObject

TODO: function to return best size (MB or GB)



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/xcode_trash_remover/core.rb', line 28

def get_trash_size
  trash_size = 0
  @@xcode_directories.each do |dir|
  if dir.empty?
    next
  end
  dir.each do |folder|
    trash_size += dir_size(folder)
    end
  end
  trash_size
end

#remove_trashObject



41
42
43
44
45
46
47
# File 'lib/xcode_trash_remover/core.rb', line 41

def remove_trash
  @@xcode_directories.each do |dir|
  dir.each do |folder|
    FileUtils.rm_rf(folder.gsub(/ /, '\ '))
    end
  end
end