Validate machine scopes from config object and show a nice looking message instead of a stacktrace :)

This should be enough to close #33
This commit is contained in:
Fabio Rehm 2013-08-03 14:51:31 -03:00
parent 20e1176a10
commit 068d9cc8b8
2 changed files with 16 additions and 0 deletions

View file

@ -4,6 +4,8 @@ module VagrantPlugins
attr_accessor :scope, :auto_detect, :enable_nfs
attr_reader :buckets
ALLOWED_SCOPES = %w( box machine )
def initialize
@scope = UNSET_VALUE
@auto_detect = UNSET_VALUE
@ -14,6 +16,18 @@ module VagrantPlugins
(@buckets ||= {})[bucket] = opts
end
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
def finalize!
return unless enabled?

View file

@ -4,3 +4,5 @@ en:
Removing cache buckets symlinks...
skipping_bucket: |-
Skipping %{bucket} cache bucket as the guest machine does not support it
unknown_cache_scope: |-
Unknown cache scope '%{cache_scope}' (allowed scopes: %{allowed})