vagrant-cachier-ng/lib/vagrant-cachier/bucket/gem.rb

38 lines
1.1 KiB
Ruby

module VagrantPlugins
module Cachier
class Bucket
class Gem < Bucket
def self.capability
:gemdir
end
def install
machine = @env[:machine]
guest = machine.guest
if guest.capability?(:gemdir)
if gemdir_path = guest.capability(:gemdir)
prefix = gemdir_path.split('/').last
bucket_path = "/tmp/vagrant-cache/#{@name}/#{prefix}"
machine.communicate.tap do |comm|
comm.execute("mkdir -p #{bucket_path}")
gem_cache_path = "#{gemdir_path}/cache"
@env[:cache_dirs] << gem_cache_path
unless comm.test("test -L #{gem_cache_path}")
comm.sudo("rm -rf #{gem_cache_path}")
comm.sudo("mkdir -p `dirname #{gem_cache_path}`")
comm.sudo("ln -s #{bucket_path} #{gem_cache_path}")
end
end
end
else
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'RubyGems')
end
end
end
end
end
end