From 068d9cc8b8b651aaaabd3de71f6678f56c38917c Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 3 Aug 2013 14:51:31 -0300 Subject: [PATCH] Validate machine scopes from config object and show a nice looking message instead of a stacktrace :) This should be enough to close #33 --- lib/vagrant-cachier/config.rb | 14 ++++++++++++++ locales/en.yml | 2 ++ 2 files changed, 16 insertions(+) diff --git a/lib/vagrant-cachier/config.rb b/lib/vagrant-cachier/config.rb index b3fcda0..a450505 100644 --- a/lib/vagrant-cachier/config.rb +++ b/lib/vagrant-cachier/config.rb @@ -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? diff --git a/locales/en.yml b/locales/en.yml index 52dc977..ec6d39a 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -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})