expression type | example output |
---|---|
literal undef | nil |
literal default | "default" |
literal integer | 1 |
literal float | 3.14 |
literal false | false |
literal true | true |
literal string | "hello" |
literal regexp | "/this|that.*/" |
string with single quote | "ta'phoenix" |
string with double quote | "he said \"hi\"" |
user defined Object | "Car({'regnbr' => 'abc123'})" |
deferred | "Deferred({'name' => 'func', 'arguments' => [1, 2, 3]})" |
sensitive | "#<Sensitive [value redacted]:70229233735920>" |
Timestamp 'now' | "2018-09-01T15:56:53.993630000 UTC" |
array | [1, 2, 3] |
array with sensitive | ["#<Sensitive [value redacted]:70229233766180>"] |
hash with sensitive | {"x"=>"#<Sensitive [value redacted]:70229233764800>"} |
hash | {"a"=>10, "b"=>20} |
hash non Data key | {"[\"funky\", \"key\"]"=>10} |
hash Sensitive key | {"#<Sensitive [value redacted]:70229233763220>"=>42} |
hash __ptype key | {"__ptype"=>10} |
binary | "aGVsbG8=" |
ascii-8bit string | "AgMEaGVsbG8=" |
runtime 'alien' object | "#Alien:0x007fbf0534a7f8" |
runtime symbol | "symbolic" |
runtime 'alien' fact | "#Alien:0x007fbf0534a7f8" |
a type | "Integer[0, 100]" |
a user defined type | "Car" |
a self referencing type | "Tree = Array[Variant[String, Tree]]" |
Last active
September 2, 2018 17:02
-
-
Save hlindberg/ae53dc18608e13f6878903c251250ffd to your computer and use it in GitHub Desktop.
Stringified output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'puppet_pal' | |
Puppet.initialize_settings | |
binary_string = "\x02\x03\x04hello".force_encoding('ascii-8bit') | |
class Alien | |
end | |
alien_fact = Alien.new | |
vars = { | |
'binary_val' => binary_string, | |
'alien_val' => [] | |
} | |
facts = { | |
'alien_fact' => alien_fact | |
} | |
result = Puppet::Pal.in_tmp_environment('pal_env', modulepath: [], facts: facts, variables: vars) do |pal| | |
pal.with_catalog_compiler {|c| | |
vars['alien_val'][0] = alien_fact # punch a runtime value into the mutable array | |
vars['alien_val'][1] = :symbolic # punch a symbol value | |
source = <<-'SOURCE' | |
type Car = Object[attributes => {regnbr => String}]; | |
type Tree = Array[Variant[String, Tree]] | |
$x = { | |
"literal undef" => undef, | |
"literal default" => default, | |
"literal integer" => 1, | |
"literal float" => 3.14, | |
"literal false" => false, | |
"literal true" => true, | |
"literal string" => "hello", | |
"literal regexp" => /this|that.*/, | |
"string with single quote" => "ta'phoenix", | |
"string with double quote" => "he said \"hi\"", | |
"user defined Object" => Car(abc123), | |
"deferred" => Deferred(func,[1,2,3]), | |
"sensitive" => Sensitive(hush), | |
"Timestamp 'now'" => Timestamp(), | |
"array" => [1,2,3], | |
"array with sensitive" => [Sensitive(hush)], | |
"hash with sensitive" => {x => Sensitive(hush)}, | |
"hash" => { a=> 10, b=> 20}, | |
"hash non Data key" => {[funky, key] => 10}, | |
"hash Sensitive key" => {Sensitive(hush) => 42 }, | |
"hash __ptype key" => {__ptype => 10}, | |
"binary" => Binary("hello", "%s"), | |
"ascii-8bit string" => $binary_val, | |
"runtime 'alien' object" => $alien_val[0], | |
"runtime symbol" => $alien_val[1], | |
"runtime 'alien' fact" => $facts['alien_fact'], | |
"a type" => Integer[0,100], | |
"a user defined type" => Car, | |
"a self referencing type" => Tree, | |
} | |
$x | |
SOURCE | |
require 'byebug'; debugger | |
val = c.evaluate_string(source) | |
Puppet::Pops::Serialization::ToStringifiedConverter.convert(val, | |
:message_prefix => "The data given to sconv.rb" | |
) | |
} | |
end | |
puts "| expression type | example output |" | |
puts "| --- | --- |" | |
result.each_pair do |k,v| | |
puts "| #{k} | #{v.inspect} |" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gist is updated with more variants. Some notable changes:
but this could also be the result of some alien object being stringified; code updated to deal with that