psych 2.1.0 → 2.1.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.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.travis.yml +1 -10
- data/Gemfile +3 -0
- data/Mavenfile +7 -0
- data/Rakefile +27 -119
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/ext/java/PsychEmitter.java +345 -0
- data/ext/java/PsychLibrary.java +93 -0
- data/ext/java/PsychParser.java +399 -0
- data/ext/java/PsychToRuby.java +79 -0
- data/ext/java/PsychYamlTree.java +55 -0
- data/ext/psych/.gitignore +11 -0
- data/lib/psych.rb +2 -2
- data/lib/psych/scalar_scanner.rb +1 -1
- data/lib/psych/visitors/to_ruby.rb +2 -2
- data/psych.gemspec +39 -0
- metadata +21 -84
- data/.autotest +0 -18
- data/Manifest.txt +0 -114
- data/test/psych/handlers/test_recorder.rb +0 -26
- data/test/psych/helper.rb +0 -122
- data/test/psych/json/test_stream.rb +0 -110
- data/test/psych/nodes/test_enumerable.rb +0 -44
- data/test/psych/test_alias_and_anchor.rb +0 -97
- data/test/psych/test_array.rb +0 -58
- data/test/psych/test_boolean.rb +0 -37
- data/test/psych/test_class.rb +0 -37
- data/test/psych/test_coder.rb +0 -207
- data/test/psych/test_date_time.rb +0 -39
- data/test/psych/test_deprecated.rb +0 -215
- data/test/psych/test_document.rb +0 -47
- data/test/psych/test_emitter.rb +0 -111
- data/test/psych/test_encoding.rb +0 -269
- data/test/psych/test_exception.rb +0 -158
- data/test/psych/test_hash.rb +0 -95
- data/test/psych/test_json_tree.rb +0 -66
- data/test/psych/test_merge_keys.rb +0 -181
- data/test/psych/test_nil.rb +0 -19
- data/test/psych/test_null.rb +0 -20
- data/test/psych/test_numeric.rb +0 -46
- data/test/psych/test_object.rb +0 -45
- data/test/psych/test_object_references.rb +0 -72
- data/test/psych/test_omap.rb +0 -76
- data/test/psych/test_parser.rb +0 -340
- data/test/psych/test_psych.rb +0 -184
- data/test/psych/test_safe_load.rb +0 -98
- data/test/psych/test_scalar.rb +0 -12
- data/test/psych/test_scalar_scanner.rb +0 -107
- data/test/psych/test_serialize_subclasses.rb +0 -39
- data/test/psych/test_set.rb +0 -50
- data/test/psych/test_stream.rb +0 -94
- data/test/psych/test_string.rb +0 -227
- data/test/psych/test_struct.rb +0 -50
- data/test/psych/test_symbol.rb +0 -26
- data/test/psych/test_tainted.rb +0 -131
- data/test/psych/test_to_yaml_properties.rb +0 -64
- data/test/psych/test_tree_builder.rb +0 -80
- data/test/psych/test_yaml.rb +0 -1293
- data/test/psych/test_yamldbm.rb +0 -193
- data/test/psych/test_yamlstore.rb +0 -86
- data/test/psych/visitors/test_depth_first.rb +0 -50
- data/test/psych/visitors/test_emitter.rb +0 -145
- data/test/psych/visitors/test_to_ruby.rb +0 -332
- data/test/psych/visitors/test_yaml_tree.rb +0 -180
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2e70b3ff8828fe0241a7047bdd843ad39f669c7
|
4
|
+
data.tar.gz: ec14c0a1d14bb917e2b43701d97c23ff32c037d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24c746dc58c84d37adf9e1660c002d3882bbd4ae81bf5f800094959593c0b06ca1d246c563e95ed40e4459d3fa179260f8358ce1dd6a57d9b44d2187b8a52401
|
7
|
+
data.tar.gz: 01df0982d787422a5cd43ff68adc5dca474d0e7b5012205095f43ccc04d55c5b80d3f112da68c46617c5b587631307fb1e75e61e6acfafe0cee3f378afa6ab7d
|
data/.gitignore
ADDED
data/.travis.yml
CHANGED
@@ -4,13 +4,4 @@ rvm:
|
|
4
4
|
- 2.2
|
5
5
|
- 2.3.0
|
6
6
|
- ruby-head
|
7
|
-
|
8
|
-
before_script:
|
9
|
-
- gem install hoe
|
10
|
-
- gem install rake-compiler
|
11
|
-
- gem install minitest -v '~> 5.0'
|
12
|
-
script: rake test
|
13
|
-
matrix:
|
14
|
-
allow_failures:
|
15
|
-
- rvm: ruby-head
|
16
|
-
- rvm: rbx-2
|
7
|
+
before_install: gem install bundler --no-document
|
data/Gemfile
ADDED
data/Mavenfile
ADDED
data/Rakefile
CHANGED
@@ -1,123 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
$hoe = Hoe.spec 'psych' do
|
25
|
-
license 'MIT'
|
26
|
-
developer 'Aaron Patterson', 'aaron@tenderlovemaking.com'
|
27
|
-
|
28
|
-
self.extra_rdoc_files = Dir['*.rdoc']
|
29
|
-
self.history_file = 'CHANGELOG.rdoc'
|
30
|
-
self.readme_file = 'README.rdoc'
|
31
|
-
self.testlib = :minitest
|
32
|
-
|
33
|
-
extra_dev_deps << ['rake-compiler', '>= 0.4.1']
|
34
|
-
extra_dev_deps << ['minitest', '~> 5.0']
|
35
|
-
|
36
|
-
self.spec_extras = {
|
37
|
-
:required_ruby_version => '>= 1.9.2'
|
38
|
-
}
|
39
|
-
|
40
|
-
if java?
|
41
|
-
require './lib/psych/versions.rb'
|
42
|
-
extra_deps << ['jar-dependencies', '>= 0.1.7']
|
43
|
-
|
44
|
-
# the jar declaration for jar-dependencies
|
45
|
-
self.spec_extras[ 'requirements' ] = "jar org.yaml:snakeyaml, #{Psych::DEFAULT_SNAKEYAML_VERSION}"
|
46
|
-
self.spec_extras[ 'platform' ] = 'java'
|
47
|
-
# TODO: clean this section up.
|
48
|
-
require "rake/javaextensiontask"
|
49
|
-
Rake::JavaExtensionTask.new("psych", spec) do |ext|
|
50
|
-
require 'maven/ruby/maven'
|
51
|
-
# uses Mavenfile to write classpath into pkg/classpath
|
52
|
-
# and tell maven via system properties the snakeyaml version
|
53
|
-
# this is basically the same as running from the commandline:
|
54
|
-
# rmvn dependency:build-classpath -Dsnakeyaml.version='use version from Psych::DEFAULT_SNAKEYAML_VERSION here'
|
55
|
-
Maven::Ruby::Maven.new.exec( 'dependency:build-classpath', "-Dsnakeyaml.version=#{Psych::DEFAULT_SNAKEYAML_VERSION}", '-Dverbose=true')#, '--quiet' )
|
56
|
-
ext.source_version = '1.7'
|
57
|
-
ext.target_version = '1.7'
|
58
|
-
ext.classpath = File.read('pkg/classpath')
|
59
|
-
ext.ext_dir = 'ext/java'
|
60
|
-
end
|
61
|
-
else
|
62
|
-
self.spec_extras[:extensions] = ["ext/psych/extconf.rb"]
|
63
|
-
Rake::ExtensionTask.new "psych", spec do |ext|
|
64
|
-
ext.lib_dir = File.join(*['lib', ENV['FAT_DIR']].compact)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def gem_build_path
|
70
|
-
File.join 'pkg', $hoe.spec.full_name
|
71
|
-
end
|
72
|
-
|
73
|
-
def add_file_to_gem relative_path
|
74
|
-
target_path = File.join gem_build_path, relative_path
|
75
|
-
target_dir = File.dirname(target_path)
|
76
|
-
mkdir_p target_dir unless File.directory?(target_dir)
|
77
|
-
rm_f target_path
|
78
|
-
safe_ln relative_path, target_path
|
79
|
-
$hoe.spec.files.concat [relative_path]
|
80
|
-
end
|
81
|
-
|
82
|
-
if java?
|
83
|
-
task gem_build_path => [:compile] do
|
84
|
-
add_file_to_gem 'lib/psych.jar'
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.libs << "lib"
|
7
|
+
t.test_files = FileList['test/**/test_*.rb']
|
8
|
+
end
|
9
|
+
|
10
|
+
if RUBY_PLATFORM =~ /java/
|
11
|
+
require 'rake/javaextensiontask'
|
12
|
+
Rake::JavaExtensionTask.new("psych") do |ext|
|
13
|
+
require 'maven/ruby/maven'
|
14
|
+
# uses Mavenfile to write classpath into pkg/classpath
|
15
|
+
# and tell maven via system properties the snakeyaml version
|
16
|
+
# this is basically the same as running from the commandline:
|
17
|
+
# rmvn dependency:build-classpath -Dsnakeyaml.version='use version from Psych::DEFAULT_SNAKEYAML_VERSION here'
|
18
|
+
Maven::Ruby::Maven.new.exec( 'dependency:build-classpath', "-Dsnakeyaml.version=#{Psych::DEFAULT_SNAKEYAML_VERSION}", '-Dverbose=true')#, '--quiet' )
|
19
|
+
ext.source_version = '1.7'
|
20
|
+
ext.target_version = '1.7'
|
21
|
+
ext.classpath = File.read('pkg/classpath')
|
22
|
+
ext.ext_dir = 'ext/java'
|
85
23
|
end
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
task :test => :compile
|
91
|
-
|
92
|
-
task :hack_spec do
|
93
|
-
$hoe.spec.extra_rdoc_files.clear
|
94
|
-
end
|
95
|
-
task 'core:spec' => [:hack_spec, 'gem:spec']
|
96
|
-
|
97
|
-
desc "merge psych in to ruby trunk"
|
98
|
-
namespace :merge do
|
99
|
-
basedir = File.expand_path File.dirname __FILE__
|
100
|
-
rubydir = File.join ENV['HOME'], 'git', 'ruby'
|
101
|
-
mergedirs = {
|
102
|
-
# From # To
|
103
|
-
[basedir, 'ext', 'psych/'] => [rubydir, 'ext', 'psych/'],
|
104
|
-
[basedir, 'lib/'] => [rubydir, 'ext', 'psych', 'lib/'],
|
105
|
-
[basedir, 'test', 'psych/'] => [rubydir, 'test', 'psych/'],
|
106
|
-
}
|
107
|
-
|
108
|
-
rsync = 'rsync -av --exclude lib --exclude ".*" --exclude "*.o" --exclude Makefile --exclude mkmf.log --delete'
|
109
|
-
|
110
|
-
task :to_ruby do
|
111
|
-
mergedirs.each do |from, to|
|
112
|
-
sh "#{rsync} #{File.join(*from)} #{File.join(*to)}"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
task :from_ruby do
|
117
|
-
mergedirs.each do |from, to|
|
118
|
-
sh "#{rsync} #{File.join(*to)} #{File.join(*from)}"
|
119
|
-
end
|
24
|
+
else
|
25
|
+
require 'rake/extensiontask'
|
26
|
+
Rake::ExtensionTask.new("psych") do |ext|
|
27
|
+
ext.lib_dir = File.join(*['lib', ENV['FAT_DIR']].compact)
|
120
28
|
end
|
121
29
|
end
|
122
30
|
|
123
|
-
|
31
|
+
task :default => [:compile, :test]
|
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,345 @@
|
|
1
|
+
/***** BEGIN LICENSE BLOCK *****
|
2
|
+
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
|
3
|
+
*
|
4
|
+
* The contents of this file are subject to the Eclipse Public
|
5
|
+
* License Version 1.0 (the "License"); you may not use this file
|
6
|
+
* except in compliance with the License. You may obtain a copy of
|
7
|
+
* the License at http://www.eclipse.org/legal/epl-v10.html
|
8
|
+
*
|
9
|
+
* Software distributed under the License is distributed on an "AS
|
10
|
+
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
11
|
+
* implied. See the License for the specific language governing
|
12
|
+
* rights and limitations under the License.
|
13
|
+
*
|
14
|
+
* Copyright (C) 2010 Charles O Nutter <headius@headius.com>
|
15
|
+
*
|
16
|
+
* Alternatively, the contents of this file may be used under the terms of
|
17
|
+
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
18
|
+
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
19
|
+
* in which case the provisions of the GPL or the LGPL are applicable instead
|
20
|
+
* of those above. If you wish to allow use of your version of this file only
|
21
|
+
* under the terms of either the GPL or the LGPL, and not to allow others to
|
22
|
+
* use your version of this file under the terms of the EPL, indicate your
|
23
|
+
* decision by deleting the provisions above and replace them with the notice
|
24
|
+
* and other provisions required by the GPL or the LGPL. If you do not delete
|
25
|
+
* the provisions above, a recipient may use your version of this file under
|
26
|
+
* the terms of any one of the EPL, the GPL or the LGPL.
|
27
|
+
***** END LICENSE BLOCK *****/
|
28
|
+
package org.jruby.ext.psych;
|
29
|
+
|
30
|
+
import java.io.IOException;
|
31
|
+
import java.io.OutputStreamWriter;
|
32
|
+
import java.nio.charset.Charset;
|
33
|
+
import java.util.HashMap;
|
34
|
+
import java.util.Map;
|
35
|
+
|
36
|
+
import org.jcodings.Encoding;
|
37
|
+
import org.jruby.Ruby;
|
38
|
+
import org.jruby.RubyArray;
|
39
|
+
import org.jruby.RubyClass;
|
40
|
+
import org.jruby.RubyFixnum;
|
41
|
+
import org.jruby.RubyModule;
|
42
|
+
import org.jruby.RubyObject;
|
43
|
+
import org.jruby.RubyString;
|
44
|
+
import org.jruby.anno.JRubyMethod;
|
45
|
+
import org.jruby.runtime.ObjectAllocator;
|
46
|
+
import org.jruby.runtime.ThreadContext;
|
47
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
48
|
+
import org.jruby.util.IOOutputStream;
|
49
|
+
import org.yaml.snakeyaml.DumperOptions;
|
50
|
+
import org.yaml.snakeyaml.emitter.Emitter;
|
51
|
+
import org.yaml.snakeyaml.emitter.EmitterException;
|
52
|
+
import org.yaml.snakeyaml.error.Mark;
|
53
|
+
import org.yaml.snakeyaml.events.AliasEvent;
|
54
|
+
import org.yaml.snakeyaml.events.DocumentEndEvent;
|
55
|
+
import org.yaml.snakeyaml.events.DocumentStartEvent;
|
56
|
+
import org.yaml.snakeyaml.events.Event;
|
57
|
+
import org.yaml.snakeyaml.events.ImplicitTuple;
|
58
|
+
import org.yaml.snakeyaml.events.MappingEndEvent;
|
59
|
+
import org.yaml.snakeyaml.events.MappingStartEvent;
|
60
|
+
import org.yaml.snakeyaml.events.ScalarEvent;
|
61
|
+
import org.yaml.snakeyaml.events.SequenceEndEvent;
|
62
|
+
import org.yaml.snakeyaml.events.SequenceStartEvent;
|
63
|
+
import org.yaml.snakeyaml.events.StreamEndEvent;
|
64
|
+
import org.yaml.snakeyaml.events.StreamStartEvent;
|
65
|
+
|
66
|
+
import static org.jruby.runtime.Visibility.*;
|
67
|
+
|
68
|
+
public class PsychEmitter extends RubyObject {
|
69
|
+
public static void initPsychEmitter(Ruby runtime, RubyModule psych) {
|
70
|
+
RubyClass psychHandler = runtime.defineClassUnder("Handler", runtime.getObject(), runtime.getObject().getAllocator(), psych);
|
71
|
+
RubyClass psychEmitter = runtime.defineClassUnder("Emitter", psychHandler, new ObjectAllocator() {
|
72
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
73
|
+
return new PsychEmitter(runtime, klazz);
|
74
|
+
}
|
75
|
+
}, psych);
|
76
|
+
|
77
|
+
psychEmitter.defineAnnotatedMethods(PsychEmitter.class);
|
78
|
+
}
|
79
|
+
|
80
|
+
public PsychEmitter(Ruby runtime, RubyClass klass) {
|
81
|
+
super(runtime, klass);
|
82
|
+
}
|
83
|
+
|
84
|
+
@JRubyMethod(visibility = PRIVATE)
|
85
|
+
public IRubyObject initialize(ThreadContext context, IRubyObject io) {
|
86
|
+
options = new DumperOptions();
|
87
|
+
options.setIndent(2);
|
88
|
+
|
89
|
+
this.io = io;
|
90
|
+
|
91
|
+
return context.nil;
|
92
|
+
}
|
93
|
+
|
94
|
+
@JRubyMethod(visibility = PRIVATE)
|
95
|
+
public IRubyObject initialize(ThreadContext context, IRubyObject io, IRubyObject rbOptions) {
|
96
|
+
IRubyObject width = rbOptions.callMethod(context, "line_width");
|
97
|
+
IRubyObject canonical = rbOptions.callMethod(context, "canonical");
|
98
|
+
IRubyObject level = rbOptions.callMethod(context, "indentation");
|
99
|
+
|
100
|
+
options = new DumperOptions();
|
101
|
+
|
102
|
+
options.setCanonical(canonical.isTrue());
|
103
|
+
options.setIndent((int)level.convertToInteger().getLongValue());
|
104
|
+
options.setWidth((int)width.convertToInteger().getLongValue());
|
105
|
+
|
106
|
+
this.io = io;
|
107
|
+
|
108
|
+
return context.nil;
|
109
|
+
}
|
110
|
+
|
111
|
+
@JRubyMethod
|
112
|
+
public IRubyObject start_stream(ThreadContext context, IRubyObject encoding) {
|
113
|
+
if (!(encoding instanceof RubyFixnum)) {
|
114
|
+
throw context.runtime.newTypeError(encoding, context.runtime.getFixnum());
|
115
|
+
}
|
116
|
+
|
117
|
+
initEmitter(context, encoding);
|
118
|
+
|
119
|
+
StreamStartEvent event = new StreamStartEvent(NULL_MARK, NULL_MARK);
|
120
|
+
|
121
|
+
emit(context, event);
|
122
|
+
|
123
|
+
return this;
|
124
|
+
}
|
125
|
+
|
126
|
+
@JRubyMethod
|
127
|
+
public IRubyObject end_stream(ThreadContext context) {
|
128
|
+
StreamEndEvent event = new StreamEndEvent(NULL_MARK, NULL_MARK);
|
129
|
+
emit(context, event);
|
130
|
+
return this;
|
131
|
+
}
|
132
|
+
|
133
|
+
@JRubyMethod
|
134
|
+
public IRubyObject start_document(ThreadContext context, IRubyObject _version, IRubyObject tags, IRubyObject implicit) {
|
135
|
+
DumperOptions.Version version = null;
|
136
|
+
boolean implicitBool = implicit.isTrue();
|
137
|
+
Map<String, String> tagsMap = null;
|
138
|
+
|
139
|
+
RubyArray versionAry = _version.convertToArray();
|
140
|
+
if (versionAry.size() == 2) {
|
141
|
+
int versionInt0 = (int)versionAry.eltInternal(0).convertToInteger().getLongValue();
|
142
|
+
int versionInt1 = (int)versionAry.eltInternal(1).convertToInteger().getLongValue();
|
143
|
+
|
144
|
+
if (versionInt0 == 1) {
|
145
|
+
if (versionInt1 == 0) {
|
146
|
+
version = DumperOptions.Version.V1_0;
|
147
|
+
} else if (versionInt1 == 1) {
|
148
|
+
version = DumperOptions.Version.V1_1;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
if (version == null) {
|
152
|
+
throw context.runtime.newArgumentError("invalid YAML version: " + versionAry);
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
RubyArray tagsAry = tags.convertToArray();
|
157
|
+
if (tagsAry.size() > 0) {
|
158
|
+
tagsMap = new HashMap<String, String>(tagsAry.size());
|
159
|
+
for (int i = 0; i < tagsAry.size(); i++) {
|
160
|
+
RubyArray tagsTuple = tagsAry.eltInternal(i).convertToArray();
|
161
|
+
if (tagsTuple.size() != 2) {
|
162
|
+
throw context.runtime.newRuntimeError("tags tuple must be of length 2");
|
163
|
+
}
|
164
|
+
IRubyObject key = tagsTuple.eltInternal(0);
|
165
|
+
IRubyObject value = tagsTuple.eltInternal(1);
|
166
|
+
tagsMap.put(
|
167
|
+
key.asJavaString(),
|
168
|
+
value.asJavaString());
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
DocumentStartEvent event = new DocumentStartEvent(NULL_MARK, NULL_MARK, !implicitBool, version, tagsMap);
|
173
|
+
emit(context, event);
|
174
|
+
return this;
|
175
|
+
}
|
176
|
+
|
177
|
+
@JRubyMethod
|
178
|
+
public IRubyObject end_document(ThreadContext context, IRubyObject implicit) {
|
179
|
+
DocumentEndEvent event = new DocumentEndEvent(NULL_MARK, NULL_MARK, !implicit.isTrue());
|
180
|
+
emit(context, event);
|
181
|
+
return this;
|
182
|
+
}
|
183
|
+
|
184
|
+
@JRubyMethod(required = 6)
|
185
|
+
public IRubyObject scalar(ThreadContext context, IRubyObject[] args) {
|
186
|
+
IRubyObject value = args[0];
|
187
|
+
IRubyObject anchor = args[1];
|
188
|
+
IRubyObject tag = args[2];
|
189
|
+
IRubyObject plain = args[3];
|
190
|
+
IRubyObject quoted = args[4];
|
191
|
+
IRubyObject style = args[5];
|
192
|
+
|
193
|
+
if (!(value instanceof RubyString)) {
|
194
|
+
throw context.runtime.newTypeError(value, context.runtime.getString());
|
195
|
+
}
|
196
|
+
|
197
|
+
ScalarEvent event = new ScalarEvent(
|
198
|
+
anchor.isNil() ? null : anchor.asJavaString(),
|
199
|
+
tag.isNil() ? null : tag.asJavaString(),
|
200
|
+
new ImplicitTuple(plain.isTrue(),
|
201
|
+
quoted.isTrue()),
|
202
|
+
value.asJavaString(),
|
203
|
+
NULL_MARK,
|
204
|
+
NULL_MARK,
|
205
|
+
SCALAR_STYLES[(int)style.convertToInteger().getLongValue()]);
|
206
|
+
emit(context, event);
|
207
|
+
return this;
|
208
|
+
}
|
209
|
+
|
210
|
+
@JRubyMethod(required = 4)
|
211
|
+
public IRubyObject start_sequence(ThreadContext context, IRubyObject[] args) {
|
212
|
+
IRubyObject anchor = args[0];
|
213
|
+
IRubyObject tag = args[1];
|
214
|
+
IRubyObject implicit = args[2];
|
215
|
+
IRubyObject style = args[3];
|
216
|
+
|
217
|
+
final int SEQUENCE_BLOCK = 1; // see psych/nodes/sequence.rb
|
218
|
+
|
219
|
+
SequenceStartEvent event = new SequenceStartEvent(
|
220
|
+
anchor.isNil() ? null : anchor.asJavaString(),
|
221
|
+
tag.isNil() ? null : tag.asJavaString(),
|
222
|
+
implicit.isTrue(),
|
223
|
+
NULL_MARK,
|
224
|
+
NULL_MARK,
|
225
|
+
SEQUENCE_BLOCK != style.convertToInteger().getLongValue());
|
226
|
+
emit(context, event);
|
227
|
+
return this;
|
228
|
+
}
|
229
|
+
|
230
|
+
@JRubyMethod
|
231
|
+
public IRubyObject end_sequence(ThreadContext context) {
|
232
|
+
SequenceEndEvent event = new SequenceEndEvent(NULL_MARK, NULL_MARK);
|
233
|
+
emit(context, event);
|
234
|
+
return this;
|
235
|
+
}
|
236
|
+
|
237
|
+
@JRubyMethod(required = 4)
|
238
|
+
public IRubyObject start_mapping(ThreadContext context, IRubyObject[] args) {
|
239
|
+
IRubyObject anchor = args[0];
|
240
|
+
IRubyObject tag = args[1];
|
241
|
+
IRubyObject implicit = args[2];
|
242
|
+
IRubyObject style = args[3];
|
243
|
+
|
244
|
+
final int MAPPING_BLOCK = 1; // see psych/nodes/mapping.rb
|
245
|
+
|
246
|
+
MappingStartEvent event = new MappingStartEvent(
|
247
|
+
anchor.isNil() ? null : anchor.asJavaString(),
|
248
|
+
tag.isNil() ? null : tag.asJavaString(),
|
249
|
+
implicit.isTrue(),
|
250
|
+
NULL_MARK,
|
251
|
+
NULL_MARK,
|
252
|
+
MAPPING_BLOCK != style.convertToInteger().getLongValue());
|
253
|
+
emit(context, event);
|
254
|
+
return this;
|
255
|
+
}
|
256
|
+
|
257
|
+
@JRubyMethod
|
258
|
+
public IRubyObject end_mapping(ThreadContext context) {
|
259
|
+
MappingEndEvent event = new MappingEndEvent(NULL_MARK, NULL_MARK);
|
260
|
+
emit(context, event);
|
261
|
+
return this;
|
262
|
+
}
|
263
|
+
|
264
|
+
@JRubyMethod
|
265
|
+
public IRubyObject alias(ThreadContext context, IRubyObject anchor) {
|
266
|
+
AliasEvent event = new AliasEvent(anchor.asJavaString(), NULL_MARK, NULL_MARK);
|
267
|
+
emit(context, event);
|
268
|
+
return this;
|
269
|
+
}
|
270
|
+
|
271
|
+
@JRubyMethod(name = "canonical=")
|
272
|
+
public IRubyObject canonical_set(ThreadContext context, IRubyObject canonical) {
|
273
|
+
// TODO: unclear if this affects a running emitter
|
274
|
+
options.setCanonical(canonical.isTrue());
|
275
|
+
return canonical;
|
276
|
+
}
|
277
|
+
|
278
|
+
@JRubyMethod
|
279
|
+
public IRubyObject canonical(ThreadContext context) {
|
280
|
+
// TODO: unclear if this affects a running emitter
|
281
|
+
return context.runtime.newBoolean(options.isCanonical());
|
282
|
+
}
|
283
|
+
|
284
|
+
@JRubyMethod(name = "indentation=")
|
285
|
+
public IRubyObject indentation_set(ThreadContext context, IRubyObject level) {
|
286
|
+
// TODO: unclear if this affects a running emitter
|
287
|
+
options.setIndent((int)level.convertToInteger().getLongValue());
|
288
|
+
return level;
|
289
|
+
}
|
290
|
+
|
291
|
+
@JRubyMethod
|
292
|
+
public IRubyObject indentation(ThreadContext context) {
|
293
|
+
// TODO: unclear if this affects a running emitter
|
294
|
+
return context.runtime.newFixnum(options.getIndent());
|
295
|
+
}
|
296
|
+
|
297
|
+
@JRubyMethod(name = "line_width=")
|
298
|
+
public IRubyObject line_width_set(ThreadContext context, IRubyObject width) {
|
299
|
+
options.setWidth((int)width.convertToInteger().getLongValue());
|
300
|
+
return width;
|
301
|
+
}
|
302
|
+
|
303
|
+
@JRubyMethod
|
304
|
+
public IRubyObject line_width(ThreadContext context) {
|
305
|
+
return context.runtime.newFixnum(options.getWidth());
|
306
|
+
}
|
307
|
+
|
308
|
+
private void emit(ThreadContext context, Event event) {
|
309
|
+
try {
|
310
|
+
if (emitter == null) throw context.runtime.newRuntimeError("uninitialized emitter");
|
311
|
+
|
312
|
+
emitter.emit(event);
|
313
|
+
} catch (IOException ioe) {
|
314
|
+
throw context.runtime.newIOErrorFromException(ioe);
|
315
|
+
} catch (EmitterException ee) {
|
316
|
+
throw context.runtime.newRuntimeError(ee.toString());
|
317
|
+
}
|
318
|
+
}
|
319
|
+
|
320
|
+
private void initEmitter(ThreadContext context, IRubyObject _encoding) {
|
321
|
+
if (emitter != null) throw context.runtime.newRuntimeError("already initialized emitter");
|
322
|
+
|
323
|
+
Encoding encoding = PsychLibrary.YAMLEncoding.values()[(int)_encoding.convertToInteger().getLongValue()].encoding;
|
324
|
+
Charset charset = context.runtime.getEncodingService().charsetForEncoding(encoding);
|
325
|
+
|
326
|
+
emitter = new Emitter(new OutputStreamWriter(new IOOutputStream(io, encoding), charset), options);
|
327
|
+
}
|
328
|
+
|
329
|
+
Emitter emitter;
|
330
|
+
DumperOptions options = new DumperOptions();
|
331
|
+
IRubyObject io;
|
332
|
+
|
333
|
+
private static final Mark NULL_MARK = new Mark(null, 0, 0, 0, null, 0);
|
334
|
+
|
335
|
+
// Map style constants from Psych values (ANY = 0 ... FOLDED = 5)
|
336
|
+
// to SnakeYaml values; see psych/nodes/scalar.rb.
|
337
|
+
private static final Character[] SCALAR_STYLES = new Character[] {
|
338
|
+
null, // ANY; we'll choose plain
|
339
|
+
null, // PLAIN
|
340
|
+
'\'', // SINGLE_QUOTED
|
341
|
+
'"', // DOUBLE_QUOTED
|
342
|
+
'|', // LITERAL
|
343
|
+
'>', // FOLDED
|
344
|
+
};
|
345
|
+
}
|