Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Haskel committed Sep 10, 2015
1 parent ead4c7e commit 993e8b9
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/puppet/provider/hocon_setting/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def self.namevar(section_name, setting)
end

def exists?
# we only want to check for the individual element for idempotence when
# absent, otherwise the new value will be picked up by insync?
if resource[:type] == 'array_element' and resource[:ensure] == :absent
if resource[:type] == 'array_element'
Array(@resource[:value]).each do |v|
if value.flatten.include?(v)
return true
Expand Down Expand Up @@ -97,8 +95,9 @@ def remove_value(value_to_remove)
if resource[:type] == 'array_element'
new_value_tmp = []
val = value
new_value_tmp << val
new_value_tmp.flatten!
Array(val).each do |v|
new_value_tmp << v
end
Array(value_to_remove).each do |v|
new_value_tmp.delete(v)
end
Expand All @@ -113,10 +112,16 @@ def remove_value(value_to_remove)
def set_value(value_to_set)
if resource[:type] == 'array_element'
tmp_val = []
tmp_val << value
tmp_val << value_to_set
tmp_val.flatten!
tmp_val.uniq!
val = value
Array(val).each do |v|
tmp_val << v
end
Array(value_to_set).each do |v|
unless tmp_val.include?(v)
tmp_val << v
end
end

new_value = Hocon::ConfigValueFactory.from_any_ref(tmp_val, nil)
elsif resource[:type] == 'array' || (value_to_set.is_a?(String) && resource[:type] != 'text') || (value_to_set.is_a?(Array) && value_to_set.size > 1)
new_value = Hocon::ConfigValueFactory.from_any_ref(value_to_set, nil)
Expand Down

0 comments on commit 993e8b9

Please sign in to comment.