Method: Puppet::Resource#to_data_hash
- Defined in:
- lib/puppet/resource.rb
#to_data_hash ⇒ Object
Produces a Data compliant hash of the resource. The result depends on the –rich_data setting, and the context value for Puppet.lookup(:stringify_rich), that if it is ‘true` will use the ToStringifiedConverter to produce the value per parameter. (Note that the ToStringifiedConverter output is lossy and should not be used when producing a catalog serialization).
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/puppet/resource.rb', line 99 def to_data_hash data = { 'type' => type, 'title' => title.to_s, 'tags' => .to_data_hash } ATTRIBUTES.each do |param| value = send(param) data[param.to_s] = value unless value.nil? end data['exported'] ||= false # To get stringified parameter values the flag :stringify_rich can be set # in the puppet context. # stringify = Puppet.lookup(:stringify_rich) { false } converter = stringify ? Puppet::Pops::Serialization::ToStringifiedConverter.new : nil params = {} to_hash.each_pair do |param, value| # Don't duplicate the title as the namevar unless param == namevar && value == title if stringify params[param.to_s] = converter.convert(value) else params[param.to_s] = Puppet::Resource.value_to_json_data(value) end end end unless params.empty? data['parameters'] = Puppet::Pops::Serialization::ToDataConverter .convert(params, { :rich_data => Puppet.lookup(:rich_data), :symbol_as_string => true, :local_reference => false, :type_by_reference => true, :message_prefix => ref, :semantic => self }) end data['sensitive_parameters'] = sensitive_parameters.map(&:to_s) unless sensitive_parameters.empty? data end |