vagrant-cachier-ng/lib/vagrant-cachier/action/install_buckets.rb

41 lines
1.1 KiB
Ruby
Raw Normal View History

require_relative '../bucket'
module VagrantPlugins
module Cachier
class Action
class InstallBuckets
def initialize(app, env)
2014-02-01 20:13:42 +00:00
@app = app
@logger = Log4r::Logger.new("vagrant::cachier::action::clean")
end
def call(env)
@app.call(env)
2014-02-01 20:12:38 +00:00
configure_cache_buckets(env)
end
2014-02-01 22:17:01 +00:00
def configure_cache_buckets(env)
2014-02-01 20:12:38 +00:00
return unless env[:machine].config.cache.enabled?
2014-02-01 20:12:38 +00:00
if env[:machine].config.cache.auto_detect
Bucket.auto_detect(env)
end
2014-02-01 20:12:38 +00:00
return unless env[:machine].config.cache.buckets.any?
2014-02-01 20:12:38 +00:00
env[:ui].info 'Configuring cache buckets...'
cache_config = env[:machine].config.cache
cache_config.buckets.each do |bucket_name, configs|
2014-02-01 20:13:42 +00:00
@logger.info "Installing #{bucket_name} with configs #{configs.inspect}"
2014-02-01 20:12:38 +00:00
Bucket.install(bucket_name, env, configs)
end
2014-02-01 20:12:38 +00:00
data_file = env[:machine].data_dir.join('cache_dirs')
data_file.open('w') { |f| f.print env[:cache_dirs].uniq.join("\n") }
end
end
end
end
end