Module: Sycl

Defined in:
lib/sycl.rb

Overview

sycl.rb - Simple YAML Configuration Library

Sycl is a gem that makes using YAML for configuration files convenient and easy. Hashes and arrays made from parsing YAML via Sycl get helper methods that provide simple and natural syntax for querying and setting values. YAML output through Sycl is sorted, so configuration file versions can be compared consistently, and Sycl has hooks to add output styles, so your configuration files stay easy for humans to read and edit, even after being parsed and re-emitted.

For more details, visit the Sycl GitHub page.

Defined Under Namespace

Classes: Array, Hash

Class Method Summary collapse

Class Method Details

.dump(object) ⇒ Object

Sycl::dump(object) is the Sycl counterpart to YAML::dump(object). It takes a Sycl::Hash or a Sycl::Array, and renders it as YAML. Sycl YAML output is always sorted in canonical order, so you can parse and re-emit data in a reliable way.



78
79
80
81
82
83
84
85
86
# File 'lib/sycl.rb', line 78

def self.dump(object)
  if (object.is_a?(::Hash)  && !object.is_a?(Sycl::Hash)) ||
     (object.is_a?(::Array) && !object.is_a?(Sycl::Array))
    sycl_version = from_object object
    sycl_version.to_yaml
  else
    object.to_yaml
  end
end

.load(yaml) ⇒ Object

Sycl::load(yaml) is the Sycl counterpart to YAML::load(yaml). It accepts YAML text, and returns a Sycl::Hash or Sycl::Array object representing the parsed YAML.



60
61
62
# File 'lib/sycl.rb', line 60

def self.load(yaml)
  from_object YAML::load(yaml)
end

.load_file(filename) ⇒ Object

Sycl::load(filename) is the Sycl counterpart to YAML::load_file(filename). It accepts a filename, and returns a Sycl::Hash or Sycl::Array object representing the parsed YAML from that file.



69
70
71
# File 'lib/sycl.rb', line 69

def self.load_file(filename)
  from_object YAML::load_file(filename)
end