Puppet Function: to_ruby
- Defined in:
-
vendor_modules/stdlib/lib/puppet/functions/to_ruby.rb
- Function type:
- Ruby 4.x API
Summary
Convert an object into a String containing its Ruby representation
Overview
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'vendor_modules/stdlib/lib/puppet/functions/to_ruby.rb', line 17
Puppet::Functions.create_function(:to_ruby) do
dispatch :to_ruby do
param 'Any', :object
end
def to_ruby(object)
serialized = Puppet::Pops::Serialization::ToDataConverter.convert(object, rich_data: true)
serialized_to_ruby(serialized)
end
def serialized_to_ruby(serialized)
case serialized
when Array then "[#{serialized.map { |x| serialized_to_ruby(x) }.join(', ')}]"
when Hash then "{#{serialized.map { |k, v| "#{serialized_to_ruby(k)} => #{serialized_to_ruby(v)}" }.join(', ')}}"
else serialized.inspect
end
end
end
|