Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion libraries/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ module SystemdCookbook
).freeze

module Common
class ArrayToKeep < Array
end

ABSOLUTE_PATH ||= {
kind_of: String,
callbacks: {
Expand Down Expand Up @@ -118,6 +121,9 @@ module Common
end,
},
}.freeze
ARRAY_OF_ADDRESSES ||= {
kind_of: [String, Array, ArrayToKeep],
}.freeze
ARRAY_OF_SOFT_ABSOLUTE_PATHS ||= {
kind_of: [String, Array],
callbacks: {
Expand Down Expand Up @@ -1456,7 +1462,7 @@ module Network
).concat([true, false]),
},
'BindCarrier' => Common::ARRAY,
'Address' => Common::STRING,
'Address' => Common::ARRAY_OF_ADDRESSES,
'Gateway' => Common::STRING,
'DNS' => Common::STRING,
'Domains' => Common::ARRAY,
Expand Down
17 changes: 14 additions & 3 deletions libraries/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def property_hash(options = {})
[
opt.camelcase,
option_value(
send("#{section.underscore}_#{opt.underscore}".to_sym)
send("#{section.underscore}_#{opt.underscore}".to_sym),
"#{section.underscore}_#{opt.underscore}"
),
]
end.to_h
Expand All @@ -89,12 +90,22 @@ def property_hash(options = {})
result.delete_if { |_, v| v.empty? }
end

def option_value(obj)
def option_value(obj, name=nil)
expected_types = self.class.properties[name.to_sym].validation_options[:kind_of]
if expected_types.kind_of?(Array) and expected_types.include?(SystemdCookbook::Common::ArrayToKeep)
keep_array=true
else
keep_array = false
end
case obj
when Hash
obj.to_kv_pairs.join(' ')
when Array
obj.join(' ')
if keep_array
obj
else
obj.join(' ')
end
when TrueClass, FalseClass
obj ? 'yes' : 'no'
else
Expand Down