Module: YAML
- Defined in:
- lib/yaml/tag.rb,
lib/yaml.rb,
lib/yaml/dbm.rb,
lib/yaml/syck.rb,
lib/yaml/ypath.rb,
lib/yaml/error.rb,
lib/yaml/types.rb,
lib/yaml/stream.rb,
lib/yaml/loader.rb,
lib/yaml/encoding.rb,
lib/yaml/basenode.rb,
lib/yaml/yamlnode.rb,
ext/libyaml/rubyext.c,
lib/yaml/constants.rb,
lib/yaml/baseemitter.rb
Overview
Constants used throughout the library
Defined Under Namespace
Modules: BaseEmitter, BaseNode, LibYAML, Syck
Classes: DBM, DomainType, Error, Loader, Mapping, Object, Omap, Pairs, ParseError, PrivateType, Sequence, Set, SpecialHash, Store, Stream, TypeError, YPath, YamlNode
Constant Summary
"With UseHeader=false, the node Array or Hash must have elements"
"With UseHeader=false, the node must be an Array or Hash"
- ERROR_BAD_EXPLICIT =
"Unsupported explicit transfer: '%s'"
- ERROR_MANY_EXPLICIT =
"More than one explicit transfer"
- ERROR_MANY_IMPLICIT =
"More than one implicit request"
- ERROR_NO_ANCHOR =
"No anchor for alias '%s'"
- ERROR_BAD_ANCHOR =
"Invalid anchor: %s"
- ERROR_MANY_ANCHOR =
"More than one anchor"
- ERROR_ANCHOR_ALIAS =
"Can't define both an anchor and an alias"
- ERROR_BAD_ALIAS =
"Invalid alias: %s"
- ERROR_MANY_ALIAS =
"More than one alias"
- ERROR_ZERO_INDENT =
"Can't use zero as an indentation width"
- ERROR_UNSUPPORTED_VERSION =
"This release of YAML.rb does not support YAML version %s"
- ERROR_UNSUPPORTED_ENCODING =
"Attempt to use unsupported encoding: %s"
- VERSION =
'0.60'
- SUPPORTED_YAML_VERSIONS =
['1.0']
- WORD_CHAR =
'A-Za-z0-9'
- PRINTABLE_CHAR =
'-_A-Za-z0-9!?/()$\'". '
- NOT_PLAIN_CHAR =
'\x7f\x0-\x1f\x80-\x9f'
- ESCAPE_CHAR =
'[\\x00-\\x09\\x0b-\\x1f]'
- INDICATOR_CHAR =
'*&!|\\\\^@%{}[]='
- SPACE_INDICATORS =
'-#:,?'
- RESTRICTED_INDICATORS =
'#:,}]'
- DNS_COMP_RE =
"\\w(?:[-\\w]*\\w)?"
- DNS_NAME_RE =
"(?:(?:#{DNS_COMP_RE}\\.)+#{DNS_COMP_RE}|#{DNS_COMP_RE})"
- ESCAPES =
%w{\x00 \x01 \x02 \x03 \x04 \x05 \x06 \a
\x08 \t \n \v \f \r \x0e \x0f
\x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17
\x18 \x19 \x1a \e \x1c \x1d \x1e \x1f
}
- UNESCAPES =
{
'a' => "\x07", 'b' => "\x08", 't' => "\x09",
'n' => "\x0a", 'v' => "\x0b", 'f' => "\x0c",
'r' => "\x0d", 'e' => "\x1b", '\\' => '\\',
}
- DEFAULTS =
{
:Indent => 2, :UseHeader => false, :UseVersion => false, :Version => '1.0',
:SortKeys => false, :AnchorFormat => 'id%03d', :ExplicitTypes => false,
:WidthType => 'absolute', :BestWidth => 80,
:UseBlock => false, :UseFold => false, :Encoding => :None
}
- @@tagged_classes =
A dictionary of taguris which map to Ruby classes.
{}
Class Method Summary
(collapse)
-
+ (Object) add_builtin_type(type_tag, &transfer)
-
+ (Object) add_domain_type(domain, type_tag, &transfer)
-
+ (Object) add_private_type(type_tag, &transfer)
-
+ (Object) add_ruby_type(type_tag, &transfer)
-
+ (Object) dump(obj, io = nil)
-
+ (Object) dump_stream(*objs)
-
+ (Object) each_document(io, &block)
-
+ (Object) emitter
-
+ (Object) escape(value, skip = "")
Escape the string, condensing common escapes.
-
+ (Object) load(io)
-
+ (Object) load_all(io)
-
+ (Object) load_documents(io)
-
+ (Object) load_file(path)
-
+ (Object) parse(io)
-
+ (Object) parse_file(path)
-
+ (Object) parser
-
+ (Object) quick_emit(out, &block)
-
+ (Object) tag_class(tag, cls)
Associates a taguri tag with a Ruby class cls.
-
+ (Object) tagged_classes
Returns the complete dictionary of taguris, paired with classes.
-
+ (Object) unescape(value)
Unescape the condenses escapes.
Class Method Details
+ (Object) add_builtin_type(type_tag, &transfer)
85
86
87
|
# File 'lib/yaml.rb', line 85
def YAML.add_builtin_type(type_tag, &transfer)
LibYAML::DEFAULT_RESOLVER.add_type("tag:yaml.org,2002:#{type_tag}", transfer)
end
|
+ (Object) add_domain_type(domain, type_tag, &transfer)
89
90
91
|
# File 'lib/yaml.rb', line 89
def YAML.add_domain_type(domain, type_tag, &transfer)
LibYAML::DEFAULT_RESOLVER.add_type("tag:#{domain}:#{type_tag}", transfer)
end
|
+ (Object) add_private_type(type_tag, &transfer)
97
98
99
|
# File 'lib/yaml.rb', line 97
def YAML.add_private_type(type_tag, &transfer)
LibYAML::DEFAULT_RESOLVER.add_type("x-private:#{type_tag}", transfer)
end
|
+ (Object) add_ruby_type(type_tag, &transfer)
93
94
95
|
# File 'lib/yaml.rb', line 93
def YAML.add_ruby_type(type_tag, &transfer)
LibYAML::DEFAULT_RESOLVER.add_type("tag:ruby.yaml.org,2002:#{type_tag}", transfer)
end
|
+ (Object) dump(obj, io = nil)
23
24
25
|
# File 'lib/yaml.rb', line 23
def YAML.dump(obj, io=nil)
obj.to_yaml(io)
end
|
+ (Object) dump_stream(*objs)
27
28
29
30
31
32
33
|
# File 'lib/yaml.rb', line 27
def YAML.dump_stream(*objs)
LibYAML::Emitter.new.stream do |stream|
objs.each do |obj|
stream.document { |doc| obj.to_yaml(doc) }
end
end
end
|
+ (Object) each_document(io, &block)
51
52
53
|
# File 'lib/yaml.rb', line 51
def YAML.each_document(io, &block)
YAML.load_documents(io, &block)
end
|
19
20
21
|
# File 'lib/yaml.rb', line 19
def YAML.emitter
LibYAML::Emitter.new
end
|
+ (Object) escape(value, skip = "")
Escape the string, condensing common escapes
10
11
12
13
14
15
16
|
# File 'lib/yaml/encoding.rb', line 10
def YAML.escape( value, skip = "" )
value.gsub( /\\/, "\\\\\\" ).
gsub( /"/, "\\\"" ).
gsub( /([\x00-\x1f])/ ) do
skip[$&] || ESCAPES[ $&.unpack("C")[0] ]
end
end
|
+ (Object) load(io)
35
36
37
38
|
# File 'lib/yaml.rb', line 35
def YAML.load(io)
parsr = LibYAML::Parser.new(io)
parsr.load
end
|
+ (Object) load_all(io)
55
56
57
58
59
|
# File 'lib/yaml.rb', line 55
def YAML.load_all(io)
elements = []
YAML.load_documents(io) { |e| elements << e}
elements
end
|
+ (Object) load_documents(io)
44
45
46
47
48
49
|
# File 'lib/yaml.rb', line 44
def YAML.load_documents(io)
yparser = LibYAML::Parser.new(io)
until (element = yparser.load).nil?
yield(element)
end
end
|
+ (Object) load_file(path)
40
41
42
|
# File 'lib/yaml.rb', line 40
def YAML.load_file(path)
File.open(path) { |f| load(f) }
end
|
+ (Object) parse(io)
61
62
63
64
|
# File 'lib/yaml.rb', line 61
def YAML.parse(io)
return false if io==''
LibYAML::Parser.new(io).parse
end
|
+ (Object) parse_file(path)
66
67
68
|
# File 'lib/yaml.rb', line 66
def YAML.parse_file(path)
File.open(path) { |f| parse(f) }
end
|
15
16
17
|
# File 'lib/yaml.rb', line 15
def YAML.parser
LibYAML::Parser.new
end
|
+ (Object) quick_emit(out, &block)
70
71
72
73
74
75
76
77
78
|
# File 'lib/yaml.rb', line 70
def YAML.quick_emit(out, &block)
if out.is_a? LibYAML::Emitter
yield(out)
else
LibYAML::Emitter.new(out).stream do |stream|
stream.document { |doc| yield(doc) }
end
end
end
|
+ (Object) tag_class(tag, cls)
Associates a taguri tag with a Ruby class cls. The
taguri is used to give types to classes when loading YAML. Taguris are of
the form:
tag:authorityName,date:specific
The authorityName is a domain name or email address. The
date is the date the type was issued in YYYY or YYYY-MM or
YYYY-MM-DD format. The specific is a name for the type being
added.
For example, built-in YAML types have 'yaml.org' as the
authorityName and '2002' as the date. The
specific is simply the name of the type:
tag:yaml.org,2002:int
tag:yaml.org,2002:float
tag:yaml.org,2002:timestamp
The domain must be owned by you on the date declared. If you
don't own any domains on the date you declare the type, you can simply
use an e-mail address.
tag:why@ruby-lang.org,2004:notes/personal
35
36
37
38
39
40
|
# File 'lib/yaml/tag.rb', line 35
def YAML.tag_class( tag, cls )
if @@tagged_classes.has_key? tag
warn "class #{ @@tagged_classes[tag] } held ownership of the #{ tag } tag"
end
@@tagged_classes[tag] = cls
end
|
+ (Object) tagged_classes
Returns the complete dictionary of taguris, paired with classes. The key
for the dictionary is the full taguri. The value for each key is the class
constant associated to that taguri.
YAML.tagged_classes["tag:yaml.org,2002:int"] => Integer
48
49
50
|
# File 'lib/yaml/tag.rb', line 48
def YAML.tagged_classes
@@tagged_classes
end
|
+ (Object) unescape(value)
Unescape the condenses escapes
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/yaml/encoding.rb', line 21
def YAML.unescape( value )
value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) {
if $3
["#$3".hex ].pack('U*')
elsif $2
[$2].pack( "H2" )
else
UNESCAPES[$1]
end
}
end
|