2013-06-08 02:37:02 +00:00
|
|
|
module VagrantPlugins
|
2013-05-22 22:38:26 +00:00
|
|
|
module Cachier
|
|
|
|
class Config < Vagrant.plugin(2, :config)
|
2014-01-25 04:20:39 +00:00
|
|
|
attr_accessor :scope, :auto_detect, :enable_nfs, :sync_opts
|
2013-05-22 22:38:26 +00:00
|
|
|
attr_reader :buckets
|
|
|
|
|
2013-08-03 17:51:31 +00:00
|
|
|
ALLOWED_SCOPES = %w( box machine )
|
|
|
|
|
2013-05-22 22:38:26 +00:00
|
|
|
def initialize
|
|
|
|
@scope = UNSET_VALUE
|
|
|
|
@auto_detect = UNSET_VALUE
|
2013-06-11 23:16:06 +00:00
|
|
|
@enable_nfs = UNSET_VALUE
|
2014-01-25 04:20:39 +00:00
|
|
|
@sync_opts = UNSET_VALUE
|
2013-05-22 22:38:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def enable(bucket, opts = {})
|
|
|
|
(@buckets ||= {})[bucket] = opts
|
|
|
|
end
|
|
|
|
|
2013-08-03 17:51:31 +00:00
|
|
|
def validate(machine)
|
|
|
|
errors = _detected_errors
|
|
|
|
|
|
|
|
if enabled? && ! ALLOWED_SCOPES.include?(@scope.to_s)
|
|
|
|
errors << I18n.t('vagrant_cachier.unknown_cache_scope',
|
|
|
|
allowed: ALLOWED_SCOPES.inspect,
|
|
|
|
cache_scope: @scope)
|
|
|
|
end
|
|
|
|
|
|
|
|
{ "vagrant cachier" => errors }
|
|
|
|
end
|
|
|
|
|
2013-05-22 22:38:26 +00:00
|
|
|
def finalize!
|
|
|
|
return unless enabled?
|
|
|
|
|
|
|
|
@scope = :box if @scope == UNSET_VALUE
|
|
|
|
@auto_detect = false if @auto_detect == UNSET_VALUE
|
2013-06-11 23:16:06 +00:00
|
|
|
@enable_nfs = false if @enable_nfs == UNSET_VALUE
|
2014-01-25 04:20:39 +00:00
|
|
|
@sync_opts = {} if @sync_opts == UNSET_VALUE
|
2013-05-22 22:38:26 +00:00
|
|
|
@buckets = @buckets ? @buckets.dup : {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def enabled?
|
|
|
|
@enabled ||= @auto_detect != UNSET_VALUE ||
|
|
|
|
@buckets != nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|