jvyaml 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest.txt +19 -0
- data/README.txt +7 -0
- data/Rakefile +9 -0
- data/lib/jvyaml.rb +493 -0
- data/lib/jvyaml/store.rb +29 -0
- data/lib/jvyaml/syck.rb +9 -0
- data/lib/jvyaml_internal.jar +0 -0
- data/lib/jvyamlb.jar +0 -0
- data/rakelib/compile.rake +23 -0
- data/rakelib/package.rake +27 -0
- data/rakelib/test.rake +3 -0
- data/src/java/JvyamlInternalService.java +14 -0
- data/src/java/org/jruby/ext/jvyaml/JRubyConstructor.java +679 -0
- data/src/java/org/jruby/ext/jvyaml/JRubyRepresenter.java +194 -0
- data/src/java/org/jruby/ext/jvyaml/JRubySerializer.java +25 -0
- data/src/java/org/jruby/ext/jvyaml/RubyYAML.java +679 -0
- data/test/test_yaml_one.rb +516 -0
- data/test/test_yaml_three.rb +98 -0
- data/test/test_yaml_two.rb +1277 -0
- metadata +77 -0
data/Manifest.txt
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Manifest.txt
|
|
2
|
+
README.txt
|
|
3
|
+
Rakefile
|
|
4
|
+
lib/jvyaml.rb
|
|
5
|
+
lib/jvyaml/store.rb
|
|
6
|
+
lib/jvyaml/syck.rb
|
|
7
|
+
lib/jvyamlb.jar
|
|
8
|
+
lib/jvyaml_internal.jar
|
|
9
|
+
test/test_yaml_one.rb
|
|
10
|
+
test/test_yaml_three.rb
|
|
11
|
+
test/test_yaml_two.rb
|
|
12
|
+
src/java/JvyamlInternalService.java
|
|
13
|
+
src/java/org/jruby/ext/jvyaml/JRubyConstructor.java
|
|
14
|
+
src/java/org/jruby/ext/jvyaml/JRubyRepresenter.java
|
|
15
|
+
src/java/org/jruby/ext/jvyaml/JRubySerializer.java
|
|
16
|
+
src/java/org/jruby/ext/jvyaml/RubyYAML.java
|
|
17
|
+
rakelib/compile.rake
|
|
18
|
+
rakelib/package.rake
|
|
19
|
+
rakelib/test.rake
|
data/README.txt
ADDED
data/Rakefile
ADDED
data/lib/jvyaml.rb
ADDED
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
require 'java' #needed for the module JavaUtilities, which JavaEmbedUtils have a dependency on
|
|
2
|
+
require 'date'
|
|
3
|
+
require 'jvyamlb.jar' # add Java library to path
|
|
4
|
+
require 'jvyaml_internal'
|
|
5
|
+
|
|
6
|
+
class Java::OrgJrubyExtJvyaml::JRubyRepresenter
|
|
7
|
+
def kind_of?(other)
|
|
8
|
+
if other == JvYAML::Emitter
|
|
9
|
+
return true
|
|
10
|
+
else
|
|
11
|
+
super
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
module JvYAML
|
|
17
|
+
#
|
|
18
|
+
# Default settings
|
|
19
|
+
#
|
|
20
|
+
DEFAULTS = {
|
|
21
|
+
:Indent => 2, :UseHeader => false, :UseVersion => false, :Version => '1.0',
|
|
22
|
+
:SortKeys => false, :AnchorFormat => 'id%03d', :ExplicitTypes => false,
|
|
23
|
+
:WidthType => 'absolute', :BestWidth => 80,
|
|
24
|
+
:UseBlock => false, :UseFold => false, :Encoding => :None
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class Error < StandardError; end
|
|
28
|
+
|
|
29
|
+
def self.parse(obj)
|
|
30
|
+
::JvYAML::JvYAMLi::Node::from_internal(::JvYAML::_parse_internal(obj)) || false
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def JvYAML.parse_file( filepath )
|
|
34
|
+
File.open( filepath ) do |f|
|
|
35
|
+
parse( f )
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.add_domain_type(*args)
|
|
40
|
+
warn "JvYAML::add_domain_type isn't supported in JvYAML"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.parse_documents(*args)
|
|
44
|
+
warn "JvYAML::parse_documents isn't supported in JvYAML"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class Proxy
|
|
48
|
+
def initialize(v)
|
|
49
|
+
@value = v
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def transform
|
|
53
|
+
@value
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
class YPath
|
|
58
|
+
def self.each_path(*args)
|
|
59
|
+
warn "JvYAML::YPath.each_path isn't supported in JvYAML"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
class Emitter
|
|
64
|
+
def initialize
|
|
65
|
+
@out = ::JvYAML::JvYAMLi::Out.new self
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def reset(opts)
|
|
69
|
+
@opts = opts
|
|
70
|
+
self
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def emit(oid, &proc)
|
|
74
|
+
proc.call(@out)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def has_key?(key)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
class Object
|
|
82
|
+
attr_accessor :class, :ivars
|
|
83
|
+
def initialize(cl, iv)
|
|
84
|
+
@class, @ivars = cl, iv
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def to_jvyaml( opts = {} )
|
|
88
|
+
JvYAML::quick_emit( object_id, opts ) do |out|
|
|
89
|
+
out.map( "tag:ruby.yaml.org,2002:object:#{ @class }", to_jvyaml_style ) do |map|
|
|
90
|
+
@ivars.each do |k,v|
|
|
91
|
+
map.add( k, v )
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def JvYAML.emitter; Emitter.new; end
|
|
99
|
+
|
|
100
|
+
#
|
|
101
|
+
# Allocate an Emitter if needed
|
|
102
|
+
#
|
|
103
|
+
def JvYAML.quick_emit( oid, opts = {}, &e )
|
|
104
|
+
out =
|
|
105
|
+
if opts.is_a? JvYAML::Emitter
|
|
106
|
+
opts
|
|
107
|
+
else
|
|
108
|
+
emitter.reset( opts )
|
|
109
|
+
end
|
|
110
|
+
out.emit( oid, &e )
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
module JvYAMLi
|
|
114
|
+
class Out
|
|
115
|
+
attr_accessor :emitter
|
|
116
|
+
|
|
117
|
+
def initialize(emitter)
|
|
118
|
+
@emitter = emitter
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def map(type_id, style = nil)
|
|
122
|
+
map = Map.new(type_id, {}, style)
|
|
123
|
+
yield map
|
|
124
|
+
map.to_s
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def seq(type_id, style = nil)
|
|
128
|
+
seq = Seq.new(type_id, [], style)
|
|
129
|
+
yield seq
|
|
130
|
+
seq
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def scalar(type_id, str, style = nil)
|
|
134
|
+
Scalar.new(type_id, str, style)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
class Node
|
|
139
|
+
attr_accessor :value
|
|
140
|
+
attr_accessor :style
|
|
141
|
+
attr_accessor :type_id
|
|
142
|
+
|
|
143
|
+
def transform
|
|
144
|
+
org.jruby.ext.jvyaml.JRubyConstructor.new(self, nil).construct_document(to_internal)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def to_str
|
|
148
|
+
JvYAML.dump(self)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def to_s
|
|
152
|
+
JvYAML.dump(self)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def self.from_internal(internal)
|
|
156
|
+
case internal
|
|
157
|
+
when org.jvyamlb.nodes.ScalarNode
|
|
158
|
+
Scalar.new(internal.tag, internal.value, internal.style.chr)
|
|
159
|
+
when org.jvyamlb.nodes.MappingNode
|
|
160
|
+
Map.new(internal.tag, internal.value.inject({}) {|h, obj| h[from_internal(obj[0])] = from_internal(obj[1]); h}, internal.flow_style)
|
|
161
|
+
when org.jvyamlb.nodes.SequenceNode
|
|
162
|
+
Seq.new(internal.tag, internal.value.map {|obj| from_internal(obj)}, internal.flow_style)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
class Scalar < Node
|
|
168
|
+
def initialize(type_id, val, style)
|
|
169
|
+
@kind = :scalar
|
|
170
|
+
self.type_id = type_id
|
|
171
|
+
self.value = val
|
|
172
|
+
self.style = style
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def to_internal
|
|
176
|
+
org.jvyamlb.nodes.ScalarNode.new(self.type_id, org.jruby.util.ByteList.new(self.value.to_java_bytes, false), self.style[0])
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def to_jvyaml_node(repr)
|
|
180
|
+
repr.scalar(self.type_id,self.value,self.style)
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
class Seq < Node
|
|
185
|
+
def initialize(type_id, val, style)
|
|
186
|
+
@kind = :seq
|
|
187
|
+
self.type_id = type_id
|
|
188
|
+
self.value = val
|
|
189
|
+
self.style = style
|
|
190
|
+
end
|
|
191
|
+
def add(v)
|
|
192
|
+
@value << v
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def to_internal
|
|
196
|
+
org.jvyamlb.nodes.SequenceNode.new(self.type_id, self.value.map {|v| v.to_internal }, self.style)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def to_jvyaml_node(repr)
|
|
200
|
+
repr.seq(self.type_id,self.value,self.style)
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
class Map < Node
|
|
205
|
+
def initialize(type_id, val, style)
|
|
206
|
+
@kind = :map
|
|
207
|
+
self.type_id = type_id
|
|
208
|
+
self.value = val
|
|
209
|
+
self.style = style
|
|
210
|
+
end
|
|
211
|
+
def add(k, v)
|
|
212
|
+
@value[k] = v
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def to_internal
|
|
216
|
+
org.jvyamlb.nodes.MappingNode.new(self.type_id, self.value.inject({}) {|h, v| h[v[0].to_internal] = v[1].to_internal ;h }, self.style)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def to_jvyaml_node(repr)
|
|
220
|
+
repr.map(self.type_id,self.value,self.style)
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
#
|
|
226
|
+
# JvYAML::Stream -- for emitting many documents
|
|
227
|
+
#
|
|
228
|
+
class Stream
|
|
229
|
+
include Enumerable
|
|
230
|
+
attr_accessor :documents, :options
|
|
231
|
+
def initialize(opts = {})
|
|
232
|
+
@options = opts
|
|
233
|
+
@documents = []
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def [](i)
|
|
237
|
+
@documents[ i ]
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def add(doc)
|
|
241
|
+
@documents << doc
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def edit(doc_num,doc)
|
|
245
|
+
@documents[ doc_num ] = doc
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def each(&block)
|
|
249
|
+
@documents.each(&block)
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def emit
|
|
253
|
+
JvYAML::dump_all(@documents)
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
#
|
|
258
|
+
# Default private type
|
|
259
|
+
#
|
|
260
|
+
class PrivateType
|
|
261
|
+
def self.tag_subclasses?; false; end
|
|
262
|
+
attr_accessor :type_id, :value
|
|
263
|
+
verbose, $VERBOSE = $VERBOSE, nil
|
|
264
|
+
def initialize( type, val )
|
|
265
|
+
@type_id = type; @value = val
|
|
266
|
+
end
|
|
267
|
+
def to_jvyaml_node(repr)
|
|
268
|
+
@value.to_jvyaml_node(repr)
|
|
269
|
+
end
|
|
270
|
+
ensure
|
|
271
|
+
$VERBOSE = verbose
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
#
|
|
275
|
+
# Convert a type_id to a taguri
|
|
276
|
+
#
|
|
277
|
+
def JvYAML.tagurize( val )
|
|
278
|
+
if /^tag:.*?:.*$/ =~ val.to_s
|
|
279
|
+
val
|
|
280
|
+
elsif /^(.*?)\/(.*)$/ =~ val.to_s
|
|
281
|
+
"tag:#$1.yaml.org,2002:#$2"
|
|
282
|
+
elsif val.kind_of?(Integer)
|
|
283
|
+
val
|
|
284
|
+
else
|
|
285
|
+
"tag:yaml.org,2002:#{val}"
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# From yaml/tag.rb
|
|
290
|
+
# A dictionary of taguris which map to
|
|
291
|
+
# Ruby classes.
|
|
292
|
+
@@tagged_classes = {}
|
|
293
|
+
|
|
294
|
+
#
|
|
295
|
+
# Associates a taguri _tag_ with a Ruby class _cls_. The taguri is used to give types
|
|
296
|
+
# to classes when loading JvYAML. Taguris are of the form:
|
|
297
|
+
#
|
|
298
|
+
# tag:authorityName,date:specific
|
|
299
|
+
#
|
|
300
|
+
# The +authorityName+ is a domain name or email address. The +date+ is the date the type
|
|
301
|
+
# was issued in YYYY or YYYY-MM or YYYY-MM-DD format. The +specific+ is a name for
|
|
302
|
+
# the type being added.
|
|
303
|
+
#
|
|
304
|
+
# For example, built-in JvYAML types have 'yaml.org' as the +authorityName+ and '2002' as the
|
|
305
|
+
# +date+. The +specific+ is simply the name of the type:
|
|
306
|
+
#
|
|
307
|
+
# tag:yaml.org,2002:int
|
|
308
|
+
# tag:yaml.org,2002:float
|
|
309
|
+
# tag:yaml.org,2002:timestamp
|
|
310
|
+
#
|
|
311
|
+
# The domain must be owned by you on the +date+ declared. If you don't own any domains on the
|
|
312
|
+
# date you declare the type, you can simply use an e-mail address.
|
|
313
|
+
#
|
|
314
|
+
# tag:why@ruby-lang.org,2004:notes/personal
|
|
315
|
+
#
|
|
316
|
+
def self.tag_class( tag, cls )
|
|
317
|
+
if @@tagged_classes.has_key? tag
|
|
318
|
+
warn "class #{ @@tagged_classes[tag] } held ownership of the #{ tag } tag"
|
|
319
|
+
end
|
|
320
|
+
@@tagged_classes[tag] = cls
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# Returns the complete dictionary of taguris, paired with classes. The key for
|
|
324
|
+
# the dictionary is the full taguri. The value for each key is the class constant
|
|
325
|
+
# associated to that taguri.
|
|
326
|
+
#
|
|
327
|
+
# JvYAML.tagged_classes["tag:yaml.org,2002:int"] => Integer
|
|
328
|
+
#
|
|
329
|
+
def self.tagged_classes
|
|
330
|
+
@@tagged_classes
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
# From yaml/tag.rb
|
|
335
|
+
class Module
|
|
336
|
+
# :stopdoc:
|
|
337
|
+
|
|
338
|
+
# Adds a taguri _tag_ to a class, used when dumping or loading the class
|
|
339
|
+
# in JvYAML. See JvYAML::tag_class for detailed information on typing and
|
|
340
|
+
# taguris.
|
|
341
|
+
def jvyaml_as( tag, sc = true )
|
|
342
|
+
verbose, $VERBOSE = $VERBOSE, nil
|
|
343
|
+
class_eval <<-"end;", __FILE__, __LINE__+1
|
|
344
|
+
attr_writer :jv_taguri
|
|
345
|
+
def jv_taguri
|
|
346
|
+
if respond_to? :to_jvyaml_type
|
|
347
|
+
JvYAML::tagurize( to_jvyaml_type[1..-1] )
|
|
348
|
+
else
|
|
349
|
+
return @jv_taguri if defined?(@jv_taguri) and @jv_taguri
|
|
350
|
+
tag = #{ tag.dump }
|
|
351
|
+
if self.class.jvyaml_tag_subclasses? and self.class != JvYAML::tagged_classes[tag]
|
|
352
|
+
tag = "\#{ tag }:\#{ self.class.jvyaml_tag_class_name }"
|
|
353
|
+
end
|
|
354
|
+
tag
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
def self.jvyaml_tag_subclasses?; #{ sc ? 'true' : 'false' }; end
|
|
358
|
+
end;
|
|
359
|
+
JvYAML::tag_class tag, self
|
|
360
|
+
ensure
|
|
361
|
+
$VERBOSE = verbose
|
|
362
|
+
end
|
|
363
|
+
# Transforms the subclass name into a name suitable for display
|
|
364
|
+
# in a subclassed tag.
|
|
365
|
+
def jvyaml_tag_class_name
|
|
366
|
+
self.name
|
|
367
|
+
end
|
|
368
|
+
# Transforms the subclass name found in the tag into a Ruby
|
|
369
|
+
# constant name.
|
|
370
|
+
def jvyaml_tag_read_class( name )
|
|
371
|
+
name
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
Hash::jvyaml_as "tag:ruby.yaml.org,2002:hash"
|
|
376
|
+
Hash::jvyaml_as "tag:yaml.org,2002:map"
|
|
377
|
+
|
|
378
|
+
Array::jvyaml_as "tag:ruby.yaml.org,2002:array"
|
|
379
|
+
Array::jvyaml_as "tag:yaml.org,2002:seq"
|
|
380
|
+
|
|
381
|
+
String::jvyaml_as "tag:ruby.yaml.org,2002:string"
|
|
382
|
+
String::jvyaml_as "tag:yaml.org,2002:binary"
|
|
383
|
+
String::jvyaml_as "tag:yaml.org,2002:str"
|
|
384
|
+
|
|
385
|
+
Range::jvyaml_as "tag:ruby.yaml.org,2002:range"
|
|
386
|
+
|
|
387
|
+
Regexp::jvyaml_as "tag:ruby.yaml.org,2002:regexp"
|
|
388
|
+
|
|
389
|
+
Integer::jvyaml_as "tag:yaml.org,2002:int", false
|
|
390
|
+
|
|
391
|
+
Time::jvyaml_as "tag:ruby.yaml.org,2002:time"
|
|
392
|
+
Time::jvyaml_as "tag:yaml.org,2002:timestamp"
|
|
393
|
+
|
|
394
|
+
Date::jvyaml_as "tag:yaml.org,2002:timestamp#ymd"
|
|
395
|
+
|
|
396
|
+
Float::jvyaml_as "tag:yaml.org,2002:float"
|
|
397
|
+
|
|
398
|
+
NilClass::jvyaml_as "tag:yaml.org,2002:null"
|
|
399
|
+
|
|
400
|
+
JvYAML::tag_class "tag:yaml.org,2002:bool#yes", TrueClass
|
|
401
|
+
JvYAML::tag_class "tag:yaml.org,2002:bool#no", FalseClass
|
|
402
|
+
JvYAML::tag_class "tag:ruby.yaml.org,2002:object", Object
|
|
403
|
+
JvYAML::tag_class "tag:ruby.yaml.org,2002:exception", Exception
|
|
404
|
+
JvYAML::tag_class "tag:ruby.yaml.org,2002:struct", Struct
|
|
405
|
+
JvYAML::tag_class "tag:ruby.yaml.org,2002:symbol", Symbol
|
|
406
|
+
JvYAML::tag_class "tag:ruby.yaml.org,2002:sym", Symbol
|
|
407
|
+
|
|
408
|
+
# From yaml/types.rb
|
|
409
|
+
module JvYAML
|
|
410
|
+
#
|
|
411
|
+
# Builtin collection: !omap
|
|
412
|
+
#
|
|
413
|
+
class Omap < ::Array
|
|
414
|
+
jvyaml_as "tag:yaml.org,2002:omap"
|
|
415
|
+
def self.[]( *vals )
|
|
416
|
+
o = Omap.new
|
|
417
|
+
0.step( vals.length - 1, 2 ) do |i|
|
|
418
|
+
o[vals[i]] = vals[i+1]
|
|
419
|
+
end
|
|
420
|
+
o
|
|
421
|
+
end
|
|
422
|
+
def []( k )
|
|
423
|
+
self.assoc( k ).to_a[1]
|
|
424
|
+
end
|
|
425
|
+
def []=( k, *rest )
|
|
426
|
+
val, set = rest.reverse
|
|
427
|
+
if ( tmp = self.assoc( k ) ) and not set
|
|
428
|
+
tmp[1] = val
|
|
429
|
+
else
|
|
430
|
+
self << [ k, val ]
|
|
431
|
+
end
|
|
432
|
+
val
|
|
433
|
+
end
|
|
434
|
+
def has_key?( k )
|
|
435
|
+
self.assoc( k ) ? true : false
|
|
436
|
+
end
|
|
437
|
+
def is_complex_jvyaml?
|
|
438
|
+
true
|
|
439
|
+
end
|
|
440
|
+
def to_jvyaml_node(repr)
|
|
441
|
+
sequ = []
|
|
442
|
+
self.each do |v|
|
|
443
|
+
sequ << Hash[ *v ]
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
repr.seq(jv_taguri,sequ,to_jvyaml_style)
|
|
447
|
+
end
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
#
|
|
452
|
+
# Builtin collection: !pairs
|
|
453
|
+
#
|
|
454
|
+
class Pairs < ::Array
|
|
455
|
+
jvyaml_as "tag:yaml.org,2002:pairs"
|
|
456
|
+
def self.[]( *vals )
|
|
457
|
+
p = Pairs.new
|
|
458
|
+
0.step( vals.length - 1, 2 ) { |i|
|
|
459
|
+
p[vals[i]] = vals[i+1]
|
|
460
|
+
}
|
|
461
|
+
p
|
|
462
|
+
end
|
|
463
|
+
def []( k )
|
|
464
|
+
self.assoc( k ).to_a
|
|
465
|
+
end
|
|
466
|
+
def []=( k, val )
|
|
467
|
+
self << [ k, val ]
|
|
468
|
+
val
|
|
469
|
+
end
|
|
470
|
+
def has_key?( k )
|
|
471
|
+
self.assoc( k ) ? true : false
|
|
472
|
+
end
|
|
473
|
+
def is_complex_jvyaml?
|
|
474
|
+
true
|
|
475
|
+
end
|
|
476
|
+
def to_jvyaml_node(repr)
|
|
477
|
+
sequ = []
|
|
478
|
+
self.each do |v|
|
|
479
|
+
sequ << Hash[ *v ]
|
|
480
|
+
end
|
|
481
|
+
repr.seq(jv_taguri,sequ,to_jvyaml_style)
|
|
482
|
+
end
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
#
|
|
486
|
+
# Builtin collection: !set
|
|
487
|
+
#
|
|
488
|
+
class Set < ::Hash
|
|
489
|
+
jvyaml_as "tag:yaml.org,2002:set"
|
|
490
|
+
end
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
require 'jvyaml/syck'
|