aboutsummaryrefslogtreecommitdiff
path: root/lib/leap_cli/config
diff options
context:
space:
mode:
Diffstat (limited to 'lib/leap_cli/config')
-rw-r--r--lib/leap_cli/config/macros.rb22
-rw-r--r--lib/leap_cli/config/object.rb6
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/leap_cli/config/macros.rb b/lib/leap_cli/config/macros.rb
index f46799c..b5f6a34 100644
--- a/lib/leap_cli/config/macros.rb
+++ b/lib/leap_cli/config/macros.rb
@@ -335,5 +335,27 @@ module LeapCli; module Config
entries.join("\n")
end
+ ##
+ ## UTILITY
+ ##
+
+ class AssertionFailed < Exception
+ attr_accessor :assertion
+ def initialize(assertion)
+ @assertion = assertion
+ end
+ def to_s
+ @assertion
+ end
+ end
+
+ def assert(assertion)
+ if instance_eval(assertion)
+ true
+ else
+ raise AssertionFailed.new(assertion)
+ end
+ end
+
end
end; end
diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb
index 00997b1..1d296b3 100644
--- a/lib/leap_cli/config/object.rb
+++ b/lib/leap_cli/config/object.rb
@@ -282,6 +282,12 @@ module LeapCli
Util::log "error message: no file '#{exc}'", :indent => 1
end
end
+ rescue AssertionFailed => exc
+ Util.bail! do
+ Util::log :failed, "assertion while evaluating node '#{@node.name}'"
+ Util::log 'assertion: %s' % exc.assertion, :indent => 1
+ Util::log "offending key: #{key}", :indent => 1
+ end
rescue SyntaxError, StandardError => exc
Util::bail! do
Util::log :error, "while evaluating node '#{@node.name}'"