rubysl-yaml 0.0.1 → 1.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.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +7 -0
- data/README.md +2 -2
- data/Rakefile +0 -1
- data/lib/rubysl/yaml.rb +2 -0
- data/lib/rubysl/yaml/version.rb +5 -0
- data/lib/rubysl/yaml/yaml.rb +440 -0
- data/lib/yaml.rb +1 -0
- data/lib/yaml/baseemitter.rb +247 -0
- data/lib/yaml/basenode.rb +216 -0
- data/lib/yaml/constants.rb +45 -0
- data/lib/yaml/dbm.rb +111 -0
- data/lib/yaml/encoding.rb +33 -0
- data/lib/yaml/error.rb +34 -0
- data/lib/yaml/loader.rb +14 -0
- data/lib/yaml/rubytypes.rb +409 -0
- data/lib/yaml/store.rb +43 -0
- data/lib/yaml/stream.rb +40 -0
- data/lib/yaml/stringio.rb +83 -0
- data/lib/yaml/syck.rb +44 -0
- data/lib/yaml/tag.rb +91 -0
- data/lib/yaml/types.rb +192 -0
- data/lib/yaml/yamlnode.rb +54 -0
- data/lib/yaml/ypath.rb +52 -0
- data/rubysl-yaml.gemspec +19 -17
- data/spec/add_builtin_type_spec.rb +1 -0
- data/spec/add_domain_type_spec.rb +1 -0
- data/spec/add_private_type_spec.rb +1 -0
- data/spec/add_ruby_type_spec.rb +1 -0
- data/spec/detect_implicit_spec.rb +1 -0
- data/spec/dump_spec.rb +35 -0
- data/spec/dump_stream_spec.rb +13 -0
- data/spec/each_document_spec.rb +9 -0
- data/spec/each_node_spec.rb +1 -0
- data/spec/emitter_spec.rb +1 -0
- data/spec/fixtures/common.rb +10 -0
- data/spec/fixtures/example_class.rb +5 -0
- data/spec/fixtures/strings.rb +36 -0
- data/spec/fixtures/test_yaml.yml +2 -0
- data/spec/generic_parser_spec.rb +1 -0
- data/spec/load_documents_spec.rb +7 -0
- data/spec/load_file_spec.rb +12 -0
- data/spec/load_spec.rb +111 -0
- data/spec/load_stream_spec.rb +1 -0
- data/spec/object_maker_spec.rb +1 -0
- data/spec/parse_documents_spec.rb +1 -0
- data/spec/parse_file_spec.rb +9 -0
- data/spec/parse_spec.rb +21 -0
- data/spec/parser_spec.rb +1 -0
- data/spec/quick_emit_spec.rb +1 -0
- data/spec/read_type_class_spec.rb +1 -0
- data/spec/shared/each_document.rb +18 -0
- data/spec/tag_class_spec.rb +9 -0
- data/spec/tagged_classes_spec.rb +9 -0
- data/spec/tagurize_spec.rb +8 -0
- data/spec/to_yaml_spec.rb +97 -0
- data/spec/transfer_spec.rb +1 -0
- data/spec/try_implicit_spec.rb +1 -0
- metadata +163 -88
- data/lib/rubysl-yaml.rb +0 -7
- data/lib/rubysl-yaml/version.rb +0 -5
@@ -0,0 +1,54 @@
|
|
1
|
+
#
|
2
|
+
# YAML::YamlNode class
|
3
|
+
#
|
4
|
+
require 'yaml/basenode'
|
5
|
+
|
6
|
+
module YAML
|
7
|
+
|
8
|
+
#
|
9
|
+
# YAML Generic Model container
|
10
|
+
#
|
11
|
+
class YamlNode
|
12
|
+
include BaseNode
|
13
|
+
attr_accessor :kind, :type_id, :value, :anchor
|
14
|
+
def initialize( t, v )
|
15
|
+
@type_id = t
|
16
|
+
if Hash === v
|
17
|
+
@kind = 'map'
|
18
|
+
@value = {}
|
19
|
+
v.each { |k,v|
|
20
|
+
@value[ k.transform ] = [ k, v ]
|
21
|
+
}
|
22
|
+
elsif Array === v
|
23
|
+
@kind = 'seq'
|
24
|
+
@value = v
|
25
|
+
elsif String === v
|
26
|
+
@kind = 'scalar'
|
27
|
+
@value = v
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Transform this node fully into a native type
|
33
|
+
#
|
34
|
+
def transform
|
35
|
+
t = nil
|
36
|
+
if @value.is_a? Hash
|
37
|
+
t = {}
|
38
|
+
@value.each { |k,v|
|
39
|
+
t[ k ] = v[1].transform
|
40
|
+
}
|
41
|
+
elsif @value.is_a? Array
|
42
|
+
t = []
|
43
|
+
@value.each { |v|
|
44
|
+
t.push v.transform
|
45
|
+
}
|
46
|
+
else
|
47
|
+
t = @value
|
48
|
+
end
|
49
|
+
YAML.transfer_method( @type_id, t )
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/lib/yaml/ypath.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# YAML::YPath
|
3
|
+
#
|
4
|
+
|
5
|
+
module YAML
|
6
|
+
|
7
|
+
class YPath
|
8
|
+
attr_accessor :segments, :predicates, :flags
|
9
|
+
def initialize( str )
|
10
|
+
@segments = []
|
11
|
+
@predicates = []
|
12
|
+
@flags = nil
|
13
|
+
while str =~ /^\/?(\/|[^\/\[]+)(?:\[([^\]]+)\])?/
|
14
|
+
@segments.push $1
|
15
|
+
@predicates.push $2
|
16
|
+
str = $'
|
17
|
+
end
|
18
|
+
unless str.to_s.empty?
|
19
|
+
@segments += str.split( "/" )
|
20
|
+
end
|
21
|
+
if @segments.length == 0
|
22
|
+
@segments.push "."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
def YPath.each_path( str )
|
26
|
+
#
|
27
|
+
# Find choices
|
28
|
+
#
|
29
|
+
paths = []
|
30
|
+
str = "(#{ str })"
|
31
|
+
while str.sub!( /\(([^()]+)\)/, "\n#{ paths.length }\n" )
|
32
|
+
paths.push $1.split( '|' )
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Construct all possible paths
|
37
|
+
#
|
38
|
+
all = [ str ]
|
39
|
+
( paths.length - 1 ).downto( 0 ) do |i|
|
40
|
+
all = all.collect do |a|
|
41
|
+
paths[i].collect do |p|
|
42
|
+
a.gsub( /\n#{ i }\n/, p )
|
43
|
+
end
|
44
|
+
end.flatten.uniq
|
45
|
+
end
|
46
|
+
all.collect do |path|
|
47
|
+
yield YPath.new( path )
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/rubysl-yaml.gemspec
CHANGED
@@ -1,22 +1,24 @@
|
|
1
|
-
#
|
2
|
-
require
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/yaml/version'
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-yaml"
|
6
|
+
spec.version = RubySL::YAML::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library YAML.}
|
10
|
+
spec.summary = %q{Ruby standard library YAML.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-yaml"
|
12
|
+
spec.license = "BSD"
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = RubySL::Yaml::VERSION
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
17
18
|
|
18
|
-
|
19
|
+
spec.add_runtime_dependency "rubysl-syck", "~> 1.0"
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
22
24
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
data/spec/dump_spec.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
2
|
+
|
3
|
+
# TODO: WTF is this using a global?
|
4
|
+
describe "YAML.dump" do
|
5
|
+
after :each do
|
6
|
+
rm_r $test_file
|
7
|
+
end
|
8
|
+
|
9
|
+
it "converts an object to YAML and write result to io when io provided" do
|
10
|
+
File.open($test_file, 'w' ) do |io|
|
11
|
+
YAML.dump( ['badger', 'elephant', 'tiger'], io )
|
12
|
+
end
|
13
|
+
YAML.load_file($test_file).should == ['badger', 'elephant', 'tiger']
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns a string containing dumped YAML when no io provided" do
|
17
|
+
YAML.dump( :locked ).should match_yaml("--- :locked\n")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns the same string that #to_yaml on objects" do
|
21
|
+
["a", "b", "c"].to_yaml.should == YAML.dump(["a", "b", "c"])
|
22
|
+
end
|
23
|
+
|
24
|
+
it "dumps strings into YAML strings" do
|
25
|
+
YAML.dump("str").should match_yaml("--- str\n")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "dumps hashes into YAML key-values" do
|
29
|
+
YAML.dump({ "a" => "b" }).should match_yaml("--- \na: b\n")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "dumps Arrays into YAML collection" do
|
33
|
+
YAML.dump(["a", "b", "c"]).should match_yaml("--- \n- a\n- b\n- c\n")
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
2
|
+
|
3
|
+
describe "YAML.dump_stream" do
|
4
|
+
ruby_version_is "" ... "2.0" do
|
5
|
+
it "returns an empty string when not passed any objects" do
|
6
|
+
YAML.dump_stream.should == ""
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns a YAML stream containing the objects passed" do
|
11
|
+
YAML.dump_stream('foo', 20, [], {}).should match_yaml("--- foo\n--- 20\n--- []\n\n--- {}\n\n")
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/strings', __FILE__)
|
3
|
+
require File.expand_path('../shared/each_document', __FILE__)
|
4
|
+
|
5
|
+
ruby_version_is "" ... "2.0" do
|
6
|
+
describe "YAML#each_document" do
|
7
|
+
it_behaves_like :yaml_each_document, :each_document
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
$complex_key_1 = <<EOY
|
2
|
+
? # PLAY SCHEDULE
|
3
|
+
- Detroit Tigers
|
4
|
+
- Chicago Cubs
|
5
|
+
:
|
6
|
+
- 2001-07-23
|
7
|
+
|
8
|
+
? [ New York Yankees,
|
9
|
+
Atlanta Braves ]
|
10
|
+
: [ 2001-07-02, 2001-08-12,
|
11
|
+
2001-08-14 ]
|
12
|
+
EOY
|
13
|
+
|
14
|
+
$to_yaml_hash =
|
15
|
+
<<EOY
|
16
|
+
-
|
17
|
+
avg: 0.278
|
18
|
+
hr: 65
|
19
|
+
name: Mark McGwire
|
20
|
+
-
|
21
|
+
avg: 0.288
|
22
|
+
hr: 63
|
23
|
+
name: Sammy Sosa
|
24
|
+
EOY
|
25
|
+
|
26
|
+
$multidocument = <<EOY
|
27
|
+
---
|
28
|
+
- Mark McGwire
|
29
|
+
- Sammy Sosa
|
30
|
+
- Ken Griffey
|
31
|
+
|
32
|
+
# Team ranking
|
33
|
+
---
|
34
|
+
- Chicago Cubs
|
35
|
+
- St Louis Cardinals
|
36
|
+
EOY
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/strings', __FILE__)
|
3
|
+
require File.expand_path('../shared/each_document', __FILE__)
|
4
|
+
|
5
|
+
describe "YAML.load_documents" do
|
6
|
+
it_behaves_like :yaml_each_document, :load_documents
|
7
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
2
|
+
|
3
|
+
describe "YAML.load_file" do
|
4
|
+
after :each do
|
5
|
+
rm_r $test_file
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns a hash" do
|
9
|
+
File.open($test_file,'w' ){|io| YAML.dump( {"bar"=>2, "car"=>1}, io ) }
|
10
|
+
YAML.load_file($test_file).should == {"bar"=>2, "car"=>1}
|
11
|
+
end
|
12
|
+
end
|
data/spec/load_spec.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/strings', __FILE__)
|
3
|
+
|
4
|
+
describe "YAML.load" do
|
5
|
+
after :each do
|
6
|
+
rm_r $test_file
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns a document from current io stream when io provided" do
|
10
|
+
File.open($test_file, 'w') do |io|
|
11
|
+
YAML.dump( ['badger', 'elephant', 'tiger'], io )
|
12
|
+
end
|
13
|
+
File.open($test_file) { |yf| YAML.load( yf ) }.should == ['badger', 'elephant', 'tiger']
|
14
|
+
end
|
15
|
+
|
16
|
+
it "loads strings" do
|
17
|
+
strings = ["str",
|
18
|
+
" str",
|
19
|
+
"'str'",
|
20
|
+
"str",
|
21
|
+
" str",
|
22
|
+
"'str'",
|
23
|
+
"\"str\"",
|
24
|
+
"\n str",
|
25
|
+
"--- str",
|
26
|
+
"---\nstr",
|
27
|
+
"--- \nstr",
|
28
|
+
"--- \n str",
|
29
|
+
"--- 'str'"
|
30
|
+
]
|
31
|
+
strings.each do |str|
|
32
|
+
YAML.load(str).should == "str"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "fails on invalid keys" do
|
37
|
+
if YAML.to_s == "Psych"
|
38
|
+
error = Psych::SyntaxError
|
39
|
+
else
|
40
|
+
error = ArgumentError
|
41
|
+
end
|
42
|
+
lambda { YAML.load("key1: value\ninvalid_key") }.should raise_error(error)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "accepts symbols" do
|
46
|
+
YAML.load( "--- :locked" ).should == :locked
|
47
|
+
end
|
48
|
+
|
49
|
+
it "accepts numbers" do
|
50
|
+
YAML.load("47").should == 47
|
51
|
+
YAML.load("-1").should == -1
|
52
|
+
end
|
53
|
+
|
54
|
+
it "accepts collections" do
|
55
|
+
expected = ["a", "b", "c"]
|
56
|
+
YAML.load("--- \n- a\n- b\n- c\n").should == expected
|
57
|
+
YAML.load("--- [a, b, c]").should == expected
|
58
|
+
YAML.load("[a, b, c]").should == expected
|
59
|
+
end
|
60
|
+
|
61
|
+
it "parses start markers" do
|
62
|
+
YAML.load("---\n").should == nil
|
63
|
+
YAML.load("--- ---\n").should == "---"
|
64
|
+
YAML.load("--- abc").should == "abc"
|
65
|
+
end
|
66
|
+
|
67
|
+
ruby_version_is "" ... "2.0" do
|
68
|
+
it "does not escape symbols" do
|
69
|
+
YAML.load("foobar: >= 123").should == { "foobar" => ">= 123"}
|
70
|
+
YAML.load("foobar: |= 567").should == { "foobar" => "|= 567"}
|
71
|
+
YAML.load("--- \n*.rb").should == "*.rb"
|
72
|
+
YAML.load("--- \n&.rb").should == "&.rb"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "works with block sequence shortcuts" do
|
77
|
+
block_seq = "- - - one\n - two\n - three"
|
78
|
+
YAML.load(block_seq).should == [[["one", "two", "three"]]]
|
79
|
+
end
|
80
|
+
|
81
|
+
it "works on complex keys" do
|
82
|
+
expected = {
|
83
|
+
[ 'Detroit Tigers', 'Chicago Cubs' ] => [ Date.new( 2001, 7, 23 ) ],
|
84
|
+
[ 'New York Yankees', 'Atlanta Braves' ] => [ Date.new( 2001, 7, 2 ),
|
85
|
+
Date.new( 2001, 8, 12 ),
|
86
|
+
Date.new( 2001, 8, 14 ) ]
|
87
|
+
}
|
88
|
+
YAML.load($complex_key_1).should == expected
|
89
|
+
end
|
90
|
+
|
91
|
+
it "loads a symbol key that contains spaces" do
|
92
|
+
string = ":user name: This is the user name."
|
93
|
+
expected = { :"user name" => "This is the user name."}
|
94
|
+
YAML.load(string).should == expected
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "with iso8601 timestamp" do
|
98
|
+
it "computes the microseconds" do
|
99
|
+
[ [YAML.load("2011-03-22t23:32:11.2233+01:00"), 223300],
|
100
|
+
[YAML.load("2011-03-22t23:32:11.0099+01:00"), 9900],
|
101
|
+
[YAML.load("2011-03-22t23:32:11.000076+01:00"), 76]
|
102
|
+
].should be_computed_by(:usec)
|
103
|
+
end
|
104
|
+
|
105
|
+
ruby_bug "#4571", "1.9.2" do
|
106
|
+
it "rounds values smaller than 1 usec to 0 " do
|
107
|
+
YAML.load("2011-03-22t23:32:11.000000342222+01:00").usec.should == 0
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|