Oyl
Constants
Class methods
Writes value as a YAML 1.2 document that Oyl.parse reads back as
the same value, in any dialect (see Oyl::Builder#write).
Oyl.dump({"name" => "oyl", "on" => "yes"}) # => "name: oyl\non: \"yes\"\n"
Writes value as a YAML 1.2 document that Oyl.parse reads back as
the same value, in any dialect (see Oyl::Builder#write).
Oyl.dump({"name" => "oyl", "on" => "yes"}) # => "name: oyl\non: \"yes\"\n"
Writes each of values as a document of one YAML stream.
Parses a YAML document and returns a Oyl::Any. Scalars are typed
by YAML 1.2's Core schema, or by dialect, and a document saying
%YAML 1.1 by YAML 1.1's; << merge keys are applied.
data = Oyl.parse("name: oyl\nversion: 0.1.0")
data["name"].as_s # => "oyl"
Parses all YAML documents and returns an Array(Oyl::Any).
docs = Oyl.parse_all("---\nfoo\n---\nbar")
docs.size # => 2
Makes data, a YAML 1.1 file, read the same in YAML 1.2, rewriting only what a 1.2 reader would read otherwise and keeping every other byte: comments, layout, quoting, key order. Returns the new text and each change, with what couldn't be fixed (reported, left as it was).
from names the file's reader: :yaml11 for PyYAML (and Ansible),
:goyaml2 for go-yaml v2 (Kubernetes); afterwards the file reads the
same in it and in YAML 1.2. Left nil, the reader is unknown: what
PyYAML and go-yaml v2 read alike is fixed, what they read otherwise
reported. Values keep the reader's meaning, keys their text (as YAML
1.2 reads them); keys_keep_value and values_keep_text flip either.
text, fixes = Oyl.upgrade("on: push\nenabled: yes\nmode: 0755\n", from: :yaml11)
text # => %("on": push\nenabled: true\nmode: !!int 0o755\n)
Raises Oyl::ParseException for input the reader can't read, or if
the output would read otherwise than decided (a bug, never a file).
Converts the first YAML document in data to JSON, in Oyl's C, with
no Crystal values in between. Scalars are typed by dialect (a
%YAML 1.1 document by YAML 1.1), aliases are expanded, << merge
keys applied, keys sorted, and numbers and strings written as Go's
encoding/json writes them. A key set twice keeps its last value, or
with strict raises. An empty stream is null.
With dialect: :goyaml2, the output is byte for byte what
sigs.k8s.io/yaml's YAMLToJSON writes, as Kubernetes reads YAML.
Oyl.yaml_to_json("b: yes\na: 0777\n") # => %({"a":777,"b":"yes"})
Oyl.yaml_to_json("b: yes\na: 0777\n", dialect: :goyaml2) # => %({"a":511,"b":true})