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.
@@ -0,0 +1,194 @@
1
+ /*
2
+ * See LICENSE file in distribution for copyright and licensing information.
3
+ */
4
+ package org.jruby.ext.jvyaml;
5
+
6
+ import java.io.IOException;
7
+ import java.io.ByteArrayInputStream;
8
+
9
+ import java.util.Iterator;
10
+ import java.util.Map;
11
+ import java.util.HashMap;
12
+
13
+ import org.jruby.Ruby;
14
+ import org.jruby.RubyClass;
15
+ import org.jruby.RubyModule;
16
+ import org.jruby.RubyHash;
17
+ import org.jruby.RubyArray;
18
+ import org.jruby.RubyString;
19
+ import org.jruby.runtime.builtin.IRubyObject;
20
+
21
+ import org.jruby.javasupport.JavaEmbedUtils;
22
+
23
+ import org.jruby.runtime.ThreadContext;
24
+ import org.jvyamlb.SafeRepresenterImpl;
25
+ import org.jvyamlb.Serializer;
26
+ import org.jvyamlb.Representer;
27
+ import org.jvyamlb.YAMLConfig;
28
+ import org.jvyamlb.YAMLNodeCreator;
29
+ import org.jvyamlb.Representer;
30
+ import org.jvyamlb.Constructor;
31
+ import org.jvyamlb.ParserImpl;
32
+ import org.jvyamlb.Scanner;
33
+ import org.jvyamlb.ScannerImpl;
34
+ import org.jvyamlb.Composer;
35
+ import org.jvyamlb.ComposerImpl;
36
+ import org.jvyamlb.PositioningScannerImpl;
37
+ import org.jvyamlb.PositioningComposerImpl;
38
+ import org.jvyamlb.Serializer;
39
+ import org.jvyamlb.Resolver;
40
+ import org.jvyamlb.ResolverImpl;
41
+ import org.jvyamlb.EmitterImpl;
42
+ import org.jvyamlb.exceptions.YAMLException;
43
+ import org.jvyamlb.YAMLConfig;
44
+ import org.jvyamlb.YAML;
45
+ import org.jvyamlb.PositioningScanner;
46
+ import org.jvyamlb.Positionable;
47
+ import org.jvyamlb.Position;
48
+ import org.jvyamlb.nodes.Node;
49
+ import org.jvyamlb.nodes.ScalarNode;
50
+ import org.jvyamlb.nodes.MappingNode;
51
+
52
+ import org.jruby.util.ByteList;
53
+
54
+ /**
55
+ * @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
56
+ */
57
+ public class JRubyRepresenter extends SafeRepresenterImpl {
58
+ public JRubyRepresenter(final Serializer serializer, final YAMLConfig opts) {
59
+ super(serializer,opts);
60
+ }
61
+
62
+ @Override
63
+ protected YAMLNodeCreator getNodeCreatorFor(final Object data) {
64
+ if(data instanceof YAMLNodeCreator) {
65
+ return (YAMLNodeCreator)data;
66
+ } else if(data instanceof IRubyObject) {
67
+ return new IRubyObjectYAMLNodeCreator(data);
68
+ } else {
69
+ return super.getNodeCreatorFor(data);
70
+ }
71
+ }
72
+
73
+ public Node map(String tag, java.util.Map mapping, Object flowStyle) throws IOException {
74
+ if(null == flowStyle) {
75
+ return map(tag,mapping,false);
76
+ } else {
77
+ return map(tag,mapping,true);
78
+ }
79
+ }
80
+ public Node seq(String tag, java.util.List sequence, Object flowStyle) throws IOException {
81
+ if(sequence instanceof RubyArray) {
82
+ sequence = ((RubyArray)sequence).getList();
83
+ }
84
+
85
+ if(null == flowStyle) {
86
+ return seq(tag,sequence,false);
87
+ } else {
88
+ return seq(tag,sequence,true);
89
+ }
90
+ }
91
+
92
+ public Node scalar(String tag, String val, String style) throws IOException {
93
+ return scalar(tag, ByteList.create(val), style);
94
+ }
95
+
96
+ public Node scalar(String tag, ByteList val, String style) throws IOException {
97
+ if(null == style || style.length() == 0) {
98
+ return scalar(tag,val,(char)0);
99
+ } else {
100
+ return scalar(tag,val,style.charAt(0));
101
+ }
102
+ }
103
+
104
+ @Override
105
+ public Node representMapping(final String tag, final Map mapping, final boolean flowStyle) throws IOException {
106
+ Map value = new HashMap();
107
+ final Iterator iter = (mapping instanceof RubyHash) ? ((RubyHash)mapping).directEntrySet().iterator() : mapping.entrySet().iterator();
108
+ while(iter.hasNext()) {
109
+ Map.Entry entry = (Map.Entry)iter.next();
110
+ value.put(representData(entry.getKey()),representData(entry.getValue()));
111
+ }
112
+ return new MappingNode(tag,value,flowStyle);
113
+ }
114
+
115
+ @Override
116
+ protected boolean ignoreAliases(final Object data) {
117
+ return (data instanceof IRubyObject && ((IRubyObject)data).isNil()) || super.ignoreAliases(data);
118
+ }
119
+
120
+ public static class IRubyObjectYAMLNodeCreator implements YAMLNodeCreator {
121
+ private final IRubyObject data;
122
+ private final RubyClass outClass;
123
+ private final RubyModule YAMLModule;
124
+
125
+ public IRubyObjectYAMLNodeCreator(final Object data) {
126
+ this.data = (IRubyObject)data;
127
+ this.YAMLModule = (RubyModule)this.data.getRuntime().getModule("JvYAML");
128
+ this.outClass = ((RubyClass)((RubyModule)(YAMLModule.getConstant("JvYAMLi"))).getConstant("Node"));
129
+ }
130
+
131
+ public String taguri() {
132
+ return data.callMethod(data.getRuntime().getCurrentContext(), "taguri").toString();
133
+ }
134
+
135
+ public Node toYamlNode(final Representer representer) throws IOException {
136
+ Ruby runtime = data.getRuntime();
137
+ ThreadContext context = runtime.getCurrentContext();
138
+
139
+ if(data.getMetaClass().searchMethod("to_jvyaml") == YAMLModule.dataGetStruct() ||
140
+ data.getMetaClass().searchMethod("to_jvyaml").isUndefined() // In this case, hope that it works out correctly when calling to_yaml_node. Rails does this.
141
+ ) {
142
+ // to_yaml have not been overridden
143
+ Object val = data.callMethod(context, "to_jvyaml_node", JavaEmbedUtils.javaToRuby(runtime, representer));
144
+ if(val instanceof Node) {
145
+ return (Node)val;
146
+ } else if(val instanceof IRubyObject) {
147
+ return (Node)JavaEmbedUtils.rubyToJava((IRubyObject) val);
148
+ }
149
+ } else {
150
+ IRubyObject val = data.callMethod(context, "to_jvyaml", JavaEmbedUtils.javaToRuby(runtime, representer));
151
+
152
+ if(!outClass.isInstance(val)) {
153
+ if(val instanceof RubyString && ((RubyString)val).getByteList().length() > 4) {
154
+ IRubyObject newObj = RubyYAML.load(data, val);
155
+ if(newObj instanceof RubyHash) {
156
+ return ((JRubyRepresenter)representer).map(YAML.DEFAULT_MAPPING_TAG, (RubyHash)newObj, null);
157
+ } else if(newObj instanceof RubyArray) {
158
+ return ((JRubyRepresenter)representer).seq(YAML.DEFAULT_SEQUENCE_TAG, (RubyArray)newObj, null);
159
+ } else {
160
+ ByteList bl = ((RubyString)val).getByteList();
161
+ int subst = 4;
162
+ if(bl.get(4) == '\n') subst++;
163
+ int len = (bl.length()-subst)-1;
164
+ Resolver res = new ResolverImpl();
165
+ res.descendResolver(null, null);
166
+ String detectedTag = res.resolve(ScalarNode.class,bl.makeShared(subst, len),new boolean[]{true,false});
167
+ return ((JRubyRepresenter)representer).scalar(detectedTag, bl.makeShared(subst, len), null);
168
+ }
169
+ }
170
+
171
+ throw runtime.newTypeError("wrong argument type " + val.getMetaClass().getRealClass() + " (expected JvYAML::JvYAMLi::Node)");
172
+ } else {
173
+ IRubyObject value = val.callMethod(context, "value");
174
+ IRubyObject style = val.callMethod(context, "style");
175
+ IRubyObject type_id = val.callMethod(context, "type_id");
176
+ String s = null;
177
+ if(!style.isNil()) {
178
+ s = style.toString();
179
+ }
180
+ String t = type_id.toString();
181
+ if(value instanceof RubyHash) {
182
+ return ((JRubyRepresenter)representer).map(t, (RubyHash)value, s);
183
+ } else if(value instanceof RubyArray) {
184
+ return ((JRubyRepresenter)representer).seq(t, (RubyArray)value, s);
185
+ } else {
186
+ return ((JRubyRepresenter)representer).scalar(t, ((RubyString)value).getByteList(), s);
187
+ }
188
+ }
189
+ }
190
+
191
+ return null;
192
+ }
193
+ }
194
+ }// JRubyRepresenter
@@ -0,0 +1,25 @@
1
+ /*
2
+ * See LICENSE file in distribution for copyright and licensing information.
3
+ */
4
+ package org.jruby.ext.jvyaml;
5
+
6
+ import org.jvyamlb.SerializerImpl;
7
+ import org.jvyamlb.Emitter;
8
+ import org.jvyamlb.Resolver;
9
+ import org.jvyamlb.YAMLConfig;
10
+
11
+ import org.jvyamlb.nodes.Node;
12
+ import org.jvyamlb.nodes.CollectionNode;
13
+
14
+ /**
15
+ * @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
16
+ */
17
+ public class JRubySerializer extends SerializerImpl {
18
+ public JRubySerializer(Emitter emitter, Resolver resolver, YAMLConfig opts) {
19
+ super(emitter,resolver,opts);
20
+ }
21
+
22
+ protected boolean ignoreAnchor(Node node) {
23
+ return !(node instanceof CollectionNode);
24
+ }
25
+ }// JRubySerializer
@@ -0,0 +1,679 @@
1
+ /*
2
+ * See LICENSE file in distribution for copyright and licensing information.
3
+ */
4
+ package org.jruby.ext.jvyaml;
5
+
6
+ import java.io.IOException;
7
+
8
+ import java.util.Iterator;
9
+ import java.util.List;
10
+ import java.util.Map;
11
+
12
+ import java.util.regex.Pattern;
13
+
14
+
15
+ import org.jruby.Ruby;
16
+ import org.jruby.RubyArray;
17
+ import org.jruby.RubyFixnum;
18
+ import org.jruby.RubyHash;
19
+ import org.jruby.RubyString;
20
+ import org.jruby.RubyClass;
21
+ import org.jruby.RubyModule;
22
+
23
+ import org.jruby.anno.JRubyMethod;
24
+ import org.jruby.anno.JRubyClass;
25
+ import org.jruby.anno.JRubyModule;
26
+
27
+ import org.jruby.runtime.Block;
28
+ import org.jruby.runtime.ThreadContext;
29
+ import org.jruby.runtime.builtin.IRubyObject;
30
+
31
+ import org.jruby.javasupport.JavaEmbedUtils;
32
+
33
+ import org.jruby.javasupport.JavaUtil;
34
+ import org.jruby.javasupport.util.RuntimeHelpers;
35
+ import org.jruby.runtime.Visibility;
36
+
37
+ import org.jruby.util.IOInputStream;
38
+ import org.jruby.util.IOOutputStream;
39
+
40
+ import org.jvyamlb.Representer;
41
+ import org.jvyamlb.Constructor;
42
+ import org.jvyamlb.ParserImpl;
43
+ import org.jvyamlb.PositioningParserImpl;
44
+ import org.jvyamlb.Scanner;
45
+ import org.jvyamlb.ScannerImpl;
46
+ import org.jvyamlb.Composer;
47
+ import org.jvyamlb.ComposerImpl;
48
+ import org.jvyamlb.PositioningScannerImpl;
49
+ import org.jvyamlb.PositioningComposerImpl;
50
+ import org.jvyamlb.Serializer;
51
+ import org.jvyamlb.ResolverImpl;
52
+ import org.jvyamlb.EmitterImpl;
53
+ import org.jvyamlb.exceptions.YAMLException;
54
+ import org.jvyamlb.YAMLConfig;
55
+ import org.jvyamlb.YAML;
56
+ import org.jvyamlb.PositioningScanner;
57
+ import org.jvyamlb.Positionable;
58
+ import org.jvyamlb.Position;
59
+
60
+ /**
61
+ * @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
62
+ */
63
+ @JRubyModule(name="YAML")
64
+ public class RubyYAML {
65
+ public static RubyModule createYAMLModule(Ruby runtime) {
66
+ RubyModule result = runtime.defineModule("JvYAML");
67
+
68
+ runtime.getKernel().callMethod(runtime.getCurrentContext(),"require", runtime.newString("stringio"));
69
+
70
+ result.defineAnnotatedMethods(RubyYAML.class);
71
+
72
+ RubyClass obj = runtime.getObject();
73
+ RubyClass clazz = runtime.getClassClass();
74
+ RubyClass hash = runtime.getHash();
75
+ RubyClass array = runtime.getArray();
76
+ RubyClass struct = runtime.getStructClass();
77
+ RubyClass exception = runtime.getException();
78
+ RubyClass string = runtime.getString();
79
+ RubyClass symbol = runtime.getSymbol();
80
+ RubyClass range = runtime.getRange();
81
+ RubyClass regexp = runtime.getRegexp();
82
+ RubyClass time = runtime.getTime();
83
+ RubyClass date = runtime.fastGetClass("Date");
84
+ RubyClass fixnum = runtime.getFixnum();
85
+ RubyClass bignum = runtime.getBignum();
86
+ RubyClass flt = runtime.getFloat();
87
+ RubyClass trueClass = runtime.getTrueClass();
88
+ RubyClass falseClass = runtime.getFalseClass();
89
+ RubyClass nilClass = runtime.getNilClass();
90
+
91
+ clazz.defineAnnotatedMethods(YAMLClassMethods.class);
92
+
93
+ obj.defineAnnotatedMethods(YAMLObjectMethods.class);
94
+
95
+ hash.defineAnnotatedMethods(YAMLHashMethods.class);
96
+
97
+ array.defineAnnotatedMethods(YAMLArrayMethods.class);
98
+
99
+ struct.defineAnnotatedMethods(YAMLStructMethods.class);
100
+
101
+ exception.defineAnnotatedMethods(YAMLExceptionMethods.class);
102
+
103
+ string.defineAnnotatedMethods(YAMLStringMethods.class);
104
+
105
+ symbol.defineAnnotatedMethods(YAMLSymbolMethods.class);
106
+
107
+ range.defineAnnotatedMethods(YAMLRangeMethods.class);
108
+
109
+ regexp.defineAnnotatedMethods(YAMLRegexpMethods.class);
110
+
111
+ time.defineAnnotatedMethods(YAMLTimeMethods.class);
112
+
113
+ date.defineAnnotatedMethods(YAMLDateMethods.class);
114
+
115
+ bignum.defineAnnotatedMethods(YAMLNumericMethods.class);
116
+
117
+ fixnum.defineAnnotatedMethods(YAMLNumericMethods.class);
118
+
119
+ flt.defineAnnotatedMethods(YAMLNumericMethods.class);
120
+
121
+ trueClass.defineAnnotatedMethods(YAMLTrueMethods.class);
122
+
123
+ falseClass.defineAnnotatedMethods(YAMLFalseMethods.class);
124
+
125
+ nilClass.defineAnnotatedMethods(YAMLNilMethods.class);
126
+
127
+ result.dataWrapStruct(runtime.getObject().searchMethod("to_jvyaml"));
128
+
129
+ return result;
130
+ }
131
+
132
+ @JRubyMethod(name = "dump", module = true, visibility = Visibility.PRIVATE)
133
+ public static IRubyObject dump(IRubyObject self, IRubyObject arg0) {
134
+ Ruby runtime = self.getRuntime();
135
+ IRubyObject val = runtime.newArray(arg0);
136
+ return self.callMethod(runtime.getCurrentContext(),"dump_all", val);
137
+ }
138
+
139
+ @JRubyMethod(name = "dump", module = true, visibility = Visibility.PRIVATE)
140
+ public static IRubyObject dump(IRubyObject self, IRubyObject arg0, IRubyObject arg1) {
141
+ IRubyObject obj = arg0;
142
+ Ruby runtime = self.getRuntime();
143
+ IRubyObject val = runtime.newArray(obj);
144
+ return RuntimeHelpers.invoke(runtime.getCurrentContext(), self,"dump_all", val, arg1);
145
+ }
146
+
147
+ @JRubyMethod(name = "dump_all", required = 1, optional = 1, module = true, visibility = Visibility.PRIVATE)
148
+ public static IRubyObject dump_all(IRubyObject self, IRubyObject[] args) {
149
+ ThreadContext context = self.getRuntime().getCurrentContext();
150
+ RubyArray objs = (RubyArray)args[0];
151
+ IRubyObject io = null;
152
+ IRubyObject io2 = null;
153
+ if(args.length == 2 && args[1] != null && !args[1].isNil()) {
154
+ io = args[1];
155
+ }
156
+ YAMLConfig cfg = YAML.config().version("1.0");
157
+ IOOutputStream iox = null;
158
+ if(null == io) {
159
+ io2 = self.getRuntime().fastGetClass("StringIO").callMethod(context, "new");
160
+ iox = new IOOutputStream(io2);
161
+ } else {
162
+ iox = new IOOutputStream(io);
163
+ }
164
+ Serializer ser = new JRubySerializer(new EmitterImpl(iox,cfg),new ResolverImpl(),cfg);
165
+ try {
166
+ ser.open();
167
+ Representer r = new JRubyRepresenter(ser, cfg);
168
+ for(Iterator iter = objs.getList().iterator();iter.hasNext();) {
169
+ r.represent(iter.next());
170
+ }
171
+ ser.close();
172
+ } catch(IOException e) {
173
+ throw self.getRuntime().newIOErrorFromException(e);
174
+ }
175
+ if(null == io) {
176
+ io2.callMethod(context, "rewind");
177
+ return io2.callMethod(context, "read");
178
+ } else {
179
+ return io;
180
+ }
181
+ }
182
+
183
+ @JRubyMethod(name = "_parse_internal", required = 1, module = true, visibility = Visibility.PRIVATE)
184
+ public static IRubyObject parse_internal(IRubyObject self, IRubyObject arg) {
185
+ boolean debug = self.getRuntime().getDebug().isTrue();
186
+ IRubyObject io = check_yaml_port(arg);
187
+ Scanner scn = null;
188
+ try {
189
+ if(io instanceof RubyString) {
190
+ scn = debug ? new PositioningScannerImpl(((RubyString)io).getByteList()) : new ScannerImpl(((RubyString)io).getByteList());
191
+ } else {
192
+ scn = debug ? new PositioningScannerImpl(new IOInputStream(io)) : new ScannerImpl(new IOInputStream(io));
193
+ }
194
+ Composer ctor =
195
+ debug ?
196
+ new PositioningComposerImpl(new PositioningParserImpl((PositioningScanner)scn,YAML.config().version("1.0")),new ResolverImpl()) :
197
+ new ComposerImpl(new ParserImpl(scn,YAML.config().version("1.0")),new ResolverImpl())
198
+ ;
199
+ if(ctor.checkNode()) {
200
+ return JavaEmbedUtils.javaToRuby(self.getRuntime(),ctor.getNode());
201
+ }
202
+ return self.getRuntime().getNil();
203
+ } catch(YAMLException e) {
204
+ if(self.getRuntime().getDebug().isTrue()) {
205
+ Position.Range range = ((Positionable)e).getRange();
206
+ throw self.getRuntime().newArgumentError("syntax error on " + range.start + ":" + range.end + ": " + e.getMessage());
207
+ } else {
208
+ throw self.getRuntime().newArgumentError("syntax error:" + e.getMessage());
209
+ }
210
+ }
211
+ }
212
+
213
+ @JRubyMethod(name = "load", required = 1, module = true, visibility = Visibility.PRIVATE)
214
+ public static IRubyObject load(IRubyObject self, IRubyObject arg) {
215
+ boolean debug = self.getRuntime().getDebug().isTrue();
216
+ IRubyObject io = check_yaml_port(arg);
217
+ Scanner scn = null;
218
+ try {
219
+ if(io instanceof RubyString) {
220
+ scn = debug ? new PositioningScannerImpl(((RubyString)io).getByteList()) : new ScannerImpl(((RubyString)io).getByteList());
221
+ } else {
222
+ scn = debug ? new PositioningScannerImpl(new IOInputStream(io)) : new ScannerImpl(new IOInputStream(io));
223
+ }
224
+ Constructor ctor =
225
+ debug ?
226
+ new JRubyConstructor(self, new PositioningComposerImpl(new PositioningParserImpl((PositioningScanner)scn,YAML.config().version("1.0")),new ResolverImpl())) :
227
+ new JRubyConstructor(self, new ComposerImpl(new ParserImpl(scn,YAML.config().version("1.0")),new ResolverImpl()))
228
+ ;
229
+ if(ctor.checkData()) {
230
+ return JavaEmbedUtils.javaToRuby(self.getRuntime(),ctor.getData());
231
+ }
232
+ return self.getRuntime().getNil();
233
+ } catch(YAMLException e) {
234
+ if(self.getRuntime().getDebug().isTrue()) {
235
+ Position.Range range = ((Positionable)e).getRange();
236
+ throw self.getRuntime().newArgumentError("syntax error on " + range.start + ":" + range.end + ": " + e.getMessage());
237
+ } else {
238
+ throw self.getRuntime().newArgumentError("syntax error:" + e.getMessage());
239
+ }
240
+ }
241
+ }
242
+
243
+ @JRubyMethod(name = "load_file", required = 1, module = true, visibility = Visibility.PRIVATE)
244
+ public static IRubyObject load_file(IRubyObject self, IRubyObject arg) {
245
+ Ruby runtime = self.getRuntime();
246
+ ThreadContext context = runtime.getCurrentContext();
247
+ IRubyObject io = RuntimeHelpers.invoke(context, runtime.getFile(),"open", arg, runtime.newString("r"));
248
+ IRubyObject val = self.callMethod(context,"load", io);
249
+ io.callMethod(context, "close");
250
+ return val;
251
+ }
252
+
253
+ @JRubyMethod(name = "each_document", required = 1, frame = true, module = true, visibility = Visibility.PRIVATE)
254
+ public static IRubyObject each_document(IRubyObject self, IRubyObject arg, Block block) {
255
+ boolean debug = self.getRuntime().getDebug().isTrue();
256
+ ThreadContext context = self.getRuntime().getCurrentContext();
257
+ IRubyObject io = arg;
258
+ Scanner scn = null;
259
+ try {
260
+ if(io instanceof RubyString) {
261
+ scn = debug ? new PositioningScannerImpl(((RubyString)io).getByteList()) : new ScannerImpl(((RubyString)io).getByteList());
262
+ } else {
263
+ scn = debug ? new PositioningScannerImpl(new IOInputStream(io)) : new ScannerImpl(new IOInputStream(io));
264
+ }
265
+ Constructor ctor =
266
+ debug ?
267
+ new JRubyConstructor(self, new PositioningComposerImpl(new PositioningParserImpl((PositioningScanner)scn,YAML.config().version("1.0")),new ResolverImpl())) :
268
+ new JRubyConstructor(self, new ComposerImpl(new ParserImpl(scn,YAML.config().version("1.0")),new ResolverImpl()))
269
+ ;
270
+ while(ctor.checkData()) {
271
+ block.yield(context, JavaEmbedUtils.javaToRuby(self.getRuntime(),ctor.getData()));
272
+ }
273
+ return self.getRuntime().getNil();
274
+ } catch(YAMLException e) {
275
+ if(self.getRuntime().getDebug().isTrue()) {
276
+ Position.Range range = ((Positionable)e).getRange();
277
+ throw self.getRuntime().newArgumentError("syntax error on " + range.start + ":" + range.end + ": " + e.getMessage());
278
+ } else {
279
+ throw self.getRuntime().newArgumentError("syntax error:" + e.getMessage());
280
+ }
281
+ }
282
+ }
283
+
284
+ @JRubyMethod(name = "load_documents", required = 1, frame = true, module = true, visibility = Visibility.PRIVATE)
285
+ public static IRubyObject load_documents(IRubyObject self, IRubyObject arg, Block block) {
286
+ boolean debug = self.getRuntime().getDebug().isTrue();
287
+ ThreadContext context = self.getRuntime().getCurrentContext();
288
+ IRubyObject io = check_yaml_port(arg);
289
+ Scanner scn = null;
290
+ try {
291
+ if(io instanceof RubyString) {
292
+ scn = debug ? new PositioningScannerImpl(((RubyString)io).getByteList()) : new ScannerImpl(((RubyString)io).getByteList());
293
+ } else {
294
+ scn = debug ? new PositioningScannerImpl(new IOInputStream(io)) : new ScannerImpl(new IOInputStream(io));
295
+ }
296
+ Constructor ctor =
297
+ debug ?
298
+ new JRubyConstructor(self, new PositioningComposerImpl(new PositioningParserImpl((PositioningScanner)scn,YAML.config().version("1.0")),new ResolverImpl())) :
299
+ new JRubyConstructor(self, new ComposerImpl(new ParserImpl(scn,YAML.config().version("1.0")),new ResolverImpl()))
300
+ ;
301
+ while(ctor.checkData()) {
302
+ block.yield(context, JavaEmbedUtils.javaToRuby(self.getRuntime(),ctor.getData()));
303
+ }
304
+ return self.getRuntime().getNil();
305
+ } catch(YAMLException e) {
306
+ if(self.getRuntime().getDebug().isTrue()) {
307
+ Position.Range range = ((Positionable)e).getRange();
308
+ throw self.getRuntime().newArgumentError("syntax error on " + range.start + ":" + range.end + ": " + e.getMessage());
309
+ } else {
310
+ throw self.getRuntime().newArgumentError("syntax error:" + e.getMessage());
311
+ }
312
+ }
313
+ }
314
+
315
+ @JRubyMethod(name = "load_stream", required = 1, module = true, visibility = Visibility.PRIVATE)
316
+ public static IRubyObject load_stream(IRubyObject self, IRubyObject arg) {
317
+ boolean debug = self.getRuntime().getDebug().isTrue();
318
+ ThreadContext context = self.getRuntime().getCurrentContext();
319
+ IRubyObject d = self.getRuntime().getNil();
320
+ IRubyObject io = arg;
321
+ Scanner scn = null;
322
+ try {
323
+ if(io instanceof RubyString) {
324
+ scn = debug ? new PositioningScannerImpl(((RubyString)io).getByteList()) : new ScannerImpl(((RubyString)io).getByteList());
325
+ } else {
326
+ scn = debug ? new PositioningScannerImpl(new IOInputStream(io)) : new ScannerImpl(new IOInputStream(io));
327
+ }
328
+ Constructor ctor =
329
+ debug ?
330
+ new JRubyConstructor(self, new PositioningComposerImpl(new PositioningParserImpl((PositioningScanner)scn,YAML.config().version("1.0")),new ResolverImpl())) :
331
+ new JRubyConstructor(self, new ComposerImpl(new ParserImpl(scn,YAML.config().version("1.0")),new ResolverImpl()))
332
+ ;
333
+ while(ctor.checkData()) {
334
+ if(d.isNil()) {
335
+ d = self.getRuntime().fastGetModule("JvYAML").fastGetClass("Stream").callMethod(context,"new", d);
336
+ }
337
+ d.callMethod(context,"add", JavaEmbedUtils.javaToRuby(self.getRuntime(),ctor.getData()));
338
+ }
339
+ return d;
340
+ } catch(YAMLException e) {
341
+ if(self.getRuntime().getDebug().isTrue()) {
342
+ Position.Range range = ((Positionable)e).getRange();
343
+ throw self.getRuntime().newArgumentError("syntax error on " + range.start + ":" + range.end + ": " + e.getMessage());
344
+ } else {
345
+ throw self.getRuntime().newArgumentError("syntax error:" + e.getMessage());
346
+ }
347
+ }
348
+ }
349
+
350
+ @JRubyMethod(name = "dump_stream", rest = true, module = true, visibility = Visibility.PRIVATE)
351
+ public static IRubyObject dump_stream(IRubyObject self, IRubyObject[] args) {
352
+ ThreadContext context = self.getRuntime().getCurrentContext();
353
+ IRubyObject stream = self.getRuntime().fastGetModule("JvYAML").fastGetClass("Stream").callMethod(context, "new");
354
+ for(int i=0,j=args.length;i<j;i++) {
355
+ stream.callMethod(context,"add", args[i]);
356
+ }
357
+ return stream.callMethod(context, "emit");
358
+ }
359
+
360
+ @JRubyMethod(name = "quick_emit_node", required = 1, rest = true, frame = true, module = true, visibility = Visibility.PRIVATE)
361
+ public static IRubyObject quick_emit_node(IRubyObject self, IRubyObject[] args, Block block) {
362
+ return block.yield(self.getRuntime().getCurrentContext(), args[0]);
363
+ }
364
+
365
+ // @JRubyMethod(name = "quick_emit_node", rest = true, module = true, visibility = Visibility.PRIVATE)
366
+ public static IRubyObject quick_emit(IRubyObject self, IRubyObject[] args) {
367
+ return self.getRuntime().getNil();
368
+ }
369
+
370
+ // prepares IO port type for load (ported from ext/syck/rubyext.c)
371
+ private static IRubyObject check_yaml_port(IRubyObject port) {
372
+ if (port instanceof RubyString) {
373
+ // OK
374
+ }
375
+ else if (port.respondsTo("read")) {
376
+ if (port.respondsTo("binmode")) {
377
+ ThreadContext context = port.getRuntime().getCurrentContext();
378
+ port.callMethod(context, "binmode");
379
+ }
380
+ }
381
+ else {
382
+ throw port.getRuntime().newTypeError("instance of IO needed");
383
+ }
384
+ return port;
385
+ }
386
+
387
+ @JRubyClass(name="Hash")
388
+ public static class YAMLHashMethods {
389
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
390
+ public static IRubyObject hash_to_yaml_node(IRubyObject self, IRubyObject arg) {
391
+ Ruby runtime = self.getRuntime();
392
+ ThreadContext context = runtime.getCurrentContext();
393
+ return RuntimeHelpers.invoke(context, arg, "map", self.callMethod(context, "jv_taguri"), self, self.callMethod(context, "to_jvyaml_style"));
394
+ }
395
+ }
396
+
397
+ @JRubyClass(name="Object")
398
+ public static class YAMLObjectMethods {
399
+ @JRubyMethod(name = "to_jvyaml_properties")
400
+ public static IRubyObject obj_to_yaml_properties(IRubyObject self) {
401
+ ThreadContext context = self.getRuntime().getCurrentContext();
402
+ return self.callMethod(context, "instance_variables").callMethod(context, "sort");
403
+ }
404
+ @JRubyMethod(name = "to_jvyaml_style")
405
+ public static IRubyObject obj_to_yaml_style(IRubyObject self) {
406
+ return self.getRuntime().getNil();
407
+ }
408
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
409
+ public static IRubyObject obj_to_yaml_node(IRubyObject self, IRubyObject arg) {
410
+ ThreadContext context = self.getRuntime().getCurrentContext();
411
+ Map mep = (Map)(new RubyHash(self.getRuntime()));
412
+ RubyArray props = (RubyArray)self.callMethod(context, "to_jvyaml_properties");
413
+ for(Iterator iter = props.getList().iterator(); iter.hasNext();) {
414
+ String m = iter.next().toString();
415
+ mep.put(self.getRuntime().newString(m.substring(1)), self.callMethod(context,"instance_variable_get", self.getRuntime().newString(m)));
416
+ }
417
+ return RuntimeHelpers.invoke(context, arg, "map", self.callMethod(context, "jv_taguri"), (IRubyObject)mep, self.callMethod(context, "to_jvyaml_style"));
418
+ }
419
+ @JRubyMethod(name = "to_jvyaml")
420
+ public static IRubyObject obj_to_yaml(IRubyObject self) {
421
+ return dump(self.getRuntime().fastGetModule("JvYAML"), self);
422
+ }
423
+ @JRubyMethod(name = "to_jvyaml")
424
+ public static IRubyObject obj_to_yaml(IRubyObject self, IRubyObject opts) {
425
+ return dump(self.getRuntime().fastGetModule("JvYAML"), self);
426
+ }
427
+ @JRubyMethod(name = "jv_taguri")
428
+ public static IRubyObject obj_taguri(IRubyObject self) {
429
+ return self.getRuntime().newString("!ruby/object:" + self.getType().getName());
430
+ }
431
+ }
432
+
433
+ @JRubyClass(name="Class")
434
+ public static class YAMLClassMethods {
435
+ @JRubyMethod(name = "to_jvyaml", rest = true)
436
+ public static IRubyObject class_to_yaml(IRubyObject self, IRubyObject[] args) {
437
+ throw self.getRuntime().newTypeError("can't dump anonymous class " + self.getType().getName());
438
+ }
439
+ }
440
+
441
+ @JRubyClass(name="Array")
442
+ public static class YAMLArrayMethods {
443
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
444
+ public static IRubyObject array_to_yaml_node(IRubyObject self, IRubyObject arg) {
445
+ ThreadContext context = self.getRuntime().getCurrentContext();
446
+ return RuntimeHelpers.invoke(context, arg, "seq", self.callMethod(context, "jv_taguri"), self, self.callMethod(context, "to_jvyaml_style"));
447
+ }
448
+ }
449
+
450
+ @JRubyClass(name="Struct")
451
+ public static class YAMLStructMethods {
452
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
453
+ public static IRubyObject struct_to_yaml_node(IRubyObject self, IRubyObject arg) {
454
+ ThreadContext context = self.getRuntime().getCurrentContext();
455
+ Map mep = (Map)(new RubyHash(self.getRuntime()));
456
+ for(Iterator iter = ((RubyArray)self.callMethod(context, "members")).getList().iterator();iter.hasNext();) {
457
+ IRubyObject key = self.getRuntime().newString(iter.next().toString());
458
+ mep.put(key,self.callMethod(context, "[]", key));
459
+ }
460
+ for(Iterator iter = ((RubyArray)self.callMethod(context, "to_jvyaml_properties")).getList().iterator(); iter.hasNext();) {
461
+ String m = iter.next().toString();
462
+ mep.put(self.getRuntime().newString(m.substring(1)), self.callMethod(context,"instance_variable_get", self.getRuntime().newString(m)));
463
+ }
464
+ return RuntimeHelpers.invoke(context, arg, "map", self.callMethod(context, "jv_taguri"), (IRubyObject)mep, self.callMethod(context, "to_jvyaml_style"));
465
+ }
466
+ @JRubyMethod(name = "jv_taguri")
467
+ public static IRubyObject struct_taguri(IRubyObject self) {
468
+ return self.getRuntime().newString("!ruby/struct:" + self.getType().getName());
469
+ }
470
+ }
471
+
472
+ @JRubyClass(name="Exception")
473
+ public static class YAMLExceptionMethods {
474
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
475
+ public static IRubyObject exception_to_yaml_node(IRubyObject self, IRubyObject arg) {
476
+ ThreadContext context = self.getRuntime().getCurrentContext();
477
+ Map mep = (Map)(new RubyHash(self.getRuntime()));
478
+ mep.put(self.getRuntime().newString("message"),self.callMethod(context, "message"));
479
+ for(Iterator iter = ((RubyArray)self.callMethod(context, "to_jvyaml_properties")).getList().iterator(); iter.hasNext();) {
480
+ String m = iter.next().toString();
481
+ mep.put(self.getRuntime().newString(m.substring(1)), self.callMethod(context,"instance_variable_get", self.getRuntime().newString(m)));
482
+ }
483
+ return RuntimeHelpers.invoke(context, arg,"map", self.callMethod(context, "jv_taguri"), (IRubyObject)mep, self.callMethod(context, "to_jvyaml_style"));
484
+ }
485
+ @JRubyMethod(name = "jv_taguri")
486
+ public static IRubyObject exception_taguri(IRubyObject self) {
487
+ return self.getRuntime().newString("!ruby/exception:" + self.getType().getName());
488
+ }
489
+ }
490
+
491
+ private static final Pattern AFTER_NEWLINE = Pattern.compile("\n.+", Pattern.DOTALL);
492
+ @JRubyClass(name="String")
493
+ public static class YAMLStringMethods {
494
+ @JRubyMethod(name = "is_complex_jvyaml?")
495
+ public static IRubyObject string_is_complex(IRubyObject self) {
496
+ ThreadContext context = self.getRuntime().getCurrentContext();
497
+ return (self.callMethod(context, "to_jvyaml_style").isTrue() ||
498
+ ((List)self.callMethod(context, "to_jvyaml_properties")).isEmpty() ||
499
+ AFTER_NEWLINE.matcher(self.toString()).find()) ? self.getRuntime().getTrue() : self.getRuntime().getFalse();
500
+ }
501
+ @JRubyMethod(name = "is_jv_binary_data?")
502
+ public static IRubyObject string_is_binary(IRubyObject self) {
503
+ ThreadContext context = self.getRuntime().getCurrentContext();
504
+ if(self.callMethod(context, "empty?").isTrue()) {
505
+ return self.getRuntime().getNil();
506
+ }
507
+ return self.toString().indexOf('\0') != -1 ? self.getRuntime().getTrue() : self.getRuntime().getFalse();
508
+ }
509
+ private static JRubyRepresenter into(IRubyObject arg) {
510
+ Object jobj = arg.dataGetStruct();
511
+ if(jobj != null) {
512
+ return (JRubyRepresenter)(((org.jruby.javasupport.JavaObject)jobj).getValue());
513
+ }
514
+ return null;
515
+ }
516
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
517
+ public static IRubyObject string_to_yaml_node(IRubyObject self, IRubyObject arg) {
518
+ ThreadContext context = self.getRuntime().getCurrentContext();
519
+ Ruby rt = self.getRuntime();
520
+ if(self.callMethod(context, "is_jv_binary_data?").isTrue()) {
521
+ return RuntimeHelpers.invoke(context, arg, "scalar", rt.newString("tag:yaml.org,2002:binary"), rt.newArray(self).callMethod(context, "pack", rt.newString("m")), rt.newString("|"));
522
+ }
523
+ if(((List)self.callMethod(context, "to_jvyaml_properties")).isEmpty()) {
524
+ JRubyRepresenter rep = into(arg);
525
+ if(rep != null) {
526
+ try {
527
+ return JavaUtil.convertJavaToRuby(rt,rep.scalar(self.callMethod(context, "jv_taguri").toString(),self.convertToString().getByteList(),self.toString().startsWith(":") ? "\"" : self.callMethod(context, "to_jvyaml_style").toString()));
528
+ } catch(IOException e) {
529
+ throw rt.newIOErrorFromException(e);
530
+ }
531
+ } else {
532
+ return RuntimeHelpers.invoke(context, arg, "scalar", self.callMethod(context, "jv_taguri"), self, self.toString().startsWith(":") ? rt.newString("\"") : self.callMethod(context, "to_jvyaml_style"));
533
+ }
534
+ }
535
+
536
+ Map mep = (Map)(new RubyHash(self.getRuntime()));
537
+ mep.put(self.getRuntime().newString("str"),rt.newString(self.toString()));
538
+ for(Iterator iter = ((RubyArray)self.callMethod(context, "to_jvyaml_properties")).getList().iterator(); iter.hasNext();) {
539
+ String m = iter.next().toString();
540
+ mep.put(self.getRuntime().newString(m), self.callMethod(context,"instance_variable_get", self.getRuntime().newString(m)));
541
+ }
542
+ return RuntimeHelpers.invoke(context, arg, "map", self.callMethod(context, "jv_taguri"), (IRubyObject)mep, self.callMethod(context, "to_jvyaml_style"));
543
+ }
544
+ }
545
+
546
+ @JRubyClass(name="Symbol")
547
+ public static class YAMLSymbolMethods {
548
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
549
+ public static IRubyObject symbol_to_yaml_node(IRubyObject self, IRubyObject arg) {
550
+ ThreadContext context = self.getRuntime().getCurrentContext();
551
+ return RuntimeHelpers.invoke(context, arg, "scalar", self.callMethod(context, "jv_taguri"), self.callMethod(context, "inspect"), self.callMethod(context, "to_jvyaml_style"));
552
+ }
553
+ @JRubyMethod(name = "jv_taguri")
554
+ public static IRubyObject symbol_taguri(IRubyObject self) {
555
+ return self.getRuntime().newString("tag:yaml.org,2002:str");
556
+ }
557
+ }
558
+
559
+ @JRubyClass(name="Numeric")
560
+ public static class YAMLNumericMethods {
561
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
562
+ public static IRubyObject numeric_to_yaml_node(IRubyObject self, IRubyObject arg) {
563
+ ThreadContext context = self.getRuntime().getCurrentContext();
564
+ String val = self.toString();
565
+ if("Infinity".equals(val)) {
566
+ val = ".Inf";
567
+ } else if("-Infinity".equals(val)) {
568
+ val = "-.Inf";
569
+ } else if("NaN".equals(val)) {
570
+ val = ".NaN";
571
+ }
572
+ return RuntimeHelpers.invoke(context, arg,"scalar", self.callMethod(context, "jv_taguri"), self.getRuntime().newString(val), self.callMethod(context, "to_jvyaml_style"));
573
+ }
574
+ }
575
+
576
+ @JRubyClass(name="Range")
577
+ public static class YAMLRangeMethods {
578
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
579
+ public static IRubyObject range_to_yaml_node(IRubyObject self, IRubyObject arg) {
580
+ ThreadContext context = self.getRuntime().getCurrentContext();
581
+ Map mep = (Map)(new RubyHash(self.getRuntime()));
582
+ mep.put(self.getRuntime().newString("begin"),self.callMethod(context, "begin"));
583
+ mep.put(self.getRuntime().newString("end"),self.callMethod(context, "end"));
584
+ mep.put(self.getRuntime().newString("excl"),self.callMethod(context, "exclude_end?"));
585
+ for(Iterator iter = ((RubyArray)self.callMethod(context, "to_jvyaml_properties")).getList().iterator(); iter.hasNext();) {
586
+ String m = iter.next().toString();
587
+ mep.put(self.getRuntime().newString(m.substring(1)), self.callMethod(context,"instance_variable_get", self.getRuntime().newString(m)));
588
+ }
589
+ return RuntimeHelpers.invoke(context, arg, "map", self.callMethod(context, "jv_taguri"), (IRubyObject)mep, self.callMethod(context, "to_jvyaml_style"));
590
+ }
591
+ }
592
+
593
+ @JRubyClass(name="Regexp")
594
+ public static class YAMLRegexpMethods {
595
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
596
+ public static IRubyObject regexp_to_yaml_node(IRubyObject self, IRubyObject arg) {
597
+ ThreadContext context = self.getRuntime().getCurrentContext();
598
+ return RuntimeHelpers.invoke(context, arg, "scalar", self.callMethod(context, "jv_taguri"), self.callMethod(context, "inspect"), self.callMethod(context, "to_jvyaml_style"));
599
+ }
600
+ }
601
+
602
+ @JRubyClass(name="Time")
603
+ public static class YAMLTimeMethods {
604
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
605
+ public static IRubyObject time_to_yaml_node(IRubyObject self, IRubyObject arg) {
606
+ ThreadContext context = self.getRuntime().getCurrentContext();
607
+ IRubyObject tz = self.getRuntime().newString("Z");
608
+ IRubyObject difference_sign = self.getRuntime().newString("-");
609
+ self = self.dup();
610
+ if(!self.callMethod(context, "utc?").isTrue()) {
611
+ IRubyObject utc_same_instant = self.callMethod(context, "utc");
612
+ IRubyObject utc_same_writing = RuntimeHelpers.invoke(context, self.getRuntime().getTime(), "utc", new IRubyObject[]{
613
+ self.callMethod(context, "year"),self.callMethod(context, "month"),self.callMethod(context, "day"),self.callMethod(context, "hour"),
614
+ self.callMethod(context, "min"),self.callMethod(context, "sec"),self.callMethod(context, "usec")});
615
+ IRubyObject difference_to_utc = utc_same_writing.callMethod(context, "-", utc_same_instant);
616
+ IRubyObject absolute_difference;
617
+ if(difference_to_utc.callMethod(context, "<", RubyFixnum.zero(self.getRuntime())).isTrue()) {
618
+ difference_sign = self.getRuntime().newString("-");
619
+ absolute_difference = RubyFixnum.zero(self.getRuntime()).callMethod(context, "-", difference_to_utc);
620
+ } else {
621
+ difference_sign = self.getRuntime().newString("+");
622
+ absolute_difference = difference_to_utc;
623
+ }
624
+ IRubyObject difference_minutes = absolute_difference.callMethod(context,"/", self.getRuntime().newFixnum(60)).callMethod(context, "round");
625
+ tz = self.getRuntime().newString("%s%02d:%02d").callMethod(context,"%", self.getRuntime().newArrayNoCopy(new IRubyObject[]{difference_sign,difference_minutes.callMethod(context,"/", self.getRuntime().newFixnum(60)),difference_minutes.callMethod(context,"%", self.getRuntime().newFixnum(60))}));
626
+ }
627
+ IRubyObject standard = self.callMethod(context,"strftime", self.getRuntime().newString("%Y-%m-%d %H:%M:%S"));
628
+ if(self.callMethod(context, "usec").callMethod(context, "nonzero?").isTrue()) {
629
+ standard = standard.callMethod(context, "+", self.getRuntime().newString(".%06d").callMethod(context,"%", self.getRuntime().newArray(self.callMethod(context, "usec"))));
630
+ }
631
+ standard = standard.callMethod(context, "+", self.getRuntime().newString(" %s").callMethod(context,"%", self.getRuntime().newArray(tz)));
632
+ return RuntimeHelpers.invoke(context, arg, "scalar", self.callMethod(context, "jv_taguri"), standard, self.callMethod(context, "to_jvyaml_style"));
633
+ }
634
+ }
635
+
636
+ @JRubyClass(name="Date")
637
+ public static class YAMLDateMethods {
638
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
639
+ public static IRubyObject date_to_yaml_node(IRubyObject self, IRubyObject arg) {
640
+ ThreadContext context = self.getRuntime().getCurrentContext();
641
+ return RuntimeHelpers.invoke(context, arg, "scalar", self.callMethod(context, "jv_taguri"), self.callMethod(context, "to_s"), self.callMethod(context, "to_jvyaml_style"));
642
+ }
643
+ }
644
+
645
+ @JRubyClass(name="TrueClass")
646
+ public static class YAMLTrueMethods {
647
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
648
+ public static IRubyObject true_to_yaml_node(IRubyObject self, IRubyObject arg) {
649
+ ThreadContext context = self.getRuntime().getCurrentContext();
650
+ return RuntimeHelpers.invoke(context, arg, "scalar", self.callMethod(context, "jv_taguri"), self.callMethod(context, "to_s"), self.callMethod(context, "to_jvyaml_style"));
651
+ }
652
+ @JRubyMethod(name = "jv_taguri")
653
+ public static IRubyObject true_taguri(IRubyObject self) {
654
+ return self.getRuntime().newString("tag:yaml.org,2002:bool");
655
+ }
656
+ }
657
+
658
+ @JRubyClass(name="FalseClass")
659
+ public static class YAMLFalseMethods {
660
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
661
+ public static IRubyObject false_to_yaml_node(IRubyObject self, IRubyObject arg) {
662
+ ThreadContext context = self.getRuntime().getCurrentContext();
663
+ return RuntimeHelpers.invoke(context, arg, "scalar", self.callMethod(context, "jv_taguri"), self.callMethod(context, "to_s"), self.callMethod(context, "to_jvyaml_style"));
664
+ }
665
+ @JRubyMethod(name = "jv_taguri")
666
+ public static IRubyObject false_taguri(IRubyObject self) {
667
+ return self.getRuntime().newString("tag:yaml.org,2002:bool");
668
+ }
669
+ }
670
+
671
+ @JRubyClass(name="NilClass")
672
+ public static class YAMLNilMethods {
673
+ @JRubyMethod(name = "to_jvyaml_node", required = 1)
674
+ public static IRubyObject nil_to_yaml_node(IRubyObject self, IRubyObject arg) {
675
+ ThreadContext context = self.getRuntime().getCurrentContext();
676
+ return RuntimeHelpers.invoke(context, arg,"scalar", self.callMethod(context, "jv_taguri"), self.getRuntime().newString(""), self.callMethod(context, "to_jvyaml_style"));
677
+ }
678
+ }
679
+ }// RubyYAML