roxml 1.2 → 2.3.2

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 (97) hide show
  1. data/MIT-LICENSE +18 -0
  2. data/README.rdoc +126 -0
  3. data/Rakefile +100 -0
  4. data/lib/roxml.rb +479 -485
  5. data/lib/roxml/extensions/active_support.rb +32 -0
  6. data/lib/roxml/extensions/array.rb +5 -0
  7. data/lib/roxml/extensions/array/conversions.rb +25 -0
  8. data/lib/roxml/extensions/deprecation.rb +28 -0
  9. data/lib/roxml/extensions/string.rb +21 -0
  10. data/lib/roxml/extensions/string/conversions.rb +44 -0
  11. data/lib/roxml/extensions/string/iterators.rb +12 -0
  12. data/lib/roxml/options.rb +266 -0
  13. data/lib/roxml/xml.rb +223 -0
  14. data/lib/roxml/xml/libxml.rb +63 -0
  15. data/lib/roxml/xml/rexml.rb +64 -0
  16. data/roxml.gemspec +105 -0
  17. data/test/fixtures/book_text_with_attribute.xml +1 -1
  18. data/test/fixtures/book_valid.xml +2 -2
  19. data/test/fixtures/book_with_authors.xml +7 -0
  20. data/test/fixtures/book_with_contributors_attrs.xml +7 -0
  21. data/test/fixtures/book_with_default_namespace.xml +9 -0
  22. data/test/fixtures/book_with_depth.xml +6 -0
  23. data/test/fixtures/book_with_wrapped_attr.xml +3 -0
  24. data/test/fixtures/dictionary_of_attr_name_clashes.xml +8 -0
  25. data/test/fixtures/dictionary_of_attrs.xml +6 -0
  26. data/test/fixtures/dictionary_of_guarded_names.xml +6 -0
  27. data/test/fixtures/dictionary_of_mixeds.xml +4 -0
  28. data/test/fixtures/dictionary_of_name_clashes.xml +10 -0
  29. data/test/fixtures/dictionary_of_names.xml +4 -0
  30. data/test/fixtures/dictionary_of_texts.xml +10 -0
  31. data/test/fixtures/library.xml +1 -1
  32. data/test/fixtures/library_uppercase.xml +30 -0
  33. data/test/fixtures/muffins.xml +3 -0
  34. data/test/fixtures/nameless_ageless_youth.xml +2 -0
  35. data/test/fixtures/node_with_attr_name_conflicts.xml +1 -0
  36. data/test/fixtures/node_with_name_conflicts.xml +4 -0
  37. data/test/fixtures/numerology.xml +4 -0
  38. data/test/fixtures/person_with_guarded_mothers.xml +13 -0
  39. data/test/fixtures/person_with_mothers.xml +10 -0
  40. data/test/mocks/dictionaries.rb +56 -0
  41. data/test/mocks/mocks.rb +244 -48
  42. data/test/release/dependencies_test.rb +32 -0
  43. data/test/test_helper.rb +44 -0
  44. data/test/unit/inheritance_test.rb +19 -0
  45. data/test/unit/options_test.rb +102 -0
  46. data/test/unit/roxml_test.rb +24 -0
  47. data/test/unit/string_test.rb +11 -0
  48. data/test/unit/to_xml_test.rb +52 -0
  49. data/test/unit/xml_attribute_test.rb +39 -0
  50. data/test/unit/xml_block_test.rb +81 -0
  51. data/test/unit/xml_bool_test.rb +105 -0
  52. data/test/unit/xml_construct_test.rb +77 -0
  53. data/test/unit/xml_hash_test.rb +65 -0
  54. data/test/unit/xml_initialize_test.rb +50 -0
  55. data/test/unit/xml_name_test.rb +108 -0
  56. data/test/unit/xml_namespace_test.rb +38 -0
  57. data/test/unit/xml_object_test.rb +116 -0
  58. data/test/unit/xml_required_test.rb +93 -0
  59. data/test/unit/xml_text_test.rb +68 -0
  60. metadata +138 -87
  61. data/MIT-LICENSE.txt +0 -9
  62. data/README +0 -2
  63. data/doc/classes/ROXML.html +0 -374
  64. data/doc/classes/ROXML.src/M000003.html +0 -19
  65. data/doc/classes/ROXML.src/M000004.html +0 -25
  66. data/doc/classes/ROXML.src/M000005.html +0 -22
  67. data/doc/classes/ROXML/ROXML_Class.html +0 -429
  68. data/doc/classes/ROXML/ROXML_Class.src/M000006.html +0 -27
  69. data/doc/classes/ROXML/ROXML_Class.src/M000007.html +0 -18
  70. data/doc/classes/ROXML/ROXML_Class.src/M000008.html +0 -19
  71. data/doc/classes/ROXML/ROXML_Class.src/M000009.html +0 -25
  72. data/doc/classes/ROXML/ROXML_Class.src/M000010.html +0 -24
  73. data/doc/classes/ROXML/ROXML_Class.src/M000011.html +0 -18
  74. data/doc/classes/ROXML/ROXML_Class.src/M000012.html +0 -18
  75. data/doc/classes/ROXML/XMLAttributeRef.html +0 -175
  76. data/doc/classes/ROXML/XMLAttributeRef.src/M000015.html +0 -19
  77. data/doc/classes/ROXML/XMLAttributeRef.src/M000016.html +0 -19
  78. data/doc/classes/ROXML/XMLObjectRef.html +0 -175
  79. data/doc/classes/ROXML/XMLObjectRef.src/M000013.html +0 -26
  80. data/doc/classes/ROXML/XMLObjectRef.src/M000014.html +0 -32
  81. data/doc/classes/ROXML/XMLRef.html +0 -166
  82. data/doc/classes/ROXML/XMLRef.src/M000017.html +0 -21
  83. data/doc/classes/ROXML/XMLTextRef.html +0 -198
  84. data/doc/classes/ROXML/XMLTextRef.src/M000018.html +0 -28
  85. data/doc/classes/ROXML/XMLTextRef.src/M000019.html +0 -34
  86. data/doc/classes/String.html +0 -165
  87. data/doc/classes/String.src/M000001.html +0 -23
  88. data/doc/classes/String.src/M000002.html +0 -23
  89. data/doc/created.rid +0 -1
  90. data/doc/files/lib/roxml_rb.html +0 -234
  91. data/doc/fr_class_index.html +0 -33
  92. data/doc/fr_file_index.html +0 -27
  93. data/doc/fr_method_index.html +0 -45
  94. data/doc/index.html +0 -24
  95. data/doc/rdoc-style.css +0 -208
  96. data/test/fixture_helper.rb +0 -5
  97. data/test/test_roxml.rb +0 -105
