roxml 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE.txt +9 -0
- data/doc/classes/ROXML.html +352 -0
- data/doc/classes/ROXML.src/M000003.html +19 -0
- data/doc/classes/ROXML.src/M000004.html +25 -0
- data/doc/classes/ROXML.src/M000005.html +22 -0
- data/doc/classes/ROXML/ROXML_Class.html +422 -0
- data/doc/classes/ROXML/ROXML_Class.src/M000006.html +27 -0
- data/doc/classes/ROXML/ROXML_Class.src/M000007.html +18 -0
- data/doc/classes/ROXML/ROXML_Class.src/M000008.html +19 -0
- data/doc/classes/ROXML/ROXML_Class.src/M000009.html +24 -0
- data/doc/classes/ROXML/ROXML_Class.src/M000010.html +24 -0
- data/doc/classes/ROXML/ROXML_Class.src/M000011.html +18 -0
- data/doc/classes/ROXML/ROXML_Class.src/M000012.html +18 -0
- data/doc/classes/ROXML/XMLAttributeRef.html +175 -0
- data/doc/classes/ROXML/XMLAttributeRef.src/M000015.html +19 -0
- data/doc/classes/ROXML/XMLAttributeRef.src/M000016.html +19 -0
- data/doc/classes/ROXML/XMLObjectRef.html +175 -0
- data/doc/classes/ROXML/XMLObjectRef.src/M000013.html +26 -0
- data/doc/classes/ROXML/XMLObjectRef.src/M000014.html +32 -0
- data/doc/classes/ROXML/XMLRef.html +212 -0
- data/doc/classes/ROXML/XMLRef.src/M000017.html +21 -0
- data/doc/classes/ROXML/XMLRef.src/M000018.html +18 -0
- data/doc/classes/ROXML/XMLRef.src/M000019.html +18 -0
- data/doc/classes/ROXML/XMLTextRef.html +193 -0
- data/doc/classes/ROXML/XMLTextRef.src/M000020.html +26 -0
- data/doc/classes/ROXML/XMLTextRef.src/M000021.html +33 -0
- data/doc/classes/String.html +165 -0
- data/doc/classes/String.src/M000001.html +23 -0
- data/doc/classes/String.src/M000002.html +23 -0
- data/doc/created.rid +1 -0
- data/doc/files/lib/roxml_rb.html +234 -0
- data/doc/fr_class_index.html +33 -0
- data/doc/fr_file_index.html +27 -0
- data/doc/fr_method_index.html +47 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/roxml.rb +507 -0
- data/test/fixture_helper.rb +5 -0
- data/test/fixtures/book_malformed.xml +5 -0
- data/test/fixtures/book_pair.xml +8 -0
- data/test/fixtures/book_valid.xml +5 -0
- data/test/fixtures/book_with_contributions.xml +9 -0
- data/test/fixtures/book_with_contributors.xml +7 -0
- data/test/fixtures/book_with_publisher.xml +7 -0
- data/test/fixtures/library.xml +30 -0
- data/test/mocks/mocks.rb +59 -0
- data/test/test_roxml.rb +90 -0
- metadata +104 -0
@@ -0,0 +1,8 @@
|
|
1
|
+
<book isbn="0974514055">
|
2
|
+
<title>Programming Ruby - 2nd Edition</title>
|
3
|
+
<description>Second edition of the great book out there</description>
|
4
|
+
<book isbn="0974514055">
|
5
|
+
<title>Agile Web Development with Rails</title>
|
6
|
+
<description>Jolt winning original Ruby on Rails book</description>
|
7
|
+
</book>
|
8
|
+
</book>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<book 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,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</name></contributor>
|
5
|
+
<contributor role="supporting author"><name>Andrew Hunt</name></contributor>
|
6
|
+
<contributor role="supporting author"><name>Chad Fowler</name></contributor>
|
7
|
+
</book>
|
@@ -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>
|
data/test/mocks/mocks.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "lib/roxml"
|
2
|
+
|
3
|
+
class RoxmlMockObject
|
4
|
+
include ROXML
|
5
|
+
end
|
6
|
+
|
7
|
+
class Book < RoxmlMockObject
|
8
|
+
xml_attribute :isbn
|
9
|
+
xml_text :title
|
10
|
+
xml_text :description, nil, ROXML::TAG_CDATA
|
11
|
+
xml_text :author
|
12
|
+
end
|
13
|
+
|
14
|
+
class Contributor < RoxmlMockObject
|
15
|
+
xml_attribute :role
|
16
|
+
xml_text :name
|
17
|
+
end
|
18
|
+
|
19
|
+
class BookWithContributions < RoxmlMockObject
|
20
|
+
xml_name :book
|
21
|
+
xml_attribute :isbn
|
22
|
+
xml_text :title
|
23
|
+
xml_text :description
|
24
|
+
xml_object :contributions, Contributor, ROXML::TAG_ARRAY, "contributions"
|
25
|
+
end
|
26
|
+
|
27
|
+
class BookWithContributors < RoxmlMockObject
|
28
|
+
xml_name :book
|
29
|
+
xml_attribute :isbn
|
30
|
+
xml_text :title
|
31
|
+
xml_text :description
|
32
|
+
xml_object :contributors, Contributor, ROXML::TAG_ARRAY
|
33
|
+
end
|
34
|
+
|
35
|
+
class Publisher < RoxmlMockObject
|
36
|
+
xml_text :name
|
37
|
+
end
|
38
|
+
|
39
|
+
class BookWithPublisher < RoxmlMockObject
|
40
|
+
xml_name :book
|
41
|
+
xml_attribute :isbn
|
42
|
+
xml_text :title
|
43
|
+
xml_text :description
|
44
|
+
xml_object :publisher, Publisher
|
45
|
+
end
|
46
|
+
|
47
|
+
class BookPair < RoxmlMockObject
|
48
|
+
xml_attribute :isbn
|
49
|
+
xml_text :title
|
50
|
+
xml_text :description
|
51
|
+
xml_text :author
|
52
|
+
xml_object :book, Book
|
53
|
+
end
|
54
|
+
|
55
|
+
class Library < RoxmlMockObject
|
56
|
+
xml_text :name
|
57
|
+
xml_object :books, BookWithContributions, ROXML::TAG_ARRAY
|
58
|
+
end
|
59
|
+
|
data/test/test_roxml.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require "lib/roxml"
|
2
|
+
require "test/unit"
|
3
|
+
require "test/fixture_helper"
|
4
|
+
require "test/mocks/mocks"
|
5
|
+
|
6
|
+
class TestROXML < Test::Unit::TestCase
|
7
|
+
include FixtureHelper
|
8
|
+
|
9
|
+
# Test a simple mapping with no composition
|
10
|
+
def test_valid_simple
|
11
|
+
book = Book.parse(fixture(:book_valid))
|
12
|
+
assert_equal("The PickAxe", book.title)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Malformed XML parsing should throw REXML::ParseException
|
16
|
+
def test_malformed
|
17
|
+
begin
|
18
|
+
book = Book.parse(fixture(:book_malformed))
|
19
|
+
fail()
|
20
|
+
rescue REXML::ParseException
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Test XML object containing list of other XML objects (one-to-many)
|
25
|
+
# In this case, book with contibutions
|
26
|
+
def test_one_to_many_with_container
|
27
|
+
expected_authors = ["David Thomas","Andrew Hunt","Chad Fowler"]
|
28
|
+
book = BookWithContributions.parse(fixture(:book_with_contributions))
|
29
|
+
assert_equal("Programming Ruby - 2nd Edition", book.title)
|
30
|
+
book.contributions.each do |contributor|
|
31
|
+
assert expected_authors.include?(contributor.name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Test XML object containing 1-n other XML objects without container (one-to-many)
|
36
|
+
# In this case, book with contibutions
|
37
|
+
def test_one_to_many_without_container
|
38
|
+
expected_contributors = ["David Thomas","Andrew Hunt","Chad Fowler"]
|
39
|
+
book = BookWithContributors.parse(fixture(:book_with_contributors))
|
40
|
+
assert_equal("Programming Ruby - 2nd Edition", book.title)
|
41
|
+
book.contributors.each do |contributor|
|
42
|
+
assert(expected_contributors.include?(contributor.name))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Test XML object containing one other XML object (one-to-one)
|
47
|
+
# In this case, book with publisher
|
48
|
+
def test_one_to_one
|
49
|
+
book = BookWithPublisher.parse(fixture(:book_with_publisher))
|
50
|
+
assert_equal("Programming Ruby - 2nd Edition", book.title)
|
51
|
+
assert_equal("Pragmatic Bookshelf", book.publisher.name)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Test XML object containing type of self (self-reference)
|
55
|
+
def test_self_reference
|
56
|
+
book = BookPair.parse(fixture(:book_pair))
|
57
|
+
assert_equal("Programming Ruby - 2nd Edition", book.title)
|
58
|
+
assert_equal("Agile Web Development with Rails", book.book.title)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Test three-level composition (one-to-many-to-many)
|
62
|
+
def test_one_to_many_to_many
|
63
|
+
expected_contributors = ["David Thomas","Andrew Hunt","Chad Fowler", "David Heinemeier Hansson"]
|
64
|
+
expected_books = ["Programming Ruby - 2nd Edition", "Agile Web Development with Rails"]
|
65
|
+
library = Library.parse(fixture(:library))
|
66
|
+
assert_equal("Ruby library", library.name)
|
67
|
+
library.books.each do |book|
|
68
|
+
assert expected_books.include?(book.title)
|
69
|
+
book.contributions.each do |contributor|
|
70
|
+
assert(expected_contributors.include?(contributor.name))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Verify that an exception is thrown when two accessors have the same
|
76
|
+
# name in a ROXML class.
|
77
|
+
def test_duplicate_accessor
|
78
|
+
begin
|
79
|
+
klass = Class.new do
|
80
|
+
include ROXML
|
81
|
+
|
82
|
+
xml_attribute :id
|
83
|
+
xml_text :id
|
84
|
+
end
|
85
|
+
raise "Defining a class with multiple accessors with same name should fail."
|
86
|
+
rescue
|
87
|
+
# Ok we should fail.
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: roxml
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "1.0"
|
7
|
+
date: 2006-07-01 00:00:00 -04:00
|
8
|
+
summary: Ruby Object to XML mapping library
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email:
|
12
|
+
homepage: http://roxml.rubyforge.org
|
13
|
+
rubyforge_project:
|
14
|
+
description: ROXML is a Ruby library designed to make it easier for Ruby developers to work with XML. Using simple annotations, it enables Ruby classes to be mapped to XML. ROXML takes care of the marshalling and unmarshalling of mapped attributes so that developers can focus on building first-class Ruby classes. As a result, ROXML simplifies the development of RESTful applications, Web Services, and XML-RPC.
|
15
|
+
autorequire: roxml
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
authors:
|
29
|
+
- Zak Mandhro
|
30
|
+
files:
|
31
|
+
- lib/roxml.rb
|
32
|
+
- MIT-LICENSE.txt
|
33
|
+
- test/test_roxml.rb
|
34
|
+
- test/mocks
|
35
|
+
- test/fixtures
|
36
|
+
- test/fixture_helper.rb
|
37
|
+
- test/mocks/mocks.rb
|
38
|
+
- test/fixtures/book_pair.xml
|
39
|
+
- test/fixtures/book_valid.xml
|
40
|
+
- test/fixtures/book_malformed.xml
|
41
|
+
- test/fixtures/book_with_publisher.xml
|
42
|
+
- test/fixtures/book_with_contributions.xml
|
43
|
+
- test/fixtures/book_with_contributors.xml
|
44
|
+
- test/fixtures/library.xml
|
45
|
+
- doc/created.rid
|
46
|
+
- doc/rdoc-style.css
|
47
|
+
- doc/files
|
48
|
+
- doc/classes
|
49
|
+
- doc/fr_file_index.html
|
50
|
+
- doc/fr_class_index.html
|
51
|
+
- doc/fr_method_index.html
|
52
|
+
- doc/index.html
|
53
|
+
- doc/files/lib
|
54
|
+
- doc/files/lib/roxml_rb.html
|
55
|
+
- doc/classes/String.src
|
56
|
+
- doc/classes/ROXML.src
|
57
|
+
- doc/classes/ROXML
|
58
|
+
- doc/classes/String.html
|
59
|
+
- doc/classes/ROXML.html
|
60
|
+
- doc/classes/String.src/M000001.html
|
61
|
+
- doc/classes/String.src/M000002.html
|
62
|
+
- doc/classes/ROXML.src/M000003.html
|
63
|
+
- doc/classes/ROXML.src/M000004.html
|
64
|
+
- doc/classes/ROXML.src/M000005.html
|
65
|
+
- doc/classes/ROXML/ROXML_Class.src
|
66
|
+
- doc/classes/ROXML/XMLObjectRef.src
|
67
|
+
- doc/classes/ROXML/XMLAttributeRef.src
|
68
|
+
- doc/classes/ROXML/XMLRef.src
|
69
|
+
- doc/classes/ROXML/XMLTextRef.src
|
70
|
+
- doc/classes/ROXML/ROXML_Class.html
|
71
|
+
- doc/classes/ROXML/XMLObjectRef.html
|
72
|
+
- doc/classes/ROXML/XMLAttributeRef.html
|
73
|
+
- doc/classes/ROXML/XMLRef.html
|
74
|
+
- doc/classes/ROXML/XMLTextRef.html
|
75
|
+
- doc/classes/ROXML/ROXML_Class.src/M000006.html
|
76
|
+
- doc/classes/ROXML/ROXML_Class.src/M000007.html
|
77
|
+
- doc/classes/ROXML/ROXML_Class.src/M000008.html
|
78
|
+
- doc/classes/ROXML/ROXML_Class.src/M000009.html
|
79
|
+
- doc/classes/ROXML/ROXML_Class.src/M000010.html
|
80
|
+
- doc/classes/ROXML/ROXML_Class.src/M000011.html
|
81
|
+
- doc/classes/ROXML/ROXML_Class.src/M000012.html
|
82
|
+
- doc/classes/ROXML/XMLObjectRef.src/M000013.html
|
83
|
+
- doc/classes/ROXML/XMLObjectRef.src/M000014.html
|
84
|
+
- doc/classes/ROXML/XMLAttributeRef.src/M000015.html
|
85
|
+
- doc/classes/ROXML/XMLAttributeRef.src/M000016.html
|
86
|
+
- doc/classes/ROXML/XMLRef.src/M000017.html
|
87
|
+
- doc/classes/ROXML/XMLRef.src/M000018.html
|
88
|
+
- doc/classes/ROXML/XMLRef.src/M000019.html
|
89
|
+
- doc/classes/ROXML/XMLTextRef.src/M000020.html
|
90
|
+
- doc/classes/ROXML/XMLTextRef.src/M000021.html
|
91
|
+
test_files:
|
92
|
+
- test/test_roxml.rb
|
93
|
+
rdoc_options: []
|
94
|
+
|
95
|
+
extra_rdoc_files: []
|
96
|
+
|
97
|
+
executables: []
|
98
|
+
|
99
|
+
extensions: []
|
100
|
+
|
101
|
+
requirements:
|
102
|
+
- none
|
103
|
+
dependencies: []
|
104
|
+
|