vagrant-cachier-ng/lib/vagrant-cachier/bucket.rb
Fabio Rehm 437ba6a4cf ⚠️ Massive refactoring of buckets code ⚠️
Doing this is kinda irresponsible because we don't have any unit testing
in place but I've had enough of copy & pasting things around. Although it
doesn't make the codebase GREAT, I believe it'll reach a _nice_ status :)

Thanks to those changes I realized that skipping configuration of
buckets that have already been configured was easier than I thought and
should be enough to close GH-85 \o/
2014-02-26 22:03:22 -03:00

84 lines
2.3 KiB
Ruby

module VagrantPlugins
module Cachier
class Bucket
def self.inherited(base)
@buckets ||= []
@buckets << base
end
def self.auto_detect(env)
@buckets.each do |bucket|
if env[:machine].guest.capability?(bucket.capability)
env[:machine].config.cache.enable bucket.bucket_name
end
end
end
def self.bucket_name
class_name = self.name.split('::').last
class_name.scan(/[A-Z][a-z]*/).map{|x| x.downcase}.join("_")
end
def self.install(name, env, configs)
bucket = const_get(name.to_s.split("_").map{|x| x.capitalize}.join(""))
bucket.new(name, env, configs).install
end
def initialize(name, env, configs)
@name = name
@env = env
@configs = configs
end
def machine
@env[:machine]
end
def guest
machine.guest
end
def comm
machine.communicate
end
def symlink(guest_path, bucket_path = "/tmp/vagrant-cache/#{@name}", create_parent: true)
return if @env[:cache_dirs].include?(guest_path)
@env[:cache_dirs] << guest_path
comm.execute("mkdir -p #{bucket_path}")
unless comm.test("test -L #{guest_path}")
comm.sudo("rm -rf #{guest_path}")
comm.sudo("mkdir -p `dirname #{guest_path}`") if create_parent
comm.sudo("ln -s #{bucket_path} #{guest_path}")
end
end
def user_symlink(guest_path)
return if @env[:cache_dirs].include?(guest_path)
@env[:cache_dirs] << guest_path
bucket_path = "/tmp/vagrant-cache/#{@name}"
comm.execute("mkdir -p #{bucket_path}")
unless comm.test("test -L #{guest_path}")
comm.execute("rm -rf #{guest_path}")
comm.execute("mkdir -p `dirname #{guest_path}`") if create_parent
comm.execute("ln -s #{bucket_path} #{guest_path}")
end
end
end
end
end
require_relative "bucket/apt"
require_relative "bucket/chef"
require_relative "bucket/gem"
require_relative "bucket/pacman"
require_relative "bucket/yum"
require_relative "bucket/rvm"
require_relative "bucket/apt_cacher"
require_relative "bucket/apt_lists"
require_relative "bucket/composer"
require_relative "bucket/npm"
require_relative "bucket/zypper"