mkrf 0.1.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.
Files changed (186) hide show
  1. data/CHANGELOG +2 -0
  2. data/MIT-LICENSE +7 -0
  3. data/README +54 -0
  4. data/Rakefile +107 -0
  5. data/lib/mkrf.rb +4 -0
  6. data/lib/mkrf/availability.rb +219 -0
  7. data/lib/mkrf/generator.rb +146 -0
  8. data/test/abstract_unit.rb +4 -0
  9. data/test/fixtures/down_a_directory/header_down_a_directory.h +1 -0
  10. data/test/fixtures/stdmkrf.h +1 -0
  11. data/test/sample_files/libtrivial/Rakefile +31 -0
  12. data/test/sample_files/libtrivial/extconf.rb +3 -0
  13. data/test/sample_files/libtrivial/lib/libtrivial.c +5 -0
  14. data/test/sample_files/libtrivial/lib/libtrivial.o +0 -0
  15. data/test/sample_files/libtrivial/libtrivial_so.bundle +0 -0
  16. data/test/sample_files/libtrivial/mkrf.log +1 -0
  17. data/test/sample_files/libxml-ruby-0.3.8/CHANGELOG +74 -0
  18. data/test/sample_files/libxml-ruby-0.3.8/LICENSE +22 -0
  19. data/test/sample_files/libxml-ruby-0.3.8/README +144 -0
  20. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/cbg.c +76 -0
  21. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/extconf.rb +49 -0
  22. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.c +86 -0
  23. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.h +82 -0
  24. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.rb +107 -0
  25. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/mkrf.log +1 -0
  26. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/old_extconf.rb +95 -0
  27. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.c +372 -0
  28. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.h +21 -0
  29. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.c +224 -0
  30. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.h +21 -0
  31. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.c +1159 -0
  32. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.h +27 -0
  33. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.c +168 -0
  34. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.h +17 -0
  35. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.c +167 -0
  36. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.h +21 -0
  37. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.c +2139 -0
  38. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.h +28 -0
  39. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.c +248 -0
  40. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.h +26 -0
  41. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.c +153 -0
  42. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.h +21 -0
  43. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.c +1417 -0
  44. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.h +31 -0
  45. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.c +715 -0
  46. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.h +22 -0
  47. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.c +426 -0
  48. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.h +52 -0
  49. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.c +142 -0
  50. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.h +16 -0
  51. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.c +43 -0
  52. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.h +12 -0
  53. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.c +20 -0
  54. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.h +13 -0
  55. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.c +363 -0
  56. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.h +24 -0
  57. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.c +125 -0
  58. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.h +24 -0
  59. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.c +100 -0
  60. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.h +27 -0
  61. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.c +21 -0
  62. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.h +18 -0
  63. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/sax_parser_callbacks.inc +202 -0
  64. data/test/sample_files/syck-0.55/CHANGELOG +186 -0
  65. data/test/sample_files/syck-0.55/COPYING +54 -0
  66. data/test/sample_files/syck-0.55/Makefile +582 -0
  67. data/test/sample_files/syck-0.55/Makefile.am +5 -0
  68. data/test/sample_files/syck-0.55/Makefile.in +582 -0
  69. data/test/sample_files/syck-0.55/README +105 -0
  70. data/test/sample_files/syck-0.55/README.BYTECODE +484 -0
  71. data/test/sample_files/syck-0.55/README.EXT +444 -0
  72. data/test/sample_files/syck-0.55/RELEASE +123 -0
  73. data/test/sample_files/syck-0.55/TODO +25 -0
  74. data/test/sample_files/syck-0.55/aclocal.m4 +883 -0
  75. data/test/sample_files/syck-0.55/bootstrap +7 -0
  76. data/test/sample_files/syck-0.55/config.h +79 -0
  77. data/test/sample_files/syck-0.55/config.h.in +78 -0
  78. data/test/sample_files/syck-0.55/config.status +1197 -0
  79. data/test/sample_files/syck-0.55/config/README +14 -0
  80. data/test/sample_files/syck-0.55/config/depcomp +529 -0
  81. data/test/sample_files/syck-0.55/config/install-sh +323 -0
  82. data/test/sample_files/syck-0.55/config/missing +357 -0
  83. data/test/sample_files/syck-0.55/configure +6728 -0
  84. data/test/sample_files/syck-0.55/configure.in +36 -0
  85. data/test/sample_files/syck-0.55/ext/ruby/CHANGELOG +303 -0
  86. data/test/sample_files/syck-0.55/ext/ruby/README +400 -0
  87. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/MANIFEST +1 -0
  88. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/bytecode.c +1170 -0
  89. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/emitter.c +1224 -0
  90. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/extconf.rb +10 -0
  91. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.c +1894 -0
  92. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.h +79 -0
  93. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/handler.c +174 -0
  94. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/implicit.c +2989 -0
  95. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/mkrf.log +1 -0
  96. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/node.c +407 -0
  97. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/rubyext.c +2385 -0
  98. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.c +504 -0
  99. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.h +458 -0
  100. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/token.c +2707 -0
  101. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yaml2byte.c +250 -0
  102. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yamlbyte.h +170 -0
  103. data/test/sample_files/syck-0.55/ext/ruby/install.rb +1022 -0
  104. data/test/sample_files/syck-0.55/ext/ruby/lib/okay.rb +161 -0
  105. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/news.rb +69 -0
  106. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/rpc.rb +434 -0
  107. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml.rb +436 -0
  108. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/baseemitter.rb +247 -0
  109. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/basenode.rb +216 -0
  110. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/compat.rb +26 -0
  111. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/constants.rb +45 -0
  112. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/dbm.rb +111 -0
  113. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/emitter.rb +107 -0
  114. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/encoding.rb +33 -0
  115. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/error.rb +34 -0
  116. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/rubytypes.rb +438 -0
  117. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/store.rb +29 -0
  118. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stream.rb +40 -0
  119. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb +83 -0
  120. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/syck.rb +19 -0
  121. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/tag.rb +86 -0
  122. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/types.rb +188 -0
  123. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/yamlnode.rb +54 -0
  124. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/ypath.rb +52 -0
  125. data/test/sample_files/syck-0.55/ext/ruby/lib/yod.rb +1168 -0
  126. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-modules.rb +27 -0
  127. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-sample.rb +336 -0
  128. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-validate.rb +341 -0
  129. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-client.rb +51 -0
  130. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-server.rb +85 -0
  131. data/test/sample_files/syck-0.55/ext/ruby/samples/yaml-sortHashKeys.rb +128 -0
  132. data/test/sample_files/syck-0.55/ext/ruby/tests/basic.rb +1653 -0
  133. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsAnchorAlias.yml +51 -0
  134. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBasicTests.yml +282 -0
  135. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockMapping.yml +78 -0
  136. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockSequence.yml +0 -0
  137. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsDocumentSeparator.yml +102 -0
  138. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsErrorTests.yml +23 -0
  139. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFlowCollections.yml +73 -0
  140. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFoldedScalars.yml +215 -0
  141. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsMapInSeq.yml +0 -0
  142. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsNullsAndEmpties.yml +66 -0
  143. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsRubyTests.yml +182 -0
  144. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsSpecificationExamples.yml +2699 -0
  145. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsTypeTransfers.yml +265 -0
  146. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsYpath.yml +221 -0
  147. data/test/sample_files/syck-0.55/ext/ruby/yts/cookbook.rb +159 -0
  148. data/test/sample_files/syck-0.55/ext/ruby/yts/index.yml +10 -0
  149. data/test/sample_files/syck-0.55/ext/ruby/yts/yts.rb +193 -0
  150. data/test/sample_files/syck-0.55/lib/Makefile +497 -0
  151. data/test/sample_files/syck-0.55/lib/Makefile.am +27 -0
  152. data/test/sample_files/syck-0.55/lib/Makefile.in +497 -0
  153. data/test/sample_files/syck-0.55/lib/bytecode.c +1170 -0
  154. data/test/sample_files/syck-0.55/lib/bytecode.re +525 -0
  155. data/test/sample_files/syck-0.55/lib/emitter.c +1224 -0
  156. data/test/sample_files/syck-0.55/lib/gram.c +1894 -0
  157. data/test/sample_files/syck-0.55/lib/gram.h +79 -0
  158. data/test/sample_files/syck-0.55/lib/gram.output +2005 -0
  159. data/test/sample_files/syck-0.55/lib/gram.y +481 -0
  160. data/test/sample_files/syck-0.55/lib/handler.c +174 -0
  161. data/test/sample_files/syck-0.55/lib/implicit.c +2989 -0
  162. data/test/sample_files/syck-0.55/lib/implicit.re +206 -0
  163. data/test/sample_files/syck-0.55/lib/node.c +407 -0
  164. data/test/sample_files/syck-0.55/lib/syck.c +504 -0
  165. data/test/sample_files/syck-0.55/lib/syck.h +458 -0
  166. data/test/sample_files/syck-0.55/lib/syck_st.c +577 -0
  167. data/test/sample_files/syck-0.55/lib/syck_st.h +46 -0
  168. data/test/sample_files/syck-0.55/lib/token.c +2707 -0
  169. data/test/sample_files/syck-0.55/lib/token.re +1139 -0
  170. data/test/sample_files/syck-0.55/lib/yaml2byte.c +250 -0
  171. data/test/sample_files/syck-0.55/lib/yamlbyte.h +170 -0
  172. data/test/sample_files/syck-0.55/stamp-h1 +1 -0
  173. data/test/sample_files/syck-0.55/tests/Basic.c +141 -0
  174. data/test/sample_files/syck-0.55/tests/CuTest.c +294 -0
  175. data/test/sample_files/syck-0.55/tests/CuTest.h +84 -0
  176. data/test/sample_files/syck-0.55/tests/Emit.c +87 -0
  177. data/test/sample_files/syck-0.55/tests/Makefile +480 -0
  178. data/test/sample_files/syck-0.55/tests/Makefile.am +13 -0
  179. data/test/sample_files/syck-0.55/tests/Makefile.in +480 -0
  180. data/test/sample_files/syck-0.55/tests/Parse.c +208 -0
  181. data/test/sample_files/syck-0.55/tests/YTS.c +2310 -0
  182. data/test/sample_files/syck-0.55/tests/YTS.c.erb +326 -0
  183. data/test/sample_files/syck-0.55/tests/YTS.c.rb +44 -0
  184. data/test/test_availability.rb +68 -0
  185. data/test/test_generator.rb +74 -0
  186. metadata +252 -0
