diff options
| author | Markus Reiter | 2016-09-24 13:52:43 +0200 |
|---|---|---|
| committer | Markus Reiter | 2016-09-24 16:00:58 +0200 |
| commit | b86c8efb79b3ed835d552c4d7416640ef10caf21 (patch) | |
| tree | 7e1edc8a8f339e4d2781f43576d40c9c79aebcdc /Library/Homebrew/cask/lib/hbc/cache.rb | |
| parent | 687f0fcf721c8e36f32570ed72d0988a6eaf986f (diff) | |
| download | brew-b86c8efb79b3ed835d552c4d7416640ef10caf21.tar.bz2 | |
Cask: Use nested classes and modules.
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc/cache.rb')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cache.rb | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cache.rb b/Library/Homebrew/cask/lib/hbc/cache.rb index 7ae5fcc8c..db3ec536b 100644 --- a/Library/Homebrew/cask/lib/hbc/cache.rb +++ b/Library/Homebrew/cask/lib/hbc/cache.rb @@ -1,34 +1,36 @@ -module Hbc::Cache - module_function +module Hbc + module Cache + module_function - def ensure_cache_exists - return if Hbc.cache.exist? + def ensure_cache_exists + return if Hbc.cache.exist? - odebug "Creating Cache at #{Hbc.cache}" - Hbc.cache.mkpath - end + odebug "Creating Cache at #{Hbc.cache}" + Hbc.cache.mkpath + end - def migrate_legacy_cache - return unless Hbc.legacy_cache.exist? + def migrate_legacy_cache + return unless Hbc.legacy_cache.exist? - ohai "Migrating cached files to #{Hbc.cache}..." - Hbc.legacy_cache.children.select(&:symlink?).each do |symlink| - file = symlink.readlink + ohai "Migrating cached files to #{Hbc.cache}..." + Hbc.legacy_cache.children.select(&:symlink?).each do |symlink| + file = symlink.readlink - new_name = file.basename - .sub(%r{\-((?:(\d|#{Hbc::DSL::Version::DIVIDER_REGEX})*\-\2*)*[^\-]+)$}x, - '--\1') + new_name = file.basename + .sub(%r{\-((?:(\d|#{DSL::Version::DIVIDER_REGEX})*\-\2*)*[^\-]+)$}x, + '--\1') - renamed_file = Hbc.cache.join(new_name) + renamed_file = Hbc.cache.join(new_name) - if file.exist? - puts "#{file} -> #{renamed_file}" - FileUtils.mv(file, renamed_file) + if file.exist? + puts "#{file} -> #{renamed_file}" + FileUtils.mv(file, renamed_file) + end + + FileUtils.rm(symlink) end - FileUtils.rm(symlink) + FileUtils.remove_entry_secure(Hbc.legacy_cache) end - - FileUtils.remove_entry_secure(Hbc.legacy_cache) end end |
