Module: RbYAML
- Defined in:
- lib/rbyaml.rb,
lib/rbyaml/yaml.rb,
lib/rbyaml/error.rb,
lib/rbyaml/nodes.rb,
lib/rbyaml/dumper.rb,
lib/rbyaml/events.rb,
lib/rbyaml/loader.rb,
lib/rbyaml/parser.rb,
lib/rbyaml/tokens.rb,
lib/rbyaml/emitter.rb,
lib/rbyaml/composer.rb,
lib/rbyaml/resolver.rb,
lib/rbyaml/serializer.rb,
lib/rbyaml/constructor.rb,
lib/rbyaml/representer.rb
Defined Under Namespace
Classes: AliasEvent, AliasToken, AnchorToken, BaseConstructor, BaseDumper, BaseLoader, BaseRepresenter, BaseResolver, BlockEndToken, BlockEntryToken, BlockMappingStartToken, BlockSequenceStartToken, CollectionEndEvent, CollectionNode, CollectionStartEvent, CommonDumper, CommonLoader, Composer, ComposerError, Constructor, ConstructorError, DirectiveToken, DocumentEndEvent, DocumentEndToken, DocumentStartEvent, DocumentStartToken, Dumper, Emitter, EmitterError, Event, FlowEntryToken, FlowMappingEndToken, FlowMappingStartToken, FlowSequenceEndToken, FlowSequenceStartToken, KeyToken, Loader, MappingEndEvent, MappingNode, MappingStartEvent, Mark, MarkedYAMLError, Node, NodeEvent, Parser, ParserError, Representer, RepresenterError, Resolver, ResolverError, SafeConstructor, SafeDumper, SafeLoader, SafeRepresenter, ScalarAnalysis, ScalarEvent, ScalarNode, ScalarToken, SequenceEndEvent, SequenceNode, SequenceStartEvent, Serializer, SerializerError, Stream, StreamEndEvent, StreamEndToken, StreamStartEvent, StreamStartToken, TagToken, Token, TypeError, ValueToken, YAMLError
Constant Summary
collapse
- DEFAULT_SCALAR_TAG =
'tag:yaml.org,2002:str'
- DEFAULT_SEQUENCE_TAG =
'tag:yaml.org,2002:seq'
- DEFAULT_MAPPING_TAG =
'tag:yaml.org,2002:map'
- @@tagged_classes =
A dictionary of taguris which map to Ruby classes.
{}
Class Method Summary
collapse
-
._add_constructor(tag, constructor, loader = Loader) ⇒ Object
-
._add_implicit_resolver(tag, regexp, first = nil, loader = Loader, dumper = Dumper) ⇒ Object
-
._add_multi_constructor(tag_prefix, multi_constructor, loader = Loader) ⇒ Object
-
._add_multi_representer(data_type, multi_representer, dumper = Dumper) ⇒ Object
-
._add_path_resolver(tag, path, kind = nil, loader = Loader, dumper = Dumper) ⇒ Object
-
._add_representer(data_type, representer, dumper = Dumper) ⇒ Object
-
._compose(stream, loader = Loader) ⇒ Object
-
._compose_all(stream, loader = Loader) ⇒ Object
-
._dump(data, stream = nil, dumper = Dumper, *kwds) ⇒ Object
-
._dump_all(documents, stream = nil, dumper = Dumper, default_style = nil, default_flow_style = nil, canonical = nil, indent = nil, width = nil, line_break = nil, explicit_start = nil, explicit_end = nil, version = nil, tags = nil) ⇒ Object
-
._dump_ruby_object(data, dumper = Dumper) ⇒ Object
-
._emit(events, stream = nil, dumper = Dumper, default_style = nil, default_flow_style = nil, canonical = nil, indent = nil, width = nil, line_break = nil) ⇒ Object
-
._load(stream, loader = Loader) ⇒ Object
-
._load_all(stream, loader = Loader) ⇒ Object
-
._parse(stream, loader = Loader) ⇒ Object
-
._safe_dump(data, stream = nil, *kwds) ⇒ Object
-
._safe_dump_all(documents, stream = nil, *kwds) ⇒ Object
-
._safe_load(stream) ⇒ Object
-
._safe_load_all(stream) ⇒ Object
-
._scan(stream, loader = Loader) ⇒ Object
-
._serialize(node, stream = nil, dumper = Dumper, *kwds) ⇒ Object
-
._serialize_all(nodes, stream = nil, dumper = Dumper, default_style = nil, default_flow_style = nil, canonical = nil, indent = nil, width = nil, line_break = nil, explicit_start = nil, explicit_end = nil, version = nil, tags = nil) ⇒ Object
-
.add_builtin_type(type_re, &transfer_proc) ⇒ Object
this operation does not make sense in RbYAML (right now).
-
.add_domain_type(domain, type_re, &transfer_proc) ⇒ Object
this operation does not make sense in RbYAML (right now).
-
.add_private_type(type_re, &transfer_proc) ⇒ Object
this operation does not make sense in RbYAML (right now).
-
.add_ruby_type(type_tag, &transfer_proc) ⇒ Object
this operation does not make sense in RbYAML (right now).
-
.detect_implicit(val) ⇒ Object
-
.dump(obj, io = nil) ⇒ Object
-
.dump_stream(*objs) ⇒ Object
-
.each_document(io, &block) ⇒ Object
-
.each_node(io, &doc_proc) ⇒ Object
this operation does not make sense in RbYAML (right now).
-
.load(io) ⇒ Object
-
.load_documents(io, &doc_proc) ⇒ Object
-
.load_file(filepath) ⇒ Object
-
.load_stream(io) ⇒ Object
-
.object_maker(obj_class, val) ⇒ Object
-
.parse(io) ⇒ Object
this operation does not make sense in RbYAML (right now).
-
.parse_documents(io, &doc_proc) ⇒ Object
this operation does not make sense in RbYAML (right now).
-
.parse_file(filepath) ⇒ Object
this operation does not make sense in RbYAML (right now).
-
.quick_emit(oid, opts = {}, &e) ⇒ Object
this operation does not make sense in RbYAML (right now).
-
.read_type_class(type, obj_class) ⇒ Object
-
.tag_class(tag, cls) ⇒ Object
Associates a taguri tag with a Ruby class cls.
-
.tagged_classes ⇒ Object
Returns the complete dictionary of taguris, paired with classes.
-
.transfer(type_id, obj) ⇒ Object
this operation does not make sense in RbYAML (right now).
-
.try_implicit(obj) ⇒ Object
this operation does not make sense in RbYAML (right now).
Class Method Details
._add_constructor(tag, constructor, loader = Loader) ⇒ Object
117
118
119
|
# File 'lib/rbyaml/yaml.rb', line 117
def self._add_constructor(tag, constructor, loader=Loader)
loader.add_constructor(tag, constructor)
end
|
._add_implicit_resolver(tag, regexp, first = nil, loader = Loader, dumper = Dumper) ⇒ Object
107
108
109
110
|
# File 'lib/rbyaml/yaml.rb', line 107
def self._add_implicit_resolver(tag, regexp, first=nil, loader=Loader, dumper=Dumper)
loader.add_implicit_resolver(tag, regexp, first)
dumper.add_implicit_resolver(tag, regexp, first)
end
|
._add_multi_constructor(tag_prefix, multi_constructor, loader = Loader) ⇒ Object
121
122
123
|
# File 'lib/rbyaml/yaml.rb', line 121
def self._add_multi_constructor(tag_prefix, multi_constructor, loader=Loader)
loader.add_multi_constructor(tag_prefix, multi_constructor)
end
|
._add_multi_representer(data_type, multi_representer, dumper = Dumper) ⇒ Object
129
130
131
|
# File 'lib/rbyaml/yaml.rb', line 129
def self._add_multi_representer(data_type, multi_representer, dumper=Dumper)
dumper.add_multi_representer(data_type, multi_representer)
end
|
._add_path_resolver(tag, path, kind = nil, loader = Loader, dumper = Dumper) ⇒ Object
112
113
114
115
|
# File 'lib/rbyaml/yaml.rb', line 112
def self._add_path_resolver(tag, path, kind=nil, loader=Loader, dumper=Dumper)
loader.add_path_resolver(tag, path, kind)
lumper.add_path_resolver(tag, path, kind)
end
|
._add_representer(data_type, representer, dumper = Dumper) ⇒ Object
125
126
127
|
# File 'lib/rbyaml/yaml.rb', line 125
def self._add_representer(data_type, representer, dumper=Dumper)
dumper.add_representer(data_type, representer)
end
|
._compose(stream, loader = Loader) ⇒ Object
23
24
25
26
|
# File 'lib/rbyaml/yaml.rb', line 23
def self._compose(stream, loader=Loader)
l = loader.new(stream)
l.composer.get_node if l.composer.check_node
end
|
._compose_all(stream, loader = Loader) ⇒ Object
28
29
30
31
|
# File 'lib/rbyaml/yaml.rb', line 28
def self._compose_all(stream, loader=Loader)
l = loader.new(stream)
yield l.composer.get_node while l.composer.check_node
end
|
._dump(data, stream = nil, dumper = Dumper, *kwds) ⇒ Object
95
96
97
|
# File 'lib/rbyaml/yaml.rb', line 95
def self._dump(data, stream=nil, dumper=Dumper, *kwds)
_dump_all([data], stream, dumper, *kwds)
end
|
._dump_all(documents, stream = nil, dumper = Dumper, default_style = nil, default_flow_style = nil, canonical = nil, indent = nil, width = nil, line_break = nil, explicit_start = nil, explicit_end = nil, version = nil, tags = nil) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/rbyaml/yaml.rb', line 81
def self._dump_all(documents,stream=nil,dumper=Dumper,default_style=nil,default_flow_style=nil,canonical=nil,indent=nil,width=nil,line_break=nil,explicit_start=nil,explicit_end=nil,version=nil,tags=nil)
if stream.nil?
require 'stringio'
stream = StringIO.new
end
dumper = dumper.new(stream,default_style,default_flow_style,canonical,indent,width,line_break,version,tags,explicit_start,explicit_end)
dumper.serializer.open
for data in documents
dumper.representer.represent(data)
end
dumper.serializer.close
stream.string if StringIO === stream
end
|
._dump_ruby_object(data, dumper = Dumper) ⇒ Object
133
134
135
|
# File 'lib/rbyaml/yaml.rb', line 133
def self._dump_ruby_object(data, dumper=Dumper)
_dump(data,nil,dumper)
end
|
._emit(events, stream = nil, dumper = Dumper, default_style = nil, default_flow_style = nil, canonical = nil, indent = nil, width = nil, line_break = nil) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/rbyaml/yaml.rb', line 51
def self._emit(events, stream=nil, dumper=Dumper,default_style=nil,default_flow_style=nil,canonical=nil, indent=nil, width=nil,line_break=nil)
if stream.nil?
require 'stringio'
stream = StringIO.new
end
dumper = dumper.new(stream,default_style,default_flow_style,canonical,indent,width,line_break)
for event in events
dumper.emit(event)
end
stream.string if StringIO === stream
end
|
._load(stream, loader = Loader) ⇒ Object
38
39
40
41
|
# File 'lib/rbyaml/yaml.rb', line 38
def self._load(stream, loader=Loader)
l = loader.new(stream)
l.constructor.get_data if l.constructor.check_data
end
|
._load_all(stream, loader = Loader) ⇒ Object
33
34
35
36
|
# File 'lib/rbyaml/yaml.rb', line 33
def self._load_all(stream, loader=Loader)
l = loader.new(stream)
yield l.constructor.get_data while l.constructor.check_data
end
|
._parse(stream, loader = Loader) ⇒ Object
18
19
20
21
|
# File 'lib/rbyaml/yaml.rb', line 18
def self._parse(stream, loader=Loader)
l = loader.new(stream)
yield l.parser.get_event while l.parser.check_event
end
|
._safe_dump(data, stream = nil, *kwds) ⇒ Object
103
104
105
|
# File 'lib/rbyaml/yaml.rb', line 103
def self._safe_dump(data, stream=nil, *kwds)
_dump_all([data], stream, SafeDumper, *kwds)
end
|
._safe_dump_all(documents, stream = nil, *kwds) ⇒ Object
99
100
101
|
# File 'lib/rbyaml/yaml.rb', line 99
def self._safe_dump_all(documents, stream=nil, *kwds)
_dump_all(documents, stream, SafeDumper, *kwds)
end
|
._safe_load(stream) ⇒ Object
47
48
49
|
# File 'lib/rbyaml/yaml.rb', line 47
def self._safe_load(stream)
_load(stream, SafeLoader)
end
|
._safe_load_all(stream) ⇒ Object
43
44
45
|
# File 'lib/rbyaml/yaml.rb', line 43
def self._safe_load_all(stream)
_load_all(stream, SafeLoader)
end
|
._scan(stream, loader = Loader) ⇒ Object
13
14
15
16
|
# File 'lib/rbyaml/yaml.rb', line 13
def self._scan(stream, loader=Loader)
l = loader.new(stream)
yield l.scanner.get_token while l.scanner.check_token
end
|
._serialize(node, stream = nil, dumper = Dumper, *kwds) ⇒ Object
77
78
79
|
# File 'lib/rbyaml/yaml.rb', line 77
def self._serialize(node, stream=nil, dumper=Dumper, *kwds)
_serialize_all([node], stream, dumper, *kwds)
end
|
._serialize_all(nodes, stream = nil, dumper = Dumper, default_style = nil, default_flow_style = nil, canonical = nil, indent = nil, width = nil, line_break = nil, explicit_start = nil, explicit_end = nil, version = nil, tags = nil) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/rbyaml/yaml.rb', line 63
def self._serialize_all(nodes,stream=nil,dumper=Dumper,default_style=nil,default_flow_style=nil,canonical=nil,indent=nil,width=nil,line_break=nil,explicit_start=nil,explicit_end=nil,version=nil,tags=nil)
if stream.nil?
require 'stringio'
stream = StringIO.new
end
dumper = dumper.new(stream,default_style,default_flow_style,canonical,indent,width,line_break,version,tags,explicit_start,explicit_end)
dumper.serializer.open
for node in nodes
dumper.serializer.serialize(node)
end
dumper.serializer.close
stream.string if StringIO === stream
end
|
.add_builtin_type(type_re, &transfer_proc) ⇒ Object
this operation does not make sense in RbYAML (right now)
72
73
74
|
# File 'lib/rbyaml.rb', line 72
def self.add_builtin_type( type_re, &transfer_proc )
end
|
.add_domain_type(domain, type_re, &transfer_proc) ⇒ Object
this operation does not make sense in RbYAML (right now)
67
68
69
|
# File 'lib/rbyaml.rb', line 67
def self.add_domain_type( domain, type_re, &transfer_proc )
end
|
.add_private_type(type_re, &transfer_proc) ⇒ Object
this operation does not make sense in RbYAML (right now)
82
83
84
|
# File 'lib/rbyaml.rb', line 82
def self.add_private_type( type_re, &transfer_proc )
end
|
.add_ruby_type(type_tag, &transfer_proc) ⇒ Object
this operation does not make sense in RbYAML (right now)
77
78
79
|
# File 'lib/rbyaml.rb', line 77
def self.add_ruby_type( type_tag, &transfer_proc )
end
|
.detect_implicit(val) ⇒ Object
86
87
88
|
# File 'lib/rbyaml.rb', line 86
def self.detect_implicit( val )
SimpleDetector.detect(val)
end
|
.dump(obj, io = nil) ⇒ Object
5
6
7
|
# File 'lib/rbyaml.rb', line 5
def self.dump(obj, io = nil)
_dump(obj,io)
end
|
.dump_stream(*objs) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/rbyaml.rb', line 58
def self.dump_stream( *objs )
d = RbYAML::Stream.new
objs.each do |doc|
d.add( doc )
end
d.emit
end
|
.each_document(io, &block) ⇒ Object
31
32
33
|
# File 'lib/rbyaml.rb', line 31
def self.each_document( io, &block )
_load_all(io,&block)
end
|
.each_node(io, &doc_proc) ⇒ Object
this operation does not make sense in RbYAML (right now)
40
41
42
|
# File 'lib/rbyaml.rb', line 40
def self.each_node( io, &doc_proc )
end
|
9
10
11
|
# File 'lib/rbyaml.rb', line 9
def self.load( io )
_load(io)
end
|
.load_documents(io, &doc_proc) ⇒ Object
35
36
37
|
# File 'lib/rbyaml.rb', line 35
def self.load_documents( io, &doc_proc )
each_document( io, &doc_proc )
end
|
.load_file(filepath) ⇒ Object
13
14
15
16
17
|
# File 'lib/rbyaml.rb', line 13
def self.load_file( filepath )
File.open( filepath ) do |f|
load( f )
end
end
|
.load_stream(io) ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/rbyaml.rb', line 49
def self.load_stream( io )
d = nil
load_documents(io) { |doc|
d = Stream.new( nil ) if not d
d.add( doc )
}
d
end
|
.object_maker(obj_class, val) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/rbyaml.rb', line 106
def self.object_maker( obj_class, val )
if Hash === val
o = obj_class.allocate
val.each_pair { |k,v|
o.instance_variable_set("@#{k}", v)
}
o
else
raise YAMLError, "Invalid object explicitly tagged !ruby/Object: " + val.inspect
end
end
|
.parse(io) ⇒ Object
this operation does not make sense in RbYAML (right now)
20
21
22
|
# File 'lib/rbyaml.rb', line 20
def self.parse( io )
end
|
.parse_documents(io, &doc_proc) ⇒ Object
this operation does not make sense in RbYAML (right now)
45
46
47
|
# File 'lib/rbyaml.rb', line 45
def self.parse_documents( io, &doc_proc )
end
|
.parse_file(filepath) ⇒ Object
this operation does not make sense in RbYAML (right now)
25
26
27
28
29
|
# File 'lib/rbyaml.rb', line 25
def self.parse_file( filepath )
end
|
.quick_emit(oid, opts = {}, &e) ⇒ Object
this operation does not make sense in RbYAML (right now)
119
120
|
# File 'lib/rbyaml.rb', line 119
def self.quick_emit( oid, opts = {}, &e )
end
|
.read_type_class(type, obj_class) ⇒ Object
100
101
102
103
104
|
# File 'lib/rbyaml.rb', line 100
def self.read_type_class( type, obj_class )
scheme, domain, type, tclass = type.split( ':', 4 )
tclass.split( "::" ).each { |c| obj_class = obj_class.const_get( c ) } if tclass
return [ type, obj_class ]
end
|
.tag_class(tag, cls) ⇒ Object
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
148
149
150
151
152
153
|
# File 'lib/rbyaml.rb', line 148
def self.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
|
.tagged_classes ⇒ Object
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
161
162
163
|
# File 'lib/rbyaml.rb', line 161
def self.tagged_classes
@@tagged_classes
end
|
.transfer(type_id, obj) ⇒ Object
this operation does not make sense in RbYAML (right now)
91
92
93
|
# File 'lib/rbyaml.rb', line 91
def self.transfer( type_id, obj )
end
|
.try_implicit(obj) ⇒ Object
this operation does not make sense in RbYAML (right now)
96
97
98
|
# File 'lib/rbyaml.rb', line 96
def self.try_implicit( obj )
end
|