@@ -0,0 +1,29 @@
1
+ #
2
+ # YAML::Store
3
+ #
4
+ require 'yaml'
5
+ require 'pstore'
6
+
7
+ class YAML::Store < PStore
8
+ def initialize( *o )
9
+ @opt = YAML::DEFAULTS.dup
10
+ if String === o.first
11
+ super(o.shift)
12
+ end
13
+ if o.last.is_a? Hash
14
+ @opt.update(o.pop)
15
+ end
16
+ end
17
+
18
+ def dump(table)
19
+ @table.to_yaml(@opt)
20
+ end
21
+
22
+ def load(content)
23
+ YAML::load(content)
24
+ end
25
+
26
+ def load_file(file)
27
+ YAML::load(file)
28
+ end
29
+ end
@@ -0,0 +1,40 @@
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
@@ -0,0 +1,83 @@
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
+
@@ -0,0 +1,19 @@
1
+ #
2
+ # YAML::Syck module
3
+ # .. glues syck and yaml.rb together ..
4
+ #
5
+ require 'syck'
6
+ require 'yaml/basenode'
7
+
8
+ module YAML
9
+ module Syck
10
+
11
+ #
12
+ # Mixin BaseNode functionality
13
+ #
14
+ class Node
15
+ include YAML::BaseNode
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,86 @@
1
+ # -*- mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- vim: sw=4 ts=4
2
+ # $Id: tag.rb,v 1.6 2005/04/07 16:22:02 why Exp $
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 # :nodoc: all
54
+ # Adds a taguri _tag_ to a class, used when dumping or loading the class
55
+ # in YAML. See YAML::tag_class for detailed information on typing and
56
+ # taguris.
57
+ def tag_as( tag, sc = true )
58
+ class_eval <<-"end;"
59
+ attr_accessor :taguri
60
+ def taguri
61
+ if respond_to? :to_yaml_type
62
+ YAML::tagurize( to_yaml_type[1..-1] )
63
+ else
64
+ return @taguri if @taguri
65
+ tag = #{ tag.dump }
66
+ if self.class.tag_subclasses? and self.class != YAML::tagged_classes[tag]
67
+ tag = "\#{ tag }:\#{ self.class.tag_class_name }"
68
+ end
69
+ tag
70
+ end
71
+ end
72
+ def self.tag_subclasses?; #{ sc ? 'true' : 'false' }; end
73
+ end;
74
+ YAML::tag_class tag, self
75
+ end
76
+ # Transforms the subclass name into a name suitable for display
77
+ # in a subclassed tag.
78
+ def tag_class_name
79
+ self.name
80
+ end
81
+ # Transforms the subclass name found in the tag into a Ruby
82
+ # constant name.
83
+ def tag_read_class( name )
84
+ name
85
+ end
86
+ end
@@ -0,0 +1,188 @@
1
+ #
2
+ # Classes required by the full core typeset
3
+ #
4
+ require 'yaml/compat'
5
+
6
+ module YAML
7
+
8
+ #
9
+ # Default private type
10
+ #
11
+ class PrivateType
12
+ def self.tag_subclasses?; false; end
13
+ attr_accessor :type_id, :value
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
+ end
22
+
23
+ #
24
+ # Default domain type
25
+ #
26
+ class DomainType
27
+ def self.tag_subclasses?; false; end
28
+ attr_accessor :domain, :type_id, :value
29
+ def initialize( domain, type, val )
30
+ @domain = domain; @type_id = type; @value = val
31
+ @value.taguri = "tag:#{ @domain }:#{ @type_id }"
32
+ end
33
+ def to_yaml( opts = {} )
34
+ @value.to_yaml( opts )
35
+ end
36
+ end
37
+
38
+ #
39
+ # Unresolved objects
40
+ #
41
+ class Object
42
+ def self.tag_subclasses?; false; end
43
+ def to_yaml( opts = {} )
44
+ YAML::quick_emit( object_id, opts ) do |out|
45
+ out.map( "tag:ruby.yaml.org,2002:object:#{ @class }", to_yaml_style ) do |map|
46
+ @ivars.each do |k,v|
47
+ map.add( k, v )
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ #
55
+ # YAML Hash class to support comments and defaults
56
+ #
57
+ class SpecialHash < ::Hash
58
+ attr_accessor :default
59
+ def inspect
60
+ self.default.to_s
61
+ end
62
+ def to_s
63
+ self.default.to_s
64
+ end
65
+ def update( h )
66
+ if YAML::SpecialHash === h
67
+ @default = h.default if h.default
68
+ end
69
+ super( h )
70
+ end
71
+ def to_yaml( opts = {} )
72
+ opts[:DefaultKey] = self.default
73
+ super( opts )
74
+ end
75
+ end
76
+
77
+ #
78
+ # Builtin collection: !omap
79
+ #
80
+ class Omap < ::Array
81
+ tag_as "tag:yaml.org,2002:omap"
82
+ def yaml_initialize( tag, val )
83
+ if Array === val
84
+ val.each do |v|
85
+ if Hash === v
86
+ concat( v.to_a ) # Convert the map to a sequence
87
+ else
88
+ raise YAML::Error, "Invalid !omap entry: " + val.inspect
89
+ end
90
+ end
91
+ else
92
+ raise YAML::Error, "Invalid !omap: " + val.inspect
93
+ end
94
+ self
95
+ end
96
+ def self.[]( *vals )
97
+ o = Omap.new
98
+ 0.step( vals.length - 1, 2 ) do |i|
99
+ o[vals[i]] = vals[i+1]
100
+ end
101
+ o
102
+ end
103
+ def []( k )
104
+ self.assoc( k ).to_a[1]
105
+ end
106
+ def []=( k, *rest )
107
+ val, set = rest.reverse
108
+ if ( tmp = self.assoc( k ) ) and not set
109
+ tmp[1] = val
110
+ else
111
+ self << [ k, val ]
112
+ end
113
+ val
114
+ end
115
+ def has_key?( k )
116
+ self.assoc( k ) ? true : false
117
+ end
118
+ def is_complex_yaml?
119
+ true
120
+ end
121
+ def to_yaml( opts = {} )
122
+ YAML::quick_emit( self.object_id, opts ) do |out|
123
+ out.seq( taguri, to_yaml_style ) do |seq|
124
+ self.each do |v|
125
+ seq.add( Hash[ *v ] )
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ #
133
+ # Builtin collection: !pairs
134
+ #
135
+ class Pairs < ::Array
136
+ tag_as "tag:yaml.org,2002:pairs"
137
+ def yaml_initialize( tag, val )
138
+ if Array === val
139
+ val.each do |v|
140
+ if Hash === v
141
+ concat( v.to_a ) # Convert the map to a sequence
142
+ else
143
+ raise YAML::Error, "Invalid !pairs entry: " + val.inspect
144
+ end
145
+ end
146
+ else
147
+ raise YAML::Error, "Invalid !pairs: " + val.inspect
148
+ end
149
+ self
150
+ end
151
+ def self.[]( *vals )
152
+ p = Pairs.new
153
+ 0.step( vals.length - 1, 2 ) { |i|
154
+ p[vals[i]] = vals[i+1]
155
+ }
156
+ p
157
+ end
158
+ def []( k )
159
+ self.assoc( k ).to_a
160
+ end
161
+ def []=( k, val )
162
+ self << [ k, val ]
163
+ val
164
+ end
165
+ def has_key?( k )
166
+ self.assoc( k ) ? true : false
167
+ end
168
+ def is_complex_yaml?
169
+ true
170
+ end
171
+ def to_yaml( opts = {} )
172
+ YAML::quick_emit( self.object_id, opts ) do |out|
173
+ out.seq( taguri, to_yaml_style ) do |seq|
174
+ self.each do |v|
175
+ seq.add( Hash[ *v ] )
176
+ end
177
+ end
178
+ end
179
+ end
180
+ end
181
+
182
+ #
183
+ # Builtin collection: !set
184
+ #
185
+ class Set < ::Hash
186
+ tag_as "tag:yaml.org,2002:set"
187
+ end
188
+ end