summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2016-02-18 09:47:05 -0800
committerelijah <elijah@riseup.net>2016-02-18 09:47:05 -0800
commit355244d9a4b74360de67afaa99aba47cf6d9a3b3 (patch)
tree9e2f646f616e8fc03345062e018c08b2fa34b84f /lib
parent85b21bf1e423cbbc7b44b0ff8e2d3de49a9fdeba (diff)
added support for json keys prefixed with '!' for replace.
Diffstat (limited to 'lib')
-rw-r--r--lib/leap_cli/config/object.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb
index 0f7376f..bde5fe7 100644
--- a/lib/leap_cli/config/object.rb
+++ b/lib/leap_cli/config/object.rb
@@ -197,6 +197,10 @@ module LeapCli
mode = :subtract
old_value = self.fetch '-'+key, nil
self.delete('-'+key)
+ elsif self.has_key?('!'+key)
+ mode = :replace
+ old_value = self.fetch '!'+key, nil
+ self.delete('!'+key)
else
mode = :normal
old_value = self.fetch key, nil
@@ -208,8 +212,12 @@ module LeapCli
old_value = true if old_value == "true"
old_value = false if old_value == "false"
+ # force replace?
+ if mode == :replace && prefer_self
+ value = old_value
+
# merge hashes
- if old_value.is_a?(Hash) || new_value.is_a?(Hash)
+ elsif old_value.is_a?(Hash) || new_value.is_a?(Hash)
value = Config::Object.new(@manager, @node)
old_value.is_a?(Hash) ? value.deep_merge!(old_value) : (value[key] = old_value if !old_value.nil?)
new_value.is_a?(Hash) ? value.deep_merge!(new_value, prefer_self) : (value[key] = new_value if !new_value.nil?)