diff --git a/libraries/data.rb b/libraries/data.rb index 74c69da..8b027a0 100644 --- a/libraries/data.rb +++ b/libraries/data.rb @@ -63,6 +63,9 @@ module SystemdCookbook ).freeze module Common + class ArrayToKeep < Array + end + ABSOLUTE_PATH ||= { kind_of: String, callbacks: { @@ -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: { @@ -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, diff --git a/libraries/mixin.rb b/libraries/mixin.rb index ba3cd41..1871c4f 100644 --- a/libraries/mixin.rb +++ b/libraries/mixin.rb @@ -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 @@ -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