Class: VagrantPlugins::Cachier::Bucket::Gem

Inherits:
VagrantPlugins::Cachier::Bucket show all
Defined in:
lib/vagrant-cachier/bucket/gem.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VagrantPlugins::Cachier::Bucket

auto_detect, bucket_name, inherited, #initialize, install

Constructor Details

This class inherits a constructor from VagrantPlugins::Cachier::Bucket

Class Method Details

.capabilityObject



5
6
7
# File 'lib/vagrant-cachier/bucket/gem.rb', line 5

def self.capability
  :gemdir
end

Instance Method Details

#installObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vagrant-cachier/bucket/gem.rb', line 9

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