@@ -0,0 +1,63 @@
1
+ require 'libxml'
2
+
3
+ module ROXML
4
+ module XML # :nodoc:all
5
+ Document = LibXML::XML::Document
6
+ Node = LibXML::XML::Node
7
+ Parser = LibXML::XML::Parser
8
+
9
+ module NamespacedSearch
10
+ def search(xpath)
11
+ if default_namespace && !xpath.include?(':')
12
+ find(namespaced(xpath),
13
+ in_default_namespace(default_namespace.href))
14
+ else
15
+ find(xpath)
16
+ end
17
+ end
18
+
19
+ private
20
+ def namespaced(xpath)
21
+ xpath.between('/') do |component|
22
+ if component =~ /\w+/ && !component.include?(':') && !component.starts_with?('@')
23
+ in_default_namespace(component)
24
+ else
25
+ component
26
+ end
27
+ end
28
+ end
29
+
30
+ def in_default_namespace(name)
31
+ "roxmldefaultnamespace:#{name}"
32
+ end
33
+ end
34
+
35
+ class Document
36
+ include NamespacedSearch
37
+
38
+ private
39
+ delegate :default_namespace, :to => :root
40
+ end
41
+
42
+ class Node
43
+ include NamespacedSearch
44
+
45
+ private
46
+ def default_namespace
47
+ @default_namespace ||= namespace && namespace.find {|n| n.to_s.nil? }
48
+ end
49
+ end
50
+
51
+ class Parser
52
+ class << self
53
+ def parse(str_data)
54
+ string(str_data).parse
55
+ end
56
+
57
+ def parse_file(path)
58
+ file(path).parse
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,64 @@
1
+ require 'rexml/document'
2
+
3
+ module ROXML
4
+ module XML # :nodoc:all
5
+ Document = REXML::Document
6
+ Node = REXML::Element
7
+
8
+ class Node
9
+ class << self
10
+ def new_cdata(content)
11
+ REXML::CData.new(content)
12
+ end
13
+
14
+ def new_element(name)
15
+ name = name.id2name if name.is_a? Symbol
16
+ REXML::Element.new(name)
17
+ end
18
+ end
19
+
20
+ alias_attribute :content, :text
21
+
22
+ def search(xpath)
23
+ REXML::XPath.match(self, xpath)
24
+ end
25
+
26
+ def child_add(element)
27
+ if element.is_a?(REXML::CData)
28
+ REXML::CData.new(element, true, self)
29
+ else
30
+ add_element(element)
31
+ end
32
+ end
33
+
34
+ def ==(other)
35
+ to_s == other.to_s
36
+ end
37
+ end
38
+
39
+ class Parser
40
+ class << self
41
+ def parse(string)
42
+ REXML::Document.new(string)
43
+ end
44
+
45
+ def parse_file(path)
46
+ REXML::Document.new(open(path), :ignore_whitespace_nodes => :all)
47
+ end
48
+
49
+ def register_error_handler(&block)
50
+ end
51
+ end
52
+ ParseError = REXML::ParseException
53
+ end
54
+
55
+ class Document
56
+ delegate :search, :to => :root
57
+
58
+ def root=(node)
59
+ raise ArgumentError, "Root is already defined" if root
60
+ add(node)
61
+ end
62
+ end
63
+ end
64
+ end
data/roxml.gemspec ADDED
@@ -0,0 +1,105 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "roxml"
3
+ s.summary = "Ruby Object to XML mapping library"
4
+ s.version = "2.3.2"
5
+ s.homepage = "http://roxml.rubyforge.org"
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ["Ben Woosley", "Zak Mandhro", "Anders Engstrom", "Russ Olsen"]
8
+ s.email = "ben.woosley@gmail.com"
9
+ s.rubyforge_project = 'roxml'
10
+ s.files = [
11
+ 'README.rdoc',
12
+ 'MIT-LICENSE',
13
+ 'Rakefile',
14
+ 'roxml.gemspec',
15
+ 'lib/roxml.rb',
16
+ 'lib/roxml/extensions/active_support.rb',
17
+ 'lib/roxml/extensions/array.rb',
18
+ 'lib/roxml/extensions/array/conversions.rb',
19
+ 'lib/roxml/extensions/string.rb',
20
+ 'lib/roxml/extensions/string/conversions.rb',
21
+ 'lib/roxml/extensions/string/iterators.rb',
22
+ 'lib/roxml/extensions/deprecation.rb',
23
+ 'lib/roxml/options.rb',
24
+ 'lib/roxml/xml.rb',
25
+ 'lib/roxml/xml/libxml.rb',
26
+ 'lib/roxml/xml/rexml.rb',
27
+ 'test/fixtures/book_malformed.xml',
28
+ 'test/fixtures/book_pair.xml',
29
+ 'test/fixtures/book_text_with_attribute.xml',
30
+ 'test/fixtures/book_valid.xml',
31
+ 'test/fixtures/book_with_authors.xml',
32
+ 'test/fixtures/book_with_contributions.xml',
33
+ 'test/fixtures/book_with_contributors_attrs.xml',
34
+ 'test/fixtures/book_with_contributors.xml',
35
+ 'test/fixtures/book_with_default_namespace.xml',
36
+ 'test/fixtures/book_with_depth.xml',
37
+ 'test/fixtures/book_with_publisher.xml',
38
+ 'test/fixtures/book_with_wrapped_attr.xml',
39
+ 'test/fixtures/dictionary_of_attrs.xml',
40
+ 'test/fixtures/dictionary_of_attr_name_clashes.xml',
41
+ 'test/fixtures/dictionary_of_guarded_names.xml',
42
+ 'test/fixtures/dictionary_of_mixeds.xml',
43
+ 'test/fixtures/dictionary_of_names.xml',
44
+ 'test/fixtures/dictionary_of_name_clashes.xml',
45
+ 'test/fixtures/dictionary_of_texts.xml',
46
+ 'test/fixtures/library_uppercase.xml',
47
+ 'test/fixtures/library.xml',
48
+ 'test/fixtures/muffins.xml',
49
+ 'test/fixtures/node_with_attr_name_conflicts.xml',
50
+ 'test/fixtures/node_with_name_conflicts.xml',
51
+ 'test/fixtures/nameless_ageless_youth.xml',
52
+ 'test/fixtures/numerology.xml',
53
+ 'test/fixtures/person_with_guarded_mothers.xml',
54
+ 'test/fixtures/person_with_mothers.xml',
55
+ 'test/fixtures/person.xml',
56
+ 'test/mocks/mocks.rb',
57
+ 'test/mocks/dictionaries.rb',
58
+ 'test/release/dependencies_test.rb',
59
+ 'test/test_helper.rb',
60
+ 'test/unit/inheritance_test.rb',
61
+ 'test/unit/options_test.rb',
62
+ 'test/unit/roxml_test.rb',
63
+ 'test/unit/string_test.rb',
64
+ 'test/unit/to_xml_test.rb',
65
+ 'test/unit/xml_attribute_test.rb',
66
+ 'test/unit/xml_block_test.rb',
67
+ 'test/unit/xml_bool_test.rb',
68
+ 'test/unit/xml_construct_test.rb',
69
+ 'test/unit/xml_hash_test.rb',
70
+ 'test/unit/xml_initialize_test.rb',
71
+ 'test/unit/xml_name_test.rb',
72
+ 'test/unit/xml_namespace_test.rb',
73
+ 'test/unit/xml_object_test.rb',
74
+ 'test/unit/xml_required_test.rb',
75
+ 'test/unit/xml_text_test.rb']
76
+ s.requirements << 'none'
77
+ s.add_dependency 'extensions', '>= 0.6.0'
78
+ s.add_dependency 'activesupport', '>= 2.0.0'
79
+ s.require_path = 'lib'
80
+ s.test_files = [
81
+ 'test/unit/inheritance_test.rb',
82
+ 'test/unit/options_test.rb',
83
+ 'test/unit/roxml_test.rb',
84
+ 'test/unit/string_test.rb',
85
+ 'test/unit/to_xml_test.rb',
86
+ 'test/unit/xml_attribute_test.rb',
87
+ 'test/unit/xml_block_test.rb',
88
+ 'test/unit/xml_bool_test.rb',
89
+ 'test/unit/xml_construct_test.rb',
90
+ 'test/unit/xml_hash_test.rb',
91
+ 'test/unit/xml_initialize_test.rb',
92
+ 'test/unit/xml_name_test.rb',
93
+ 'test/unit/xml_namespace_test.rb',
94
+ 'test/unit/xml_object_test.rb',
95
+ 'test/unit/xml_required_test.rb',
96
+ 'test/unit/xml_text_test.rb']
97
+ s.has_rdoc = true
98
+ s.description = <<EOF
99
+ ROXML is a Ruby library designed to make it easier for Ruby developers to work with XML.
100
+ Using simple annotations, it enables Ruby classes to be mapped to XML. ROXML takes care
101
+ of the marshalling and unmarshalling of mapped attributes so that developers can focus on
102
+ building first-class Ruby classes. As a result, ROXML simplifies the development of
103
+ RESTful applications, Web Services, and XML-RPC.
104
+ EOF
105
+ end
@@ -1,4 +1,4 @@
1
- <book ISDN="0201710897">
1
+ <book ISBN="0201710897">
2
2
  <title>The PickAxe</title>
