Module: Ryo::YAML

Extended by:
YAML
Included in:
YAML
Defined in:
lib/ryo/yaml.rb

Overview

The Ryo::YAML module provides a number of methods for coercing YAML data into a Ryo object. It must be required separately to Ryo (ie: require "ryo/yaml"), and the methods of this module are then available on the Ryo module.

Instance Method Summary collapse

Instance Method Details

#from_yaml(path: nil, string: nil, object: Ryo::Object) ⇒ Ryo::Object, Ryo::BasicObject

Returns a Ryo object

Examples:

Ryo.from_yaml(path: "/foo/bar/baz.yaml")
Ryo.from_yaml(string: "---\nfoo: bar\n")

Parameters:

  • path (String) (defaults to: nil)

    The path to a YAML file

  • string (String) (defaults to: nil)

    A blob of YAML

  • object (Ryo) (defaults to: Ryo::Object)

Returns:

Raises:

  • (SystemCallError)

    Might raise a number of Errno exceptions



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ryo/yaml.rb', line 32

def from_yaml(path: nil, string: nil, object: Ryo::Object)
  if path && string
    raise ArgumentError, "Provide a path or string but not both"
  elsif path
    object.from YAML.load_file(path)
  elsif string
    object.from YAML.load(string)
  else
    raise ArgumentError, "No path or string provided"
  end
end