2011-06-29 20:30:46 -04:00
|
|
|
##
|
|
|
|
# The YAML module allows you to use one of the two YAML engines that ship with
|
|
|
|
# ruby. By default Psych is used but the old and unmaintained Syck may be
|
|
|
|
# chosen.
|
|
|
|
|
2012-08-22 13:43:16 -04:00
|
|
|
begin
|
|
|
|
require 'psych'
|
|
|
|
rescue LoadError
|
|
|
|
warn "#{caller[0]}:"
|
|
|
|
warn "It seems your ruby installation is missing psych (for YAML output)."
|
|
|
|
warn "To eliminate this warning, please install libyaml and reinstall your ruby."
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
|
2013-04-27 10:26:20 -04:00
|
|
|
module Psych # :nodoc:
|
2013-02-03 12:40:30 -05:00
|
|
|
class EngineManager
|
|
|
|
# Returns the YAML engine in use.
|
|
|
|
#
|
|
|
|
# By default Psych is used but the old and unmaintained Syck may be chosen.
|
|
|
|
#
|
|
|
|
# See #yamler= for more information.
|
2010-04-03 17:50:47 -04:00
|
|
|
attr_reader :yamler
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2013-02-03 12:40:30 -05:00
|
|
|
def initialize # :nodoc:
|
2012-08-22 13:43:16 -04:00
|
|
|
@yamler = 'psych'
|
2004-07-15 01:04:49 -04:00
|
|
|
end
|
|
|
|
|
2013-02-03 12:40:30 -05:00
|
|
|
def syck? # :nodoc:
|
2012-08-22 13:43:16 -04:00
|
|
|
false
|
2003-05-09 17:25:50 -04:00
|
|
|
end
|
|
|
|
|
2013-02-03 12:40:30 -05:00
|
|
|
# By default Psych is used but the old and unmaintained Syck may be chosen.
|
|
|
|
#
|
|
|
|
# After installing the 'syck' gem, you can set the YAML engine to syck:
|
|
|
|
#
|
|
|
|
# YAML::ENGINE.yamler = 'syck'
|
|
|
|
#
|
|
|
|
# To set the YAML engine back to psych:
|
|
|
|
#
|
|
|
|
# YAML::ENGINE.yamler = 'psych'
|
2010-04-03 17:50:47 -04:00
|
|
|
def yamler= engine
|
2012-08-22 13:43:16 -04:00
|
|
|
case engine
|
|
|
|
when 'syck' then warn "syck has been removed"
|
|
|
|
when 'psych' then @yamler = 'psych'
|
|
|
|
else
|
|
|
|
raise(ArgumentError, "bad engine")
|
|
|
|
end
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2010-04-03 17:50:47 -04:00
|
|
|
engine
|
2003-05-09 17:25:50 -04:00
|
|
|
end
|
2010-04-03 17:50:47 -04:00
|
|
|
end
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2012-08-22 13:43:16 -04:00
|
|
|
ENGINE = EngineManager.new # :nodoc:
|
2010-04-03 17:50:47 -04:00
|
|
|
end
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2013-04-27 10:26:20 -04:00
|
|
|
# YAML Ain't Markup Language
|
|
|
|
#
|
|
|
|
# This module provides a Ruby interface for data serialization in YAML format.
|
|
|
|
#
|
|
|
|
# The underlying implementation depends on an engine to handle the parsing and
|
|
|
|
# serialization for Ruby, by default this will be using the libyaml wrapper
|
|
|
|
# Psych.
|
|
|
|
#
|
|
|
|
# See Psych::EngineManager for details on switching the default YAML engine.
|
|
|
|
#
|
|
|
|
# Working with YAML can be very simple, for example:
|
|
|
|
#
|
|
|
|
# require 'yaml' # STEP ONE, REQUIRE YAML!
|
|
|
|
# # Parse a YAML string
|
|
|
|
# YAML.load("--- foo") #=> "foo"
|
|
|
|
#
|
|
|
|
# # Emit some YAML
|
|
|
|
# YAML.dump("foo") # => "--- foo\n...\n"
|
|
|
|
# { :a => 'b'}.to_yaml # => "---\n:a: b\n"
|
|
|
|
#
|
2013-04-27 10:54:37 -04:00
|
|
|
# Do not use YAML to load untrusted data. Doing so is unsafe and could allow
|
|
|
|
# malicious input to execute arbitrary code inside your application. Please see
|
|
|
|
# doc/security.rdoc for more information.
|
|
|
|
#
|
2013-04-27 10:26:20 -04:00
|
|
|
# For more advanced details on the implementation see Psych, and also check out
|
|
|
|
# yaml.org for spec details and other helpful information.
|
2013-04-27 21:11:55 -04:00
|
|
|
module YAML end if false
|
2012-08-22 13:43:16 -04:00
|
|
|
YAML = Psych
|