3
3
  <description><![CDATA[Probably the best Ruby book out there]]></description>
4
4
  <author role="primary">David Thomas</author>
@@ -1,5 +1,5 @@
1
- <book ISDN="0201710897">
1
+ <book ISBN="0201710897">
2
2
  <title>The PickAxe</title>
3
3
  <description><![CDATA[Probably the best Ruby book out there]]></description>
4
4
  <author>David Thomas, Andrew Hunt, Dave Thomas</author>
5
- </book>
5
+ <pagecount>357</pagecount></book>
@@ -0,0 +1,7 @@
1
+ <book ISBN="0201710897">
2
+ <title>The PickAxe</title>
3
+ <description><![CDATA[Probably the best Ruby book out there]]></description>
4
+ <author>David Thomas</author>
5
+ <author>Andrew Hunt</author>
6
+ <author>Dave Thomas</author>
7
+ </book>
@@ -0,0 +1,7 @@
1
+ <book isbn="0974514055">
2
+ <title>Programming Ruby - 2nd Edition</title>
3
+ <description>Second edition of the great book out there</description>
4
+ <contributor role="author" name="David Thomas" />
5
+ <contributor role="supporting author" name="Andrew Hunt" />
6
+ <contributor role="supporting author" name="Chad Fowler" />
7
+ </book>
@@ -0,0 +1,9 @@
1
+ <book xmlns="http://booknamespace.org" isbn="0974514055">
2
+ <title>Programming Ruby - 2nd Edition</title>
3
+ <description>Second edition of the great book out there</description>
4
+ <contributions>
5
+ <contributor role="author"><name>David Thomas</name></contributor>
6
+ <contributor role="supporting author"><name>Andrew Hunt</name></contributor>
7
+ <contributor role="supporting author"><name>Chad Fowler</name></contributor>
8
+ </contributions>
9
+ </book>
@@ -0,0 +1,6 @@
1
+ <book ISBN="0201710897">
2
+ <title>The PickAxe</title>
3
+ <description><![CDATA[Probably the best Ruby book out there]]></description>
4
+ <author>David Thomas, Andrew Hunt, Dave Thomas</author>
5
+ <depth units="hundredths-meters">1130</depth>
6
+ </book>
@@ -0,0 +1,3 @@
1
+ <book>
2
+ <ids ISBN="0974514055" />
3
+ </book>
@@ -0,0 +1,8 @@
1
+ <dictionary>
2
+ <definition name="quaquaversally">
3
+ <content>adjective: (of a geological formation) sloping downward from the center in all directions.</content>
4
+ </definition>
5
+ <definition name="tergiversate">
6
+ <content>To use evasions or ambiguities; equivocate.</content>
7
+ </definition>
8
+ </dictionary>
@@ -0,0 +1,6 @@
1
+ <dictionary>
2
+ <definitions>
3
+ <definition dt="quaquaversally" dd="adjective: (of a geological formation) sloping downward from the center in all directions." />
4
+ <definition dt="tergiversate" dd="To use evasions or ambiguities; equivocate." />
5
+ </definitions>
6
+ </dictionary>
@@ -0,0 +1,6 @@
1
+ <dictionary>
2
+ <definitions>
3
+ <quaquaversally>adjective: (of a geological formation) sloping downward from the center in all directions.</quaquaversally>
4
+ <tergiversate>To use evasions or ambiguities; equivocate.</tergiversate>
5
+ </definitions>
6
+ </dictionary>
@@ -0,0 +1,4 @@
1
+ <dictionary>
2
+ <definition word="quaquaversally">adjective: (of a geological formation) sloping downward from the center in all directions.</definition>
3
+ <definition word="tergiversate">To use evasions or ambiguities; equivocate.</definition>
4
+ </dictionary>
@@ -0,0 +1,10 @@
1
+ <dictionary>
2
+ <definition>
3
+ <name>quaquaversally</name>
4
+ <content>adjective: (of a geological formation) sloping downward from the center in all directions.</content>
5
+ </definition>
6
+ <definition>
7
+ <name>tergiversate</name>
8
+ <content>To use evasions or ambiguities; equivocate.</content>
9
+ </definition>
10
+ </dictionary>
@@ -0,0 +1,4 @@
1
+ <dictionary>
2
+ <quaquaversally>adjective: (of a geological formation) sloping downward from the center in all directions.</quaquaversally>
3
+ <tergiversate>To use evasions or ambiguities; equivocate.</tergiversate>
4
+ </dictionary>
@@ -0,0 +1,10 @@
1
+ <dictionary>
2
+ <definition>
3
+ <word>quaquaversally</word>
4
+ <meaning>adjective: (of a geological formation) sloping downward from the center in all directions.</meaning>
5
+ </definition>
6
+ <definition>
7
+ <word>tergiversate</word>
8
+ <meaning>To use evasions or ambiguities; equivocate.</meaning>
9
+ </definition>
10
+ </dictionary>
@@ -2,7 +2,7 @@
2
2
  <name>Ruby library</name>
3
3
  <book isbn="0974514055">
4
4
  <title>Programming Ruby - 2nd Edition</title>
5
- <description>Second edition of the great book out there></description>
5
+ <description>Second edition of the great book out there</description>
6
6
  <contributions>
7
7
  <contributor role="author">
8
8
  <name>David Thomas</name>
@@ -0,0 +1,30 @@
1
+ <library>
2
+ <NAME>Ruby library</NAME>
3
+ <BOOK isbn="0974514055">
4
+ <title>Programming Ruby - 2nd Edition</title>
5
+ <description>Second edition of the great book out there</description>
6
+ <contributions>
7
+ <contributor role="author">
8
+ <name>David Thomas</name>
9
+ </contributor>
10
+ <contributor role="supporting author">
11
+ <name>Andrew Hunt</name>
12
+ </contributor>
13
+ <contributor role="supporting author">
14
+ <name>Chad Fowler</name>
15
+ </contributor>
16
+ </contributions>
17
+ </BOOK>
18
+ <BOOK isbn="0974514055">
19
+ <title>Agile Web Development with Rails</title>
20
+ <description>Jolt winning original Ruby on Rails book</description>
21
+ <contributions>
22
+ <contributor role="author">
23
+ <name>David Thomas</name>
24
+ </contributor>
25
+ <contributor role="author">
26
+ <name>David Heinemeier Hansson</name>
27
+ </contributor>
28
+ </contributions>
29
+ </BOOK>
30
+ </library>
@@ -0,0 +1,3 @@
1
+ <muffins>
2
+ <bakers_dozens>3</bakers_dozens>
3
+ </muffins>
@@ -0,0 +1,2 @@
1
+ <person>
2
+ </person>
@@ -0,0 +1 @@
1
+ <node content="Just junk... really" name="Cartwheel" />
@@ -0,0 +1,4 @@
1
+ <node>
2
+ <content>Just junk... really</content>
3
+ <name>Cartwheel</name>
4
+ </node>
@@ -0,0 +1,4 @@
1
+ <numerology>
2
+ <prediction number="13" meaning="A bad number" />
3
+ <prediction number="7" meaning="A good number" />
4
+ </numerology>
@@ -0,0 +1,13 @@
1
+ <person>
2
+ <name>Ben Franklin</name>
3
+ <mother>
4
+ <person>
5
+ <name>Abiah Folger</name>
6
+ <mother>
7
+ <person>
8
+ <name>Madeup Mother</name>
9
+ </person>
10
+ </mother>
11
+ </person>
12
+ </mother>
13
+ </person>
@@ -0,0 +1,10 @@
1
+ <person>
2
+ <name>Ben Franklin</name>
3
+ <mother>
4
+ <name>Abiah Folger</name>
5
+ <mother>
6
+ <name>Madeup Mother</name>
7
+ </mother>
8
+ </mother>
9
+ </person>
10
+