rubysl-yaml 1.1.0 → 2.0.0
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/.travis.yml +5 -6
- data/lib/rubysl/yaml/version.rb +1 -1
- data/lib/rubysl/yaml/yaml.rb +53 -417
- data/lib/yaml/dbm.rb +116 -13
- data/lib/yaml/store.rb +45 -2
- data/lib/yaml/syck.rb +44 -35
- data/rubysl-yaml.gemspec +1 -3
- metadata +25 -70
- data/ext/rubysl/syck/bytecode.c +0 -1166
- data/ext/rubysl/syck/emitter.c +0 -1242
- data/ext/rubysl/syck/extconf.rb +0 -5
- data/ext/rubysl/syck/gram.c +0 -1894
- data/ext/rubysl/syck/gram.h +0 -79
- data/ext/rubysl/syck/handler.c +0 -174
- data/ext/rubysl/syck/implicit.c +0 -2990
- data/ext/rubysl/syck/node.c +0 -408
- data/ext/rubysl/syck/rubyext.c +0 -2366
- data/ext/rubysl/syck/st.c +0 -576
- data/ext/rubysl/syck/st.h +0 -72
- data/ext/rubysl/syck/syck.c +0 -504
- data/ext/rubysl/syck/syck.h +0 -458
- data/ext/rubysl/syck/token.c +0 -2725
- data/ext/rubysl/syck/yaml2byte.c +0 -257
- data/ext/rubysl/syck/yamlbyte.h +0 -170
- data/lib/yaml/baseemitter.rb +0 -247
- data/lib/yaml/basenode.rb +0 -216
- data/lib/yaml/constants.rb +0 -45
- data/lib/yaml/encoding.rb +0 -33
- data/lib/yaml/error.rb +0 -34
- data/lib/yaml/loader.rb +0 -14
- data/lib/yaml/rubytypes.rb +0 -409
- data/lib/yaml/stream.rb +0 -40
- data/lib/yaml/stringio.rb +0 -83
- data/lib/yaml/tag.rb +0 -91
- data/lib/yaml/types.rb +0 -192
- data/lib/yaml/yamlnode.rb +0 -54
- data/lib/yaml/ypath.rb +0 -52
data/lib/yaml/basenode.rb
DELETED
@@ -1,216 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# YAML::BaseNode class
|
3
|
-
#
|
4
|
-
require 'yaml/ypath'
|
5
|
-
|
6
|
-
module YAML
|
7
|
-
|
8
|
-
#
|
9
|
-
# YAML Generic Model container
|
10
|
-
#
|
11
|
-
module BaseNode
|
12
|
-
|
13
|
-
#
|
14
|
-
# Search for YPath entry and return
|
15
|
-
# qualified nodes.
|
16
|
-
#
|
17
|
-
def select( ypath_str )
|
18
|
-
matches = match_path( ypath_str )
|
19
|
-
|
20
|
-
#
|
21
|
-
# Create a new generic view of the elements selected
|
22
|
-
#
|
23
|
-
if matches
|
24
|
-
result = []
|
25
|
-
matches.each { |m|
|
26
|
-
result.push m.last
|
27
|
-
}
|
28
|
-
YAML.transfer( 'seq', result )
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
#
|
33
|
-
# Search for YPath entry and return
|
34
|
-
# transformed nodes.
|
35
|
-
#
|
36
|
-
def select!( ypath_str )
|
37
|
-
matches = match_path( ypath_str )
|
38
|
-
|
39
|
-
#
|
40
|
-
# Create a new generic view of the elements selected
|
41
|
-
#
|
42
|
-
if matches
|
43
|
-
result = []
|
44
|
-
matches.each { |m|
|
45
|
-
result.push m.last.transform
|
46
|
-
}
|
47
|
-
result
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
#
|
52
|
-
# Search for YPath entry and return a list of
|
53
|
-
# qualified paths.
|
54
|
-
#
|
55
|
-
def search( ypath_str )
|
56
|
-
matches = match_path( ypath_str )
|
57
|
-
|
58
|
-
if matches
|
59
|
-
matches.collect { |m|
|
60
|
-
path = []
|
61
|
-
m.each_index { |i|
|
62
|
-
path.push m[i] if ( i % 2 ).zero?
|
63
|
-
}
|
64
|
-
"/" + path.compact.join( "/" )
|
65
|
-
}
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def at( seg )
|
70
|
-
if Hash === @value
|
71
|
-
self[seg]
|
72
|
-
elsif Array === @value and seg =~ /\A\d+\Z/ and @value[seg.to_i]
|
73
|
-
@value[seg.to_i]
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
#
|
78
|
-
# YPath search returning a complete depth array
|
79
|
-
#
|
80
|
-
def match_path( ypath_str )
|
81
|
-
depth = 0
|
82
|
-
matches = []
|
83
|
-
YPath.each_path( ypath_str ) do |ypath|
|
84
|
-
seg = match_segment( ypath, 0 )
|
85
|
-
matches += seg if seg
|
86
|
-
end
|
87
|
-
matches.uniq
|
88
|
-
end
|
89
|
-
|
90
|
-
#
|
91
|
-
# Search a node for a single YPath segment
|
92
|
-
#
|
93
|
-
def match_segment( ypath, depth )
|
94
|
-
deep_nodes = []
|
95
|
-
seg = ypath.segments[ depth ]
|
96
|
-
if seg == "/"
|
97
|
-
unless String === @value
|
98
|
-
idx = -1
|
99
|
-
@value.collect { |v|
|
100
|
-
idx += 1
|
101
|
-
if Hash === @value
|
102
|
-
match_init = [v[0].transform, v[1]]
|
103
|
-
match_deep = v[1].match_segment( ypath, depth )
|
104
|
-
else
|
105
|
-
match_init = [idx, v]
|
106
|
-
match_deep = v.match_segment( ypath, depth )
|
107
|
-
end
|
108
|
-
if match_deep
|
109
|
-
match_deep.each { |m|
|
110
|
-
deep_nodes.push( match_init + m )
|
111
|
-
}
|
112
|
-
end
|
113
|
-
}
|
114
|
-
end
|
115
|
-
depth += 1
|
116
|
-
seg = ypath.segments[ depth ]
|
117
|
-
end
|
118
|
-
match_nodes =
|
119
|
-
case seg
|
120
|
-
when "."
|
121
|
-
[[nil, self]]
|
122
|
-
when ".."
|
123
|
-
[["..", nil]]
|
124
|
-
when "*"
|
125
|
-
if @value.is_a? Enumerable
|
126
|
-
idx = -1
|
127
|
-
@value.collect { |h|
|
128
|
-
idx += 1
|
129
|
-
if Hash === @value
|
130
|
-
[h[0].transform, h[1]]
|
131
|
-
else
|
132
|
-
[idx, h]
|
133
|
-
end
|
134
|
-
}
|
135
|
-
end
|
136
|
-
else
|
137
|
-
if seg =~ /^"(.*)"$/
|
138
|
-
seg = $1
|
139
|
-
elsif seg =~ /^'(.*)'$/
|
140
|
-
seg = $1
|
141
|
-
end
|
142
|
-
if ( v = at( seg ) )
|
143
|
-
[[ seg, v ]]
|
144
|
-
end
|
145
|
-
end
|
146
|
-
return deep_nodes unless match_nodes
|
147
|
-
pred = ypath.predicates[ depth ]
|
148
|
-
if pred
|
149
|
-
case pred
|
150
|
-
when /^\.=/
|
151
|
-
pred = $' # '
|
152
|
-
match_nodes.reject! { |n|
|
153
|
-
n.last.value != pred
|
154
|
-
}
|
155
|
-
else
|
156
|
-
match_nodes.reject! { |n|
|
157
|
-
n.last.at( pred ).nil?
|
158
|
-
}
|
159
|
-
end
|
160
|
-
end
|
161
|
-
return match_nodes + deep_nodes unless ypath.segments.length > depth + 1
|
162
|
-
|
163
|
-
#puts "DEPTH: #{depth + 1}"
|
164
|
-
deep_nodes = []
|
165
|
-
match_nodes.each { |n|
|
166
|
-
if n[1].is_a? BaseNode
|
167
|
-
match_deep = n[1].match_segment( ypath, depth + 1 )
|
168
|
-
if match_deep
|
169
|
-
match_deep.each { |m|
|
170
|
-
deep_nodes.push( n + m )
|
171
|
-
}
|
172
|
-
end
|
173
|
-
else
|
174
|
-
deep_nodes = []
|
175
|
-
end
|
176
|
-
}
|
177
|
-
deep_nodes = nil if deep_nodes.length == 0
|
178
|
-
deep_nodes
|
179
|
-
end
|
180
|
-
|
181
|
-
#
|
182
|
-
# We want the node to act like as Hash
|
183
|
-
# if it is.
|
184
|
-
#
|
185
|
-
def []( *key )
|
186
|
-
if Hash === @value
|
187
|
-
v = @value.detect { |k,| k.transform == key.first }
|
188
|
-
v[1] if v
|
189
|
-
elsif Array === @value
|
190
|
-
@value.[]( *key )
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def children
|
195
|
-
if Hash === @value
|
196
|
-
@value.values.collect { |c| c[1] }
|
197
|
-
elsif Array === @value
|
198
|
-
@value
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def children_with_index
|
203
|
-
if Hash === @value
|
204
|
-
@value.keys.collect { |i| [self[i], i] }
|
205
|
-
elsif Array === @value
|
206
|
-
i = -1; @value.collect { |v| i += 1; [v, i] }
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
def emit
|
211
|
-
transform.to_yaml
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
end
|
216
|
-
|
data/lib/yaml/constants.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Constants used throughout the library
|
3
|
-
#
|
4
|
-
module YAML
|
5
|
-
|
6
|
-
#
|
7
|
-
# Constants
|
8
|
-
#
|
9
|
-
VERSION = '0.60'
|
10
|
-
SUPPORTED_YAML_VERSIONS = ['1.0']
|
11
|
-
|
12
|
-
#
|
13
|
-
# Parser tokens
|
14
|
-
#
|
15
|
-
WORD_CHAR = 'A-Za-z0-9'
|
16
|
-
PRINTABLE_CHAR = '-_A-Za-z0-9!?/()$\'". '
|
17
|
-
NOT_PLAIN_CHAR = '\x7f\x0-\x1f\x80-\x9f'
|
18
|
-
ESCAPE_CHAR = '[\\x00-\\x09\\x0b-\\x1f]'
|
19
|
-
INDICATOR_CHAR = '*&!|\\\\^@%{}[]='
|
20
|
-
SPACE_INDICATORS = '-#:,?'
|
21
|
-
RESTRICTED_INDICATORS = '#:,}]'
|
22
|
-
DNS_COMP_RE = "\\w(?:[-\\w]*\\w)?"
|
23
|
-
DNS_NAME_RE = "(?:(?:#{DNS_COMP_RE}\\.)+#{DNS_COMP_RE}|#{DNS_COMP_RE})"
|
24
|
-
ESCAPES = %w{\x00 \x01 \x02 \x03 \x04 \x05 \x06 \a
|
25
|
-
\x08 \t \n \v \f \r \x0e \x0f
|
26
|
-
\x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17
|
27
|
-
\x18 \x19 \x1a \e \x1c \x1d \x1e \x1f
|
28
|
-
}
|
29
|
-
UNESCAPES = {
|
30
|
-
'a' => "\x07", 'b' => "\x08", 't' => "\x09",
|
31
|
-
'n' => "\x0a", 'v' => "\x0b", 'f' => "\x0c",
|
32
|
-
'r' => "\x0d", 'e' => "\x1b", '\\' => '\\',
|
33
|
-
}
|
34
|
-
|
35
|
-
#
|
36
|
-
# Default settings
|
37
|
-
#
|
38
|
-
DEFAULTS = {
|
39
|
-
:Indent => 2, :UseHeader => false, :UseVersion => false, :Version => '1.0',
|
40
|
-
:SortKeys => false, :AnchorFormat => 'id%03d', :ExplicitTypes => false,
|
41
|
-
:WidthType => 'absolute', :BestWidth => 80,
|
42
|
-
:UseBlock => false, :UseFold => false, :Encoding => :None
|
43
|
-
}
|
44
|
-
|
45
|
-
end
|
data/lib/yaml/encoding.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Handle Unicode-to-Internal conversion
|
3
|
-
#
|
4
|
-
|
5
|
-
module YAML
|
6
|
-
|
7
|
-
#
|
8
|
-
# Escape the string, condensing common escapes
|
9
|
-
#
|
10
|
-
def YAML.escape( value, skip = "" )
|
11
|
-
value.gsub( /\\/, "\\\\\\" ).
|
12
|
-
gsub( /"/, "\\\"" ).
|
13
|
-
gsub( /([\x00-\x1f])/ ) do |x|
|
14
|
-
skip[x] || ESCAPES[ x.unpack("C")[0] ]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
#
|
19
|
-
# Unescape the condenses escapes
|
20
|
-
#
|
21
|
-
def YAML.unescape( value )
|
22
|
-
value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) { |x|
|
23
|
-
if $3
|
24
|
-
["#$3".hex ].pack('U*')
|
25
|
-
elsif $2
|
26
|
-
[$2].pack( "H2" )
|
27
|
-
else
|
28
|
-
UNESCAPES[$1]
|
29
|
-
end
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
data/lib/yaml/error.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Error messages and exception class
|
3
|
-
#
|
4
|
-
|
5
|
-
module YAML
|
6
|
-
|
7
|
-
#
|
8
|
-
# Error messages
|
9
|
-
#
|
10
|
-
|
11
|
-
ERROR_NO_HEADER_NODE = "With UseHeader=false, the node Array or Hash must have elements"
|
12
|
-
ERROR_NEED_HEADER = "With UseHeader=false, the node must be an Array or Hash"
|
13
|
-
ERROR_BAD_EXPLICIT = "Unsupported explicit transfer: '%s'"
|
14
|
-
ERROR_MANY_EXPLICIT = "More than one explicit transfer"
|
15
|
-
ERROR_MANY_IMPLICIT = "More than one implicit request"
|
16
|
-
ERROR_NO_ANCHOR = "No anchor for alias '%s'"
|
17
|
-
ERROR_BAD_ANCHOR = "Invalid anchor: %s"
|
18
|
-
ERROR_MANY_ANCHOR = "More than one anchor"
|
19
|
-
ERROR_ANCHOR_ALIAS = "Can't define both an anchor and an alias"
|
20
|
-
ERROR_BAD_ALIAS = "Invalid alias: %s"
|
21
|
-
ERROR_MANY_ALIAS = "More than one alias"
|
22
|
-
ERROR_ZERO_INDENT = "Can't use zero as an indentation width"
|
23
|
-
ERROR_UNSUPPORTED_VERSION = "This release of YAML.rb does not support YAML version %s"
|
24
|
-
ERROR_UNSUPPORTED_ENCODING = "Attempt to use unsupported encoding: %s"
|
25
|
-
|
26
|
-
#
|
27
|
-
# YAML Error classes
|
28
|
-
#
|
29
|
-
|
30
|
-
class Error < StandardError; end
|
31
|
-
class ParseError < Error; end
|
32
|
-
class TypeError < StandardError; end
|
33
|
-
|
34
|
-
end
|
data/lib/yaml/loader.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# YAML::Loader class
|
3
|
-
# .. type handling ..
|
4
|
-
#
|
5
|
-
module YAML
|
6
|
-
class Loader
|
7
|
-
TRANSFER_DOMAINS = {
|
8
|
-
'yaml.org,2002' => {},
|
9
|
-
'ruby.yaml.org,2002' => {}
|
10
|
-
}
|
11
|
-
PRIVATE_TYPES = {}
|
12
|
-
IMPLICIT_TYPES = [ 'null', 'bool', 'time', 'int', 'float' ]
|
13
|
-
end
|
14
|
-
end
|
data/lib/yaml/rubytypes.rb
DELETED
@@ -1,409 +0,0 @@
|
|
1
|
-
# -*- mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- vim: sw=4 ts=4
|
2
|
-
require 'date'
|
3
|
-
|
4
|
-
class Class
|
5
|
-
def to_yaml( opts = {} )
|
6
|
-
raise TypeError, "can't dump anonymous class %s" % self.class
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class Object
|
11
|
-
yaml_as "tag:ruby.yaml.org,2002:object"
|
12
|
-
def to_yaml_style; end
|
13
|
-
def to_yaml_properties; instance_variables.sort; end
|
14
|
-
def to_yaml( opts = {} )
|
15
|
-
YAML::quick_emit( self, opts ) do |out|
|
16
|
-
out.map( taguri, to_yaml_style ) do |map|
|
17
|
-
to_yaml_properties.each do |m|
|
18
|
-
map.add( m[1..-1], instance_variable_get( m ) )
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class Hash
|
26
|
-
yaml_as "tag:ruby.yaml.org,2002:hash"
|
27
|
-
yaml_as "tag:yaml.org,2002:map"
|
28
|
-
def yaml_initialize( tag, val )
|
29
|
-
if Array === val
|
30
|
-
update Hash.[]( *val ) # Convert the map to a sequence
|
31
|
-
elsif Hash === val
|
32
|
-
update val
|
33
|
-
else
|
34
|
-
raise YAML::TypeError, "Invalid map explicitly tagged #{ tag }: " + val.inspect
|
35
|
-
end
|
36
|
-
end
|
37
|
-
def to_yaml( opts = {} )
|
38
|
-
YAML::quick_emit( self, opts ) do |out|
|
39
|
-
out.map( taguri, to_yaml_style ) do |map|
|
40
|
-
each do |k, v|
|
41
|
-
map.add( k, v )
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
class Struct
|
49
|
-
yaml_as "tag:ruby.yaml.org,2002:struct"
|
50
|
-
def self.yaml_tag_class_name; self.name.gsub( "Struct::", "" ); end
|
51
|
-
def self.yaml_tag_read_class( name ); "Struct::#{ name }"; end
|
52
|
-
def self.yaml_new( klass, tag, val )
|
53
|
-
if Hash === val
|
54
|
-
struct_type = nil
|
55
|
-
|
56
|
-
#
|
57
|
-
# Use existing Struct if it exists
|
58
|
-
#
|
59
|
-
props = {}
|
60
|
-
val.delete_if { |k,v| props[k] = v if k =~ /^@/ }
|
61
|
-
begin
|
62
|
-
struct_name, struct_type = YAML.read_type_class( tag, Struct )
|
63
|
-
rescue NameError
|
64
|
-
end
|
65
|
-
if not struct_type
|
66
|
-
struct_def = [ tag.split( ':', 4 ).last ]
|
67
|
-
struct_type = Struct.new( *struct_def.concat( val.keys.collect { |k| k.intern } ) )
|
68
|
-
end
|
69
|
-
|
70
|
-
#
|
71
|
-
# Set the Struct properties
|
72
|
-
#
|
73
|
-
st = YAML::object_maker( struct_type, {} )
|
74
|
-
st.members.each do |m|
|
75
|
-
st.send( "#{m}=", val[m] )
|
76
|
-
end
|
77
|
-
props.each do |k,v|
|
78
|
-
st.instance_variable_set(k, v)
|
79
|
-
end
|
80
|
-
st
|
81
|
-
else
|
82
|
-
raise YAML::TypeError, "Invalid Ruby Struct: " + val.inspect
|
83
|
-
end
|
84
|
-
end
|
85
|
-
def to_yaml( opts = {} )
|
86
|
-
YAML::quick_emit( self, opts ) do |out|
|
87
|
-
#
|
88
|
-
# Basic struct is passed as a YAML map
|
89
|
-
#
|
90
|
-
out.map( taguri, to_yaml_style ) do |map|
|
91
|
-
self.members.each do |m|
|
92
|
-
map.add( m, self[m] )
|
93
|
-
end
|
94
|
-
self.to_yaml_properties.each do |m|
|
95
|
-
map.add( m, instance_variable_get( m ) )
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
class Array
|
103
|
-
yaml_as "tag:ruby.yaml.org,2002:array"
|
104
|
-
yaml_as "tag:yaml.org,2002:seq"
|
105
|
-
def yaml_initialize( tag, val ); concat( val.to_a ); end
|
106
|
-
def to_yaml( opts = {} )
|
107
|
-
YAML::quick_emit( self, opts ) do |out|
|
108
|
-
out.seq( taguri, to_yaml_style ) do |seq|
|
109
|
-
each do |x|
|
110
|
-
seq.add( x )
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
class Exception
|
118
|
-
yaml_as "tag:ruby.yaml.org,2002:exception"
|
119
|
-
def Exception.yaml_new( klass, tag, val )
|
120
|
-
o = YAML.object_maker( klass, { 'mesg' => val.delete( 'message' ) } )
|
121
|
-
val.each_pair do |k,v|
|
122
|
-
o.instance_variable_set("@#{k}", v)
|
123
|
-
end
|
124
|
-
o
|
125
|
-
end
|
126
|
-
def to_yaml( opts = {} )
|
127
|
-
YAML::quick_emit( self, opts ) do |out|
|
128
|
-
out.map( taguri, to_yaml_style ) do |map|
|
129
|
-
map.add( 'message', message )
|
130
|
-
to_yaml_properties.each do |m|
|
131
|
-
map.add( m[1..-1], instance_variable_get( m ) )
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
class String
|
139
|
-
yaml_as "tag:ruby.yaml.org,2002:string"
|
140
|
-
yaml_as "tag:yaml.org,2002:binary"
|
141
|
-
yaml_as "tag:yaml.org,2002:str"
|
142
|
-
def is_complex_yaml?
|
143
|
-
to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/
|
144
|
-
end
|
145
|
-
def is_binary_data?
|
146
|
-
# It's binary if it's got a null.
|
147
|
-
index(0)
|
148
|
-
end
|
149
|
-
def String.yaml_new( klass, tag, val )
|
150
|
-
val = val.unpack("m")[0] if tag == "tag:yaml.org,2002:binary"
|
151
|
-
val = { 'str' => val } if String === val
|
152
|
-
if Hash === val
|
153
|
-
s = klass.allocate
|
154
|
-
# Thank you, NaHi
|
155
|
-
String.instance_method(:initialize).
|
156
|
-
bind(s).
|
157
|
-
call( val.delete( 'str' ) )
|
158
|
-
val.each { |k,v| s.instance_variable_set( k, v ) }
|
159
|
-
s
|
160
|
-
else
|
161
|
-
raise YAML::TypeError, "Invalid String: " + val.inspect
|
162
|
-
end
|
163
|
-
end
|
164
|
-
def to_yaml( opts = {} )
|
165
|
-
YAML::quick_emit( is_complex_yaml? ? self : nil, opts ) do |out|
|
166
|
-
if is_binary_data?
|
167
|
-
out.scalar( "tag:yaml.org,2002:binary", [self].pack("m"), :literal )
|
168
|
-
elsif to_yaml_properties.empty?
|
169
|
-
out.scalar( taguri, self, self =~ /^:/ ? :quote2 : to_yaml_style )
|
170
|
-
else
|
171
|
-
out.map( taguri, to_yaml_style ) do |map|
|
172
|
-
map.add( 'str', "#{self}" )
|
173
|
-
to_yaml_properties.each do |m|
|
174
|
-
map.add( m, instance_variable_get( m ) )
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
class Symbol
|
183
|
-
yaml_as "tag:ruby.yaml.org,2002:symbol"
|
184
|
-
yaml_as "tag:ruby.yaml.org,2002:sym"
|
185
|
-
def Symbol.yaml_new( klass, tag, val )
|
186
|
-
if String === val
|
187
|
-
val = YAML::load( val ) if val =~ /\A(["']).*\1\z/
|
188
|
-
val.intern
|
189
|
-
else
|
190
|
-
raise YAML::TypeError, "Invalid Symbol: " + val.inspect
|
191
|
-
end
|
192
|
-
end
|
193
|
-
def to_yaml( opts = {} )
|
194
|
-
YAML::quick_emit( nil, opts ) do |out|
|
195
|
-
out.scalar( "tag:yaml.org,2002:str", self.inspect, :plain )
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
class Range
|
201
|
-
yaml_as "tag:ruby.yaml.org,2002:range"
|
202
|
-
def Range.yaml_new( klass, tag, val )
|
203
|
-
inr = %r'(\w+|[+-]?\d+(?:\.\d+)?(?:e[+-]\d+)?|"(?:[^\\"]|\\.)*")'
|
204
|
-
opts = {}
|
205
|
-
if String === val and val =~ /^#{inr}(\.{2,3})#{inr}$/o
|
206
|
-
r1, rdots, r2 = $1, $2, $3
|
207
|
-
opts = {
|
208
|
-
'begin' => YAML.load( "--- #{r1}" ),
|
209
|
-
'end' => YAML.load( "--- #{r2}" ),
|
210
|
-
'excl' => rdots.length == 3
|
211
|
-
}
|
212
|
-
val = {}
|
213
|
-
elsif Hash === val
|
214
|
-
opts['begin'] = val.delete('begin')
|
215
|
-
opts['end'] = val.delete('end')
|
216
|
-
opts['excl'] = val.delete('excl')
|
217
|
-
end
|
218
|
-
if Hash === opts
|
219
|
-
r = YAML::object_maker( klass, {} )
|
220
|
-
# Thank you, NaHi
|
221
|
-
Range.instance_method(:initialize).
|
222
|
-
bind(r).
|
223
|
-
call( opts['begin'], opts['end'], opts['excl'] )
|
224
|
-
val.each { |k,v| r.instance_variable_set( k, v ) }
|
225
|
-
r
|
226
|
-
else
|
227
|
-
raise YAML::TypeError, "Invalid Range: " + val.inspect
|
228
|
-
end
|
229
|
-
end
|
230
|
-
def to_yaml( opts = {} )
|
231
|
-
YAML::quick_emit( self, opts ) do |out|
|
232
|
-
# if self.begin.is_complex_yaml? or self.begin.respond_to? :to_str or
|
233
|
-
# self.end.is_complex_yaml? or self.end.respond_to? :to_str or
|
234
|
-
# not to_yaml_properties.empty?
|
235
|
-
out.map( taguri, to_yaml_style ) do |map|
|
236
|
-
map.add( 'begin', self.begin )
|
237
|
-
map.add( 'end', self.end )
|
238
|
-
map.add( 'excl', self.exclude_end? )
|
239
|
-
to_yaml_properties.each do |m|
|
240
|
-
map.add( m, instance_variable_get( m ) )
|
241
|
-
end
|
242
|
-
end
|
243
|
-
# else
|
244
|
-
# out.scalar( taguri ) do |sc|
|
245
|
-
# sc.embed( self.begin )
|
246
|
-
# sc.concat( self.exclude_end? ? "..." : ".." )
|
247
|
-
# sc.embed( self.end )
|
248
|
-
# end
|
249
|
-
# end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
class Regexp
|
255
|
-
yaml_as "tag:ruby.yaml.org,2002:regexp"
|
256
|
-
def Regexp.yaml_new( klass, tag, val )
|
257
|
-
if String === val and val =~ /^\/(.*)\/([mix]*)$/
|
258
|
-
val = { 'regexp' => $1, 'mods' => $2 }
|
259
|
-
end
|
260
|
-
if Hash === val
|
261
|
-
mods = nil
|
262
|
-
unless val['mods'].to_s.empty?
|
263
|
-
mods = 0x00
|
264
|
-
mods |= Regexp::EXTENDED if val['mods'].include?( 'x' )
|
265
|
-
mods |= Regexp::IGNORECASE if val['mods'].include?( 'i' )
|
266
|
-
mods |= Regexp::MULTILINE if val['mods'].include?( 'm' )
|
267
|
-
end
|
268
|
-
val.delete( 'mods' )
|
269
|
-
r = YAML::object_maker( klass, {} )
|
270
|
-
Regexp.instance_method(:initialize).
|
271
|
-
bind(r).
|
272
|
-
call( val.delete( 'regexp' ), mods )
|
273
|
-
val.each { |k,v| r.instance_variable_set( k, v ) }
|
274
|
-
r
|
275
|
-
else
|
276
|
-
raise YAML::TypeError, "Invalid Regular expression: " + val.inspect
|
277
|
-
end
|
278
|
-
end
|
279
|
-
def to_yaml( opts = {} )
|
280
|
-
YAML::quick_emit( nil, opts ) do |out|
|
281
|
-
if to_yaml_properties.empty?
|
282
|
-
out.scalar( taguri, self.inspect, :plain )
|
283
|
-
else
|
284
|
-
out.map( taguri, to_yaml_style ) do |map|
|
285
|
-
src = self.inspect
|
286
|
-
if src =~ /\A\/(.*)\/([a-z]*)\Z/
|
287
|
-
map.add( 'regexp', $1 )
|
288
|
-
map.add( 'mods', $2 )
|
289
|
-
else
|
290
|
-
raise YAML::TypeError, "Invalid Regular expression: " + src
|
291
|
-
end
|
292
|
-
to_yaml_properties.each do |m|
|
293
|
-
map.add( m, instance_variable_get( m ) )
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
class Time
|
302
|
-
yaml_as "tag:ruby.yaml.org,2002:time"
|
303
|
-
yaml_as "tag:yaml.org,2002:timestamp"
|
304
|
-
def Time.yaml_new( klass, tag, val )
|
305
|
-
if Hash === val
|
306
|
-
t = val.delete( 'at' )
|
307
|
-
val.each { |k,v| t.instance_variable_set( k, v ) }
|
308
|
-
t
|
309
|
-
else
|
310
|
-
raise YAML::TypeError, "Invalid Time: " + val.inspect
|
311
|
-
end
|
312
|
-
end
|
313
|
-
def to_yaml( opts = {} )
|
314
|
-
YAML::quick_emit( self, opts ) do |out|
|
315
|
-
tz = "Z"
|
316
|
-
# from the tidy Tobias Peters <t-peters@gmx.de> Thanks!
|
317
|
-
unless self.utc?
|
318
|
-
utc_same_instant = self.dup.utc
|
319
|
-
utc_same_writing = Time.utc(year,month,day,hour,min,sec,usec)
|
320
|
-
difference_to_utc = utc_same_writing - utc_same_instant
|
321
|
-
if (difference_to_utc < 0)
|
322
|
-
difference_sign = '-'
|
323
|
-
absolute_difference = -difference_to_utc
|
324
|
-
else
|
325
|
-
difference_sign = '+'
|
326
|
-
absolute_difference = difference_to_utc
|
327
|
-
end
|
328
|
-
difference_minutes = (absolute_difference/60).round
|
329
|
-
tz = "%s%02d:%02d" % [ difference_sign, difference_minutes / 60, difference_minutes % 60]
|
330
|
-
end
|
331
|
-
standard = self.strftime( "%Y-%m-%d %H:%M:%S" )
|
332
|
-
standard += ".%06d" % [usec] if usec.nonzero?
|
333
|
-
standard += " %s" % [tz]
|
334
|
-
if to_yaml_properties.empty?
|
335
|
-
out.scalar( taguri, standard, :plain )
|
336
|
-
else
|
337
|
-
out.map( taguri, to_yaml_style ) do |map|
|
338
|
-
map.add( 'at', standard )
|
339
|
-
to_yaml_properties.each do |m|
|
340
|
-
map.add( m, instance_variable_get( m ) )
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
class Date
|
349
|
-
yaml_as "tag:yaml.org,2002:timestamp#ymd"
|
350
|
-
def to_yaml( opts = {} )
|
351
|
-
YAML::quick_emit( self, opts ) do |out|
|
352
|
-
out.scalar( "tag:yaml.org,2002:timestamp", self.to_s, :plain )
|
353
|
-
end
|
354
|
-
end
|
355
|
-
end
|
356
|
-
|
357
|
-
class Integer
|
358
|
-
yaml_as "tag:yaml.org,2002:int"
|
359
|
-
def to_yaml( opts = {} )
|
360
|
-
YAML::quick_emit( nil, opts ) do |out|
|
361
|
-
out.scalar( "tag:yaml.org,2002:int", self.to_s, :plain )
|
362
|
-
end
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
class Float
|
367
|
-
yaml_as "tag:yaml.org,2002:float"
|
368
|
-
def to_yaml( opts = {} )
|
369
|
-
YAML::quick_emit( nil, opts ) do |out|
|
370
|
-
str = self.to_s
|
371
|
-
if str == "Infinity"
|
372
|
-
str = ".Inf"
|
373
|
-
elsif str == "-Infinity"
|
374
|
-
str = "-.Inf"
|
375
|
-
elsif str == "NaN"
|
376
|
-
str = ".NaN"
|
377
|
-
end
|
378
|
-
out.scalar( "tag:yaml.org,2002:float", str, :plain )
|
379
|
-
end
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
class TrueClass
|
384
|
-
yaml_as "tag:yaml.org,2002:bool#yes"
|
385
|
-
def to_yaml( opts = {} )
|
386
|
-
YAML::quick_emit( nil, opts ) do |out|
|
387
|
-
out.scalar( taguri, "true", :plain )
|
388
|
-
end
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
class FalseClass
|
393
|
-
yaml_as "tag:yaml.org,2002:bool#no"
|
394
|
-
def to_yaml( opts = {} )
|
395
|
-
YAML::quick_emit( nil, opts ) do |out|
|
396
|
-
out.scalar( taguri, "false", :plain )
|
397
|
-
end
|
398
|
-
end
|
399
|
-
end
|
400
|
-
|
401
|
-
class NilClass
|
402
|
-
yaml_as "tag:yaml.org,2002:null"
|
403
|
-
def to_yaml( opts = {} )
|
404
|
-
YAML::quick_emit( nil, opts ) do |out|
|
405
|
-
out.scalar( taguri, "", :plain )
|
406
|
-
end
|
407
|
-
end
|
408
|
-
end
|
409
|
-
|