From 67d5aa499f8aef1d398a8b39f04f75c05831662e Mon Sep 17 00:00:00 2001 From: elijah Date: Sat, 21 Sep 2013 16:51:34 -0700 Subject: 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. --- lib/leap_cli/config/object.rb | 19 +++++++++++++++---- lib/leap_cli/version.rb | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'lib') 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.' -- cgit v1.2.3