mkrf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,33 @@
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
@@ -0,0 +1,34 @@
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
@@ -0,0 +1,438 @@
1
+ # -*- mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- vim: sw=4 ts=4
2
+ require 'date'
3
+ require 'yaml/compat'
4
+
5
+ #
6
+ # Type conversions
7
+ #
8
+ class Class
9
+ def to_yaml( opts = {} )
10
+ raise TypeError, "can't dump anonymous class %s" % self.class
11
+ end
12
+ end
13
+
14
+ class Object
15
+ tag_as "tag:ruby.yaml.org,2002:object"
16
+ def to_yaml_style; end
17
+ def to_yaml_properties; instance_variables.sort; end
18
+ def to_yaml( opts = {} )
19
+ YAML::quick_emit( object_id, opts ) do |out|
20
+ out.map( taguri, to_yaml_style ) do |map|
21
+ to_yaml_properties.each do |m|
22
+ map.add( m[1..-1], instance_variable_get( m ) )
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ #
30
+ # Maps: Hash#to_yaml
31
+ #
32
+ class Hash
33
+ tag_as "tag:ruby.yaml.org,2002:hash"
34
+ tag_as "tag:yaml.org,2002:map"
35
+ def yaml_initialize( tag, val )
36
+ if Array === val
37
+ update Hash.[]( *val ) # Convert the map to a sequence
38
+ elsif Hash === val
39
+ update val
40
+ else
41
+ raise YAML::TypeError, "Invalid map explicitly tagged #{ tag }: " + val.inspect
42
+ end
43
+ end
44
+ def to_yaml( opts = {} )
45
+ YAML::quick_emit( object_id, opts ) do |out|
46
+ out.map( taguri, to_yaml_style ) do |map|
47
+ each do |k, v|
48
+ map.add( k, v )
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ #
56
+ # Structs: export as a !map
57
+ #
58
+ class Struct
59
+ tag_as "tag:ruby.yaml.org,2002:struct"
60
+ def self.tag_class_name; self.name.gsub( "Struct::", "" ); end
61
+ def self.tag_read_class( name ); "Struct::#{ name }"; end
62
+ def self.yaml_new( klass, tag, val )
63
+ if Hash === val
64
+ struct_type = nil
65
+
66
+ #
67
+ # Use existing Struct if it exists
68
+ #
69
+ props = {}
70
+ val.delete_if { |k,v| props[k] = v if k =~ /^@/ }
71
+ begin
72
+ struct_name, struct_type = YAML.read_type_class( tag, Struct )
73
+ rescue NameError
74
+ end
75
+ if not struct_type
76
+ struct_def = [ tag.split( ':', 4 ).last ]
77
+ struct_type = Struct.new( *struct_def.concat( val.keys.collect { |k| k.intern } ) )
78
+ end
79
+
80
+ #
81
+ # Set the Struct properties
82
+ #
83
+ st = YAML::object_maker( struct_type, {} )
84
+ st.members.each do |m|
85
+ st.send( "#{m}=", val[m] )
86
+ end
87
+ props.each do |k,v|
88
+ st.instance_variable_set(k, v)
89
+ end
90
+ st
91
+ else
92
+ raise YAML::TypeError, "Invalid Ruby Struct: " + val.inspect
93
+ end
94
+ end
95
+ def to_yaml( opts = {} )
96
+ YAML::quick_emit( object_id, opts ) do |out|
97
+ #
98
+ # Basic struct is passed as a YAML map
99
+ #
100
+ out.map( taguri, to_yaml_style ) do |map|
101
+ self.members.each do |m|
102
+ map.add( m, self[m] )
103
+ end
104
+ self.to_yaml_properties.each do |m|
105
+ map.add( m, instance_variable_get( m ) )
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ #
113
+ # Sequences: Array#to_yaml
114
+ #
115
+ class Array
116
+ tag_as "tag:ruby.yaml.org,2002:array"
117
+ tag_as "tag:yaml.org,2002:seq"
118
+ def yaml_initialize( tag, val ); concat( val.to_a ); end
119
+ def to_yaml( opts = {} )
120
+ YAML::quick_emit( object_id, opts ) do |out|
121
+ out.seq( taguri, to_yaml_style ) do |seq|
122
+ each do |x|
123
+ seq.add( x )
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
129
+
130
+ #
131
+ # Exception#to_yaml
132
+ #
133
+ class Exception
134
+ tag_as "tag:ruby.yaml.org,2002:exception"
135
+ def Exception.yaml_new( klass, tag, val )
136
+ o = YAML.object_maker( klass, { 'mesg' => val.delete( 'message' ) } )
137
+ val.each_pair do |k,v|
138
+ o.instance_variable_set("@#{k}", v)
139
+ end
140
+ o
141
+ end
142
+ def to_yaml( opts = {} )
143
+ YAML::quick_emit( object_id, opts ) do |out|
144
+ out.map( taguri, to_yaml_style ) do |map|
145
+ map.add( 'message', message )
146
+ to_yaml_properties.each do |m|
147
+ map.add( m[1..-1], instance_variable_get( m ) )
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
153
+
154
+
155
+ #
156
+ # String#to_yaml
157
+ #
158
+ class String
159
+ tag_as "tag:ruby.yaml.org,2002:string"
160
+ tag_as "tag:yaml.org,2002:str"
161
+ def is_complex_yaml?
162
+ to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/
163
+ end
164
+ def is_binary_data?
165
+ ( self.count( "^ -~", "^\r\n" ) / self.size > 0.3 || self.count( "\x00" ) > 0 )
166
+ end
167
+ def String.yaml_new( klass, tag, val )
168
+ val = { 'str' => val } if String === val
169
+ if Hash === val
170
+ s = klass.allocate
171
+ # Thank you, NaHi
172
+ String.instance_method(:initialize).
173
+ bind(s).
174
+ call( val.delete( 'str' ) )
175
+ val.each { |k,v| s.instance_variable_set( k, v ) }
176
+ s
177
+ else
178
+ raise YAML::TypeError, "Invalid String: " + val.inspect
179
+ end
180
+ end
181
+ def to_yaml( opts = {} )
182
+ YAML::quick_emit( is_complex_yaml? ? object_id : nil, opts ) do |out|
183
+ if to_yaml_properties.empty?
184
+ out.scalar( taguri, self, to_yaml_style )
185
+ else
186
+ out.map( taguri, to_yaml_style ) do |map|
187
+ map.add( 'str', "#{self}" )
188
+ to_yaml_properties.each do |m|
189
+ map.add( m, instance_variable_get( m ) )
190
+ end
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
196
+ #
197
+ # Symbol#to_yaml
198
+ #
199
+ class Symbol
200
+ tag_as "tag:ruby.yaml.org,2002:symbol"
201
+ tag_as "tag:ruby.yaml.org,2002:sym"
202
+ # yaml_implicit /^:/, :yaml_new
203
+ def Symbol.yaml_new( klass, tag, val )
204
+ if String === val
205
+ val.intern
206
+ else
207
+ raise YAML::TypeError, "Invalid Symbol: " + val.inspect
208
+ end
209
+ end
210
+ def to_yaml( opts = {} )
211
+ YAML::quick_emit( nil, opts ) do |out|
212
+ out.scalar( taguri, self.id2name, :plain )
213
+ end
214
+ end
215
+ end
216
+
217
+ #
218
+ # Range#to_yaml
219
+ # TODO: Rework the Range as a sequence (simpler)
220
+ #
221
+ class Range
222
+ tag_as "tag:ruby.yaml.org,2002:range"
223
+ def Range.yaml_new( klass, tag, val )
224
+ inr = %r'(\w+|[+-]?\d+(?:\.\d+)?(?:e[+-]\d+)?|"(?:[^\\"]|\\.)*")'
225
+ opts = {}
226
+ if String === val and val =~ /^#{inr}(\.{2,3})#{inr}$/o
227
+ r1, rdots, r2 = $1, $2, $3
228
+ opts = {
229
+ 'begin' => YAML.load( "--- #{r1}" ),
230
+ 'end' => YAML.load( "--- #{r2}" ),
231
+ 'excl' => rdots.length == 3
232
+ }
233
+ val = {}
234
+ elsif Hash === val
235
+ opts['begin'] = val.delete('begin')
236
+ opts['end'] = val.delete('end')
237
+ opts['excl'] = val.delete('excl')
238
+ end
239
+ if Hash === opts
240
+ r = YAML::object_maker( klass, {} )
241
+ # Thank you, NaHi
242
+ Range.instance_method(:initialize).
243
+ bind(r).
244
+ call( opts['begin'], opts['end'], opts['excl'] )
245
+ val.each { |k,v| r.instance_variable_set( k, v ) }
246
+ r
247
+ else
248
+ raise YAML::TypeError, "Invalid Range: " + val.inspect
249
+ end
250
+ end
251
+ def to_yaml( opts = {} )
252
+ YAML::quick_emit( object_id, opts ) do |out|
253
+ # if self.begin.is_complex_yaml? or self.begin.respond_to? :to_str or
254
+ # self.end.is_complex_yaml? or self.end.respond_to? :to_str or
255
+ # not to_yaml_properties.empty?
256
+ out.map( taguri, to_yaml_style ) do |map|
257
+ map.add( 'begin', self.begin )
258
+ map.add( 'end', self.end )
259
+ map.add( 'excl', self.exclude_end? )
260
+ to_yaml_properties.each do |m|
261
+ map.add( m, instance_variable_get( m ) )
262
+ end
263
+ end
264
+ # else
265
+ # out.scalar( taguri ) do |sc|
266
+ # sc.embed( self.begin )
267
+ # sc.concat( self.exclude_end? ? "..." : ".." )
268
+ # sc.embed( self.end )
269
+ # end
270
+ # end
271
+ end
272
+ end
273
+ end
274
+
275
+ #
276
+ # Make an Regexp
277
+ #
278
+ class Regexp
279
+ tag_as "tag:ruby.yaml.org,2002:regexp"
280
+ def Regexp.yaml_new( klass, tag, val )
281
+ if String === val and val =~ /^\/(.*)\/([mix]*)$/
282
+ val = { 'regexp' => $1, 'mods' => $2 }
283
+ end
284
+ if Hash === val
285
+ mods = nil
286
+ unless val['mods'].to_s.empty?
287
+ mods = 0x00
288
+ mods |= Regexp::EXTENDED if val['mods'].include?( 'x' )
289
+ mods |= Regexp::IGNORECASE if val['mods'].include?( 'i' )
290
+ mods |= Regexp::MULTILINE if val['mods'].include?( 'm' )
291
+ end
292
+ val.delete( 'mods' )
293
+ r = YAML::object_maker( klass, {} )
294
+ Regexp.instance_method(:initialize).
295
+ bind(r).
296
+ call( val.delete( 'regexp' ), mods )
297
+ val.each { |k,v| r.instance_variable_set( k, v ) }
298
+ r
299
+ else
300
+ raise YAML::TypeError, "Invalid Regular expression: " + val.inspect
301
+ end
302
+ end
303
+ def to_yaml( opts = {} )
304
+ YAML::quick_emit( nil, opts ) do |out|
305
+ if to_yaml_properties.empty?
306
+ out.scalar( taguri, self.inspect, :plain )
307
+ else
308
+ out.map( taguri, to_yaml_style ) do |map|
309
+ src = self.inspect
310
+ if src =~ /\A\/(.*)\/([a-z]*)\Z/
311
+ map.add( 'regexp', $1 )
312
+ map.add( 'mods', $2 )
313
+ else
314
+ raise YAML::TypeError, "Invalid Regular expression: " + src
315
+ end
316
+ to_yaml_properties.each do |m|
317
+ map.add( m, instance_variable_get( m ) )
318
+ end
319
+ end
320
+ end
321
+ end
322
+ end
323
+ end
324
+
325
+ #
326
+ # Emit a Time object as an ISO 8601 timestamp
327
+ #
328
+ class Time
329
+ tag_as "tag:ruby.yaml.org,2002:time"
330
+ tag_as "tag:yaml.org,2002:timestamp"
331
+ def Time.yaml_new( klass, tag, val )
332
+ if Hash === val
333
+ t = val.delete( 'at' )
334
+ val.each { |k,v| t.instance_variable_set( k, v ) }
335
+ t
336
+ else
337
+ raise YAML::TypeError, "Invalid Time: " + val.inspect
338
+ end
339
+ end
340
+ def to_yaml( opts = {} )
341
+ YAML::quick_emit( object_id, opts ) do |out|
342
+ tz = "Z"
343
+ # from the tidy Tobias Peters <t-peters@gmx.de> Thanks!
344
+ unless self.utc?
345
+ utc_same_instant = self.dup.utc
346
+ utc_same_writing = Time.utc(year,month,day,hour,min,sec,usec)
347
+ difference_to_utc = utc_same_writing - utc_same_instant
348
+ if (difference_to_utc < 0)
349
+ difference_sign = '-'
350
+ absolute_difference = -difference_to_utc
351
+ else
352
+ difference_sign = '+'
353
+ absolute_difference = difference_to_utc
354
+ end
355
+ difference_minutes = (absolute_difference/60).round
356
+ tz = "%s%02d:%02d" % [ difference_sign, difference_minutes / 60, difference_minutes % 60]
357
+ end
358
+ standard = self.strftime( "%Y-%m-%d %H:%M:%S" )
359
+ standard += ".%06d" % [usec] if usec.nonzero?
360
+ standard += " %s" % [tz]
361
+ if to_yaml_properties.empty?
362
+ out.scalar( taguri, standard, :plain )
363
+ else
364
+ out.map( taguri, to_yaml_style ) do |map|
365
+ map.add( 'at', standard )
366
+ to_yaml_properties.each do |m|
367
+ map.add( m, instance_variable_get( m ) )
368
+ end
369
+ end
370
+ end
371
+ end
372
+ end
373
+ end
374
+
375
+ #
376
+ # Emit a Date object as a simple implicit
377
+ #
378
+ class Date
379
+ tag_as "tag:yaml.org,2002:timestamp#ymd"
380
+ def to_yaml( opts = {} )
381
+ YAML::quick_emit( object_id, opts ) do |out|
382
+ out.scalar( "tag:yaml.org,2002:timestamp", self.to_s, :plain )
383
+ end
384
+ end
385
+ end
386
+
387
+ #
388
+ # Send Integer, Booleans, NilClass to String
389
+ #
390
+ class Numeric
391
+ def to_yaml( opts = {} )
392
+ YAML::quick_emit( nil, opts ) do |out|
393
+ str = self.to_s
394
+ if str == "Infinity"
395
+ str = ".Inf"
396
+ elsif str == "-Infinity"
397
+ str = "-.Inf"
398
+ elsif str == "NaN"
399
+ str = ".NaN"
400
+ end
401
+ out.scalar( taguri, str, :plain )
402
+ end
403
+ end
404
+ end
405
+ class Fixnum
406
+ tag_as "tag:yaml.org,2002:int"
407
+ end
408
+ class Float
409
+ tag_as "tag:yaml.org,2002:float"
410
+ end
411
+
412
+ class TrueClass
413
+ tag_as "tag:yaml.org,2002:bool#yes"
414
+ def to_yaml( opts = {} )
415
+ YAML::quick_emit( nil, opts ) do |out|
416
+ out.scalar( taguri, "true", :plain )
417
+ end
418
+ end
419
+ end
420
+
421
+ class FalseClass
422
+ tag_as "tag:yaml.org,2002:bool#no"
423
+ def to_yaml( opts = {} )
424
+ YAML::quick_emit( nil, opts ) do |out|
425
+ out.scalar( taguri, "false", :plain )
426
+ end
427
+ end
428
+ end
429
+
430
+ class NilClass
431
+ tag_as "tag:yaml.org,2002:null"
432
+ def to_yaml( opts = {} )
433
+ YAML::quick_emit( nil, opts ) do |out|
434
+ out.scalar( taguri, "", :plain )
435
+ end
436
+ end
437
+ end
438
+