summaryrefslogtreecommitdiff
path: root/lib/leap_cli/config
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-09-21 16:51:34 -0700
committerelijah <elijah@riseup.net>2013-09-21 16:51:34 -0700
commit67d5aa499f8aef1d398a8b39f04f75c05831662e (patch)
tree67a293a8e334fcb409032dac993744d8eccb4f85 /lib/leap_cli/config
parentc90d98beeb341561750611c3e551a5bc25479ef1 (diff)
added support for config arrays that are required: e.g. ["REQUIRED"]. this will ensure that the type is an array, and ensure that some value is set.
Diffstat (limited to 'lib/leap_cli/config')
-rw-r--r--lib/leap_cli/config/object.rb19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb
index 1d296b3..47800d5 100644
--- a/lib/leap_cli/config/object.rb
+++ b/lib/leap_cli/config/object.rb
@@ -149,9 +149,9 @@ module LeapCli
# merge arrays when one value is not an array
elsif old_value.is_a?(Array) && !new_value.is_a?(Array)
- value = (old_value.dup << new_value).compact.uniq
+ (value = (old_value.dup << new_value).compact.uniq).delete('REQUIRED')
elsif new_value.is_a?(Array) && !old_value.is_a?(Array)
- value = (new_value.dup << old_value).compact.uniq
+ (value = (new_value.dup << old_value).compact.uniq).delete('REQUIRED')
# catch errors
elsif type_mismatch?(old_value, new_value)
@@ -207,7 +207,7 @@ module LeapCli
def evaluate_everything
keys.each do |key|
obj = fetch_value(key)
- if obj == "REQUIRED"
+ if is_required_value_not_set?(obj)
Util::log 0, :warning, "required key \"#{key}\" is not set in node \"#{node.name}\"."
elsif obj.is_a? Config::Object
obj.evaluate_everything
@@ -222,7 +222,7 @@ module LeapCli
if @late_eval_list
@late_eval_list.each do |key, value|
self[key] = evaluate_now(key, value)
- if self[key] == "REQUIRED"
+ if is_required_value_not_set?(self[key])
Util::log 0, :warning, "required key \"#{key}\" is not set in node \"#{node.name}\"."
end
end
@@ -320,6 +320,17 @@ module LeapCli
end
end
+ #
+ # returns true if the value has not been changed and the default is "REQUIRED"
+ #
+ def is_required_value_not_set?(value)
+ if value.is_a? Array
+ value == ["REQUIRED"]
+ else
+ value == "REQUIRED"
+ end
+ end
+
end # class
end # module
end # module \ No newline at end of file