Sha256: 9a5731935765c5b0a0d32b4eb6b2804dcc10c5d1c2c23f4e776a3b6a934135a1

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

##
# The {Ryo::YAML 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 Ryo} module.
module Ryo::YAML
  require "yaml"
  extend self

  ##
  # @example
  #   Ryo.from_yaml(path: "/foo/bar/baz.yaml")
  #   Ryo.from_yaml(string: "---\nfoo: bar\n")
  #
  # @param [String] path
  #  The path to a YAML file
  #
  # @param [String] string
  #  A blob of YAML
  #
  # @param [Ryo] object
  #  {Ryo::Object Ryo::Object}, or {Ryo::BasicObject Ryo::BasicObject}
  #  Defaults to {Ryo::Object Ryo::Object}
  #
  # @raise [SystemCallError]
  #  Might raise a number of Errno exceptions
  #
  # @return [Ryo::Object, Ryo::BasicObject]
  #  Returns a Ryo object
  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

  Ryo.extend(self)
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
quran-audio-0.5.1 bundle/ryo.rb/lib/ryo/yaml.rb
quran-audio-0.5.0 bundle/ryo.rb/lib/ryo/yaml.rb
quran-audio-0.4.2 bundle/ryo.rb/lib/ryo/yaml.rb
ryo.rb-0.5.6 lib/ryo/yaml.rb
ryo.rb-0.5.5 lib/ryo/yaml.rb