Module: Toon

Defined in:
lib/toon.rb,
lib/toon/decoder.rb,
lib/toon/encoder.rb,
lib/toon/version.rb,
lib/extensions/core.rb,
lib/extensions/active_support.rb

Defined Under Namespace

Modules: Decoder, Encoder, Extensions Classes: Error

Constant Summary collapse

VERSION =
'1.0.2'

Class Method Summary collapse

Class Method Details

.dump(obj, io = STDOUT, **opts) ⇒ nil

Stream a TOON payload for obj into the provided IO target.

Parameters:

  • obj (Object)

    the object to encode.

  • io (#write) (defaults to: STDOUT)

    where the payload should be written.

  • opts (Hash)

    encoder options forwarded to ‘Toon::Encoder`.

Returns:

  • (nil)


47
48
49
# File 'lib/toon.rb', line 47

def self.dump(obj, io = STDOUT, **opts)
  Toon::Encoder.dump(obj, io, **opts)
end

.generate(obj, **opts) ⇒ String

Generate a TOON-formatted String from any serializable Ruby object.

Parameters:

  • obj (Object)

    the object to encode.

  • opts (Hash)

    encoder options forwarded to ‘Toon::Encoder`.

Returns:

  • (String)

    the TOON payload.



14
15
16
# File 'lib/toon.rb', line 14

def self.generate(obj, **opts)
  Toon::Encoder.generate(obj, **opts)
end

.load(io, **opts) ⇒ Object

Read a TOON payload from any IO-like object and parse it.

Parameters:

  • io (#read)

    an IO that responds to ‘#read`.

  • opts (Hash)

    decoder options forwarded to ‘Toon::Decoder`.

Returns:

  • (Object)

    the decoded Ruby structure.



38
39
40
# File 'lib/toon.rb', line 38

def self.load(io, **opts)
  Toon::Decoder.load(io, **opts)
end

.parse(str, **opts) ⇒ Object

Parse a TOON String and reconstruct the Ruby data structure.

Parameters:

  • str (String)

    the TOON representation.

  • opts (Hash)

    decoder options forwarded to ‘Toon::Decoder`.

Returns:

  • (Object)

    the decoded Ruby structure.



30
31
32
# File 'lib/toon.rb', line 30

def self.parse(str, **opts)
  Toon::Decoder.parse(str, **opts)
end

.pretty_generate(obj, **opts) ⇒ String

Generate a human-friendly TOON String with extra spacing and indentation.

Parameters:

  • obj (Object)

    the object to encode.

  • opts (Hash)

    encoder options forwarded to ‘Toon::Encoder`.

Returns:

  • (String)

    the prettified TOON payload.



22
23
24
# File 'lib/toon.rb', line 22

def self.pretty_generate(obj, **opts)
  Toon::Encoder.pretty_generate(obj, **opts)
end