aboutsummaryrefslogtreecommitdiff
path: root/lib
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
parentc90d98beeb341561750611c3e551a5bc25479ef1 (diff)
downloadleap_cli-67d5aa499f8aef1d398a8b39f04f75c05831662e.tar.gz
leap_cli-67d5aa499f8aef1d398a8b39f04f75c05831662e.tar.bz2
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')
-rw-r--r--lib/leap_cli/config/object.rb19
-rw-r--r--lib/leap_cli/version.rb2
2 files changed, 16 insertions, 5 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
diff --git a/lib/leap_cli/version.rb b/lib/leap_cli/version.rb
index e649d95..aac161b 100644
--- a/lib/leap_cli/version.rb
+++ b/lib/leap_cli/version.rb
@@ -1,6 +1,6 @@
module LeapCli
unless defined?(LeapCli::VERSION)
- VERSION = '1.2.3'
+ VERSION = '1.2.4'
COMPATIBLE_PLATFORM_VERSION = '0.2.4'..'1.99'
SUMMARY = 'Command line interface to the LEAP platform'
DESCRIPTION = 'The command "leap" can be used to manage a bevy of servers running the LEAP platform from the comfort of your own home.'