class

Oyl::Builder

Inherits Reference < Object

Writes YAML with Oyl's emitter: a stream of documents, each holding one node. #write writes a Crystal value so that it reads back as the same value; #scalar, #sequence and #mapping write what they are given.

yaml = Oyl::Builder.build do |b|
  b.document do
    b.mapping do
      b.write "name"
      b.write "oyl"
      b.write "fast"
      b.write true
    end
  end
end
yaml # => "name: oyl\nfast: true\n"

Constants

STR_TAG = "tag:yaml.org,2002:str".to_slice

Constructors

new(*, style : Oyl::EmitStyle = :block, indent : Int32 = 2)
Source

Class methods

build(*, style : Oyl::EmitStyle = :block, indent : Int32 = 2, &) : String

Yields a builder and returns the YAML it wrote.

Source
typed?(text : String) : Bool

Whether YAML 1.2, YAML 1.1 or go-yaml v2 reads text, written plain, as anything but a string.

Source

Instance methods

alias(anchor : String) : Nil

Writes an alias to the node anchored anchor.

Source
close
Source
document(*, explicit_start : Bool = false, explicit_end : Bool = false, &) : Nil

Writes a document around what the block writes. --- and ... are written where YAML needs them, or always with explicit_start and explicit_end.

Source
finalize
Source
mapping(*, style : Oyl::MappingStyle = :any, tag : String | Nil = nil, anchor : String | Nil = nil, &) : Nil

Writes a mapping of what the block writes: a key, then its value.

Source
scalar(value : String, *, style : Oyl::ScalarStyle = :any, tag : String | Nil = nil, anchor : String | Nil = nil) : Nil

Writes value as a scalar's text. With ScalarStyle::ANY (or PLAIN) it is written plain when that reads back as the same text, else quoted; YAML may still read that text as another type (true). tag is a full tag (tag:yaml.org,2002:str, written !!str) or a local one (!foo).

Source
sequence(*, style : Oyl::SequenceStyle = :any, tag : String | Nil = nil, anchor : String | Nil = nil, &) : Nil

Writes a sequence of what the block writes.

Source
to_s(io : IO) : Nil

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Source
to_s

Ends the stream, if it hasn't ended, and returns the YAML written.

Source
write(value) : Nil

Writes value so that Oyl.parse reads it back as the same value, whatever its dialect: a string is quoted where YAML 1.2, YAML 1.1 or go-yaml v2 would read it as another type ("yes", "1:30", ""), and written as a literal block when it has line breaks. YAML 1.2 has no plain form for Time and Bytes, so they are tagged !!timestamp and !!binary. Each type writes itself with to_oyl(builder), which a type of your own can define.

Source