rubysl-yaml 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/yaml/stream.rb DELETED
@@ -1,40 +0,0 @@
1
- module YAML
2
-
3
- #
4
- # YAML::Stream -- for emitting many documents
5
- #
6
- class Stream
7
-
8
- attr_accessor :documents, :options
9
-
10
- def initialize( opts = {} )
11
- @options = opts
12
- @documents = []
13
- end
14
-
15
- def []( i )
16
- @documents[ i ]
17
- end
18
-
19
- def add( doc )
20
- @documents << doc
21
- end
22
-
23
- def edit( doc_num, doc )
24
- @documents[ doc_num ] = doc
25
- end
26
-
27
- def emit( io = nil )
28
- # opts = @options.dup
29
- # opts[:UseHeader] = true if @documents.length > 1
30
- out = YAML.emitter
31
- out.reset( io || io2 = StringIO.new )
32
- @documents.each { |v|
33
- v.to_yaml( out )
34
- }
35
- io || ( io2.rewind; io2.read )
36
- end
37
-
38
- end
39
-
40
- end
data/lib/yaml/stringio.rb DELETED
@@ -1,83 +0,0 @@
1
- #
2
- # Limited StringIO if no core lib is available
3
- #
4
- begin
5
- require 'stringio'
6
- rescue LoadError
7
- # StringIO based on code by MoonWolf
8
- class StringIO
9
- def initialize(string="")
10
- @string=string
11
- @pos=0
12
- @eof=(string.size==0)
13
- end
14
- def pos
15
- @pos
16
- end
17
- def eof
18
- @eof
19
- end
20
- alias eof? eof
21
- def readline(rs=$/)
22
- if @eof
23
- raise EOFError
24
- else
25
- if p = @string[@pos..-1]=~rs
26
- line = @string[@pos,p+1]
27
- else
28
- line = @string[@pos..-1]
29
- end
30
- @pos+=line.size
31
- @eof =true if @pos==@string.size
32
- $_ = line
33
- end
34
- end
35
- def rewind
36
- seek(0,0)
37
- end
38
- def seek(offset,whence)
39
- case whence
40
- when 0
41
- @pos=offset
42
- when 1
43
- @pos+=offset
44
- when 2
45
- @pos=@string.size+offset
46
- end
47
- @eof=(@pos>=@string.size)
48
- 0
49
- end
50
- end
51
-
52
- #
53
- # Class method for creating streams
54
- #
55
- def YAML.make_stream( io )
56
- if String === io
57
- io = StringIO.new( io )
58
- elsif not IO === io
59
- raise YAML::Error, "YAML stream must be an IO or String object."
60
- end
61
- if YAML::unicode
62
- def io.readline
63
- YAML.utf_to_internal( readline( @ln_sep ), @utf_encoding )
64
- end
65
- def io.check_unicode
66
- @utf_encoding = YAML.sniff_encoding( read( 4 ) )
67
- @ln_sep = YAML.enc_separator( @utf_encoding )
68
- seek( -4, IO::SEEK_CUR )
69
- end
70
- def io.utf_encoding
71
- @utf_encoding
72
- end
73
- io.check_unicode
74
- else
75
- def io.utf_encoding
76
- :None
77
- end
78
- end
79
- io
80
- end
81
-
82
- end
83
-
data/lib/yaml/tag.rb DELETED
@@ -1,91 +0,0 @@
1
- # -*- mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- vim: sw=4 ts=4
2
- # $Id: tag.rb 11708 2007-02-12 23:01:19Z shyouhei $
3
- #
4
- # = yaml/tag.rb: methods for associating a taguri to a class.
5
- #
6
- # Author:: why the lucky stiff
7
- #
8
- module YAML
9
- # A dictionary of taguris which map to
10
- # Ruby classes.
11
- @@tagged_classes = {}
12
-
13
- #
14
- # Associates a taguri _tag_ with a Ruby class _cls_. The taguri is used to give types
15
- # to classes when loading YAML. Taguris are of the form:
16
- #
17
- # tag:authorityName,date:specific
18
- #
19
- # The +authorityName+ is a domain name or email address. The +date+ is the date the type
20
- # was issued in YYYY or YYYY-MM or YYYY-MM-DD format. The +specific+ is a name for
21
- # the type being added.
22
- #
23
- # For example, built-in YAML types have 'yaml.org' as the +authorityName+ and '2002' as the
24
- # +date+. The +specific+ is simply the name of the type:
25
- #
26
- # tag:yaml.org,2002:int
27
- # tag:yaml.org,2002:float
28
- # tag:yaml.org,2002:timestamp
29
- #
30
- # The domain must be owned by you on the +date+ declared. If you don't own any domains on the
31
- # date you declare the type, you can simply use an e-mail address.
32
- #
33
- # tag:why@ruby-lang.org,2004:notes/personal
34
- #
35
- def YAML.tag_class( tag, cls )
36
- if @@tagged_classes.has_key? tag
37
- warn "class #{ @@tagged_classes[tag] } held ownership of the #{ tag } tag"
38
- end
39
- @@tagged_classes[tag] = cls
40
- end
41
-
42
- # Returns the complete dictionary of taguris, paired with classes. The key for
43
- # the dictionary is the full taguri. The value for each key is the class constant
44
- # associated to that taguri.
45
- #
46
- # YAML.tagged_classes["tag:yaml.org,2002:int"] => Integer
47
- #
48
- def YAML.tagged_classes
49
- @@tagged_classes
50
- end
51
- end
52
-
53
- class Module
54
- # :stopdoc:
55
-
56
- # Adds a taguri _tag_ to a class, used when dumping or loading the class
57
- # in YAML. See YAML::tag_class for detailed information on typing and
58
- # taguris.
59
- def yaml_as( tag, sc = true )
60
- verbose, $VERBOSE = $VERBOSE, nil
61
- class_eval <<-"end;", __FILE__, __LINE__+1
62
- attr_writer :taguri
63
- def taguri
64
- if respond_to? :to_yaml_type
65
- YAML::tagurize( to_yaml_type[1..-1] )
66
- else
67
- return @taguri if defined?(@taguri) and @taguri
68
- tag = #{ tag.dump }
69
- if self.class.yaml_tag_subclasses? and self.class != YAML::tagged_classes[tag]
70
- tag = "\#{ tag }:\#{ self.class.yaml_tag_class_name }"
71
- end
72
- tag
73
- end
74
- end
75
- def self.yaml_tag_subclasses?; #{ sc ? 'true' : 'false' }; end
76
- end;
77
- YAML::tag_class tag, self
78
- ensure
79
- $VERBOSE = verbose
80
- end
81
- # Transforms the subclass name into a name suitable for display
82
- # in a subclassed tag.
83
- def yaml_tag_class_name
84
- self.name
85
- end
86
- # Transforms the subclass name found in the tag into a Ruby
87
- # constant name.
88
- def yaml_tag_read_class( name )
89
- name
90
- end
91
- end
data/lib/yaml/types.rb DELETED
@@ -1,192 +0,0 @@
1
- # -*- mode: ruby; ruby-indent-level: 4 -*- vim: sw=4
2
- #
3
- # Classes required by the full core typeset
4
- #
5
-
6
- module YAML
7
-
8
- #
9
- # Default private type
10
- #
11
- class PrivateType
12
- def self.tag_subclasses?; false; end
13
- verbose, $VERBOSE = $VERBOSE, nil
14
- def initialize( type, val )
15
- @type_id = type; @value = val
16
- @value.taguri = "x-private:#{ @type_id }"
17
- end
18
- def to_yaml( opts = {} )
19
- @value.to_yaml( opts )
20
- end
21
- ensure
22
- $VERBOSE = verbose
23
- end
24
-
25
- #
26
- # Default domain type
27
- #
28
- class DomainType
29
- def self.tag_subclasses?; false; end
30
- verbose, $VERBOSE = $VERBOSE, nil
31
- def initialize( domain, type, val )
32
- @domain = domain; @type_id = type; @value = val
33
- @value.taguri = "tag:#{ @domain }:#{ @type_id }"
34
- end
35
- def to_yaml( opts = {} )
36
- @value.to_yaml( opts )
37
- end
38
- ensure
39
- $VERBOSE = verbose
40
- end
41
-
42
- #
43
- # Unresolved objects
44
- #
45
- class Object
46
- def self.tag_subclasses?; false; end
47
- def to_yaml( opts = {} )
48
- YAML::quick_emit( self, opts ) do |out|
49
- out.map( "tag:ruby.yaml.org,2002:object:#{ @class }", to_yaml_style ) do |map|
50
- @ivars.each do |k,v|
51
- map.add( k, v )
52
- end
53
- end
54
- end
55
- end
56
- end
57
-
58
- #
59
- # YAML Hash class to support comments and defaults
60
- #
61
- class SpecialHash < ::Hash
62
- attr_accessor :default
63
- def inspect
64
- self.default.to_s
65
- end
66
- def to_s
67
- self.default.to_s
68
- end
69
- def update( h )
70
- if YAML::SpecialHash === h
71
- @default = h.default if h.default
72
- end
73
- super( h )
74
- end
75
- def to_yaml( opts = {} )
76
- opts[:DefaultKey] = self.default
77
- super( opts )
78
- end
79
- end
80
-
81
- #
82
- # Builtin collection: !omap
83
- #
84
- class Omap < ::Array
85
- yaml_as "tag:yaml.org,2002:omap"
86
- def yaml_initialize( tag, val )
87
- if Array === val
88
- val.each do |v|
89
- if Hash === v
90
- concat( v.to_a ) # Convert the map to a sequence
91
- else
92
- raise YAML::Error, "Invalid !omap entry: " + val.inspect
93
- end
94
- end
95
- else
96
- raise YAML::Error, "Invalid !omap: " + val.inspect
97
- end
98
- self
99
- end
100
- def self.[]( *vals )
101
- o = Omap.new
102
- 0.step( vals.length - 1, 2 ) do |i|
103
- o[vals[i]] = vals[i+1]
104
- end
105
- o
106
- end
107
- def []( k )
108
- self.assoc( k ).to_a[1]
109
- end
110
- def []=( k, *rest )
111
- val, set = rest.reverse
112
- if ( tmp = self.assoc( k ) ) and not set
113
- tmp[1] = val
114
- else
115
- self << [ k, val ]
116
- end
117
- val
118
- end
119
- def has_key?( k )
120
- self.assoc( k ) ? true : false
121
- end
122
- def is_complex_yaml?
123
- true
124
- end
125
- def to_yaml( opts = {} )
126
- YAML::quick_emit( self, opts ) do |out|
127
- out.seq( taguri, to_yaml_style ) do |seq|
128
- self.each do |v|
129
- seq.add( Hash[ *v ] )
130
- end
131
- end
132
- end
133
- end
134
- end
135
-
136
- #
137
- # Builtin collection: !pairs
138
- #
139
- class Pairs < ::Array
140
- yaml_as "tag:yaml.org,2002:pairs"
141
- def yaml_initialize( tag, val )
142
- if Array === val
143
- val.each do |v|
144
- if Hash === v
145
- concat( v.to_a ) # Convert the map to a sequence
146
- else
147
- raise YAML::Error, "Invalid !pairs entry: " + val.inspect
148
- end
149
- end
150
- else
151
- raise YAML::Error, "Invalid !pairs: " + val.inspect
152
- end
153
- self
154
- end
155
- def self.[]( *vals )
156
- p = Pairs.new
157
- 0.step( vals.length - 1, 2 ) { |i|
158
- p[vals[i]] = vals[i+1]
159
- }
160
- p
161
- end
162
- def []( k )
163
- self.assoc( k ).to_a
164
- end
165
- def []=( k, val )
166
- self << [ k, val ]
167
- val
168
- end
169
- def has_key?( k )
170
- self.assoc( k ) ? true : false
171
- end
172
- def is_complex_yaml?
173
- true
174
- end
175
- def to_yaml( opts = {} )
176
- YAML::quick_emit( self, opts ) do |out|
177
- out.seq( taguri, to_yaml_style ) do |seq|
178
- self.each do |v|
179
- seq.add( Hash[ *v ] )
180
- end
181
- end
182
- end
183
- end
184
- end
185
-
186
- #
187
- # Builtin collection: !set
188
- #
189
- class Set < ::Hash
190
- yaml_as "tag:yaml.org,2002:set"
191
- end
192
- end
data/lib/yaml/yamlnode.rb DELETED
@@ -1,54 +0,0 @@
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