representable 0.0.1.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/.gitignore +7 -0
  2. data/.gitmodules +3 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +3 -0
  5. data/History.txt +354 -0
  6. data/LICENSE +20 -0
  7. data/README.rdoc +186 -0
  8. data/Rakefile +10 -0
  9. data/TODO +37 -0
  10. data/VERSION +1 -0
  11. data/examples/amazon.rb +35 -0
  12. data/examples/current_weather.rb +27 -0
  13. data/examples/dashed_elements.rb +20 -0
  14. data/examples/library.rb +40 -0
  15. data/examples/posts.rb +27 -0
  16. data/examples/rails.rb +70 -0
  17. data/examples/twitter.rb +37 -0
  18. data/examples/xml/active_record.xml +70 -0
  19. data/examples/xml/amazon.xml +133 -0
  20. data/examples/xml/current_weather.xml +89 -0
  21. data/examples/xml/dashed_elements.xml +52 -0
  22. data/examples/xml/posts.xml +23 -0
  23. data/examples/xml/twitter.xml +422 -0
  24. data/lib/representable.rb +257 -0
  25. data/lib/representable/definition.rb +109 -0
  26. data/lib/representable/nokogiri_extensions.rb +19 -0
  27. data/lib/representable/references.rb +153 -0
  28. data/lib/representable/version.rb +3 -0
  29. data/lib/representable/xml.rb +79 -0
  30. data/representable.gemspec +29 -0
  31. data/spec/definition_spec.rb +495 -0
  32. data/spec/examples/active_record_spec.rb +41 -0
  33. data/spec/examples/amazon_spec.rb +54 -0
  34. data/spec/examples/current_weather_spec.rb +37 -0
  35. data/spec/examples/dashed_elements_spec.rb +20 -0
  36. data/spec/examples/library_spec.rb +46 -0
  37. data/spec/examples/post_spec.rb +24 -0
  38. data/spec/examples/twitter_spec.rb +32 -0
  39. data/spec/roxml_integration_test.rb +289 -0
  40. data/spec/roxml_spec.rb +372 -0
  41. data/spec/shared_specs.rb +15 -0
  42. data/spec/spec_helper.rb +5 -0
  43. data/spec/support/libxml.rb +3 -0
  44. data/spec/support/nokogiri.rb +3 -0
  45. data/spec/xml/array_spec.rb +36 -0
  46. data/spec/xml/attributes_spec.rb +71 -0
  47. data/spec/xml/encoding_spec.rb +53 -0
  48. data/spec/xml/namespace_spec.rb +270 -0
  49. data/spec/xml/namespaces_spec.rb +67 -0
  50. data/spec/xml/object_spec.rb +82 -0
  51. data/spec/xml/parser_spec.rb +21 -0
  52. data/spec/xml/text_spec.rb +71 -0
  53. data/test/fixtures/book_malformed.xml +5 -0
  54. data/test/fixtures/book_pair.xml +8 -0
  55. data/test/fixtures/book_text_with_attribute.xml +5 -0
  56. data/test/fixtures/book_valid.xml +5 -0
  57. data/test/fixtures/book_with_authors.xml +7 -0
  58. data/test/fixtures/book_with_contributions.xml +9 -0
  59. data/test/fixtures/book_with_contributors.xml +7 -0
  60. data/test/fixtures/book_with_contributors_attrs.xml +7 -0
  61. data/test/fixtures/book_with_default_namespace.xml +9 -0
  62. data/test/fixtures/book_with_depth.xml +6 -0
  63. data/test/fixtures/book_with_octal_pages.xml +4 -0
  64. data/test/fixtures/book_with_publisher.xml +7 -0
  65. data/test/fixtures/book_with_wrapped_attr.xml +3 -0
  66. data/test/fixtures/dictionary_of_attr_name_clashes.xml +8 -0
  67. data/test/fixtures/dictionary_of_attrs.xml +6 -0
  68. data/test/fixtures/dictionary_of_guarded_names.xml +6 -0
  69. data/test/fixtures/dictionary_of_mixeds.xml +4 -0
  70. data/test/fixtures/dictionary_of_name_clashes.xml +10 -0
  71. data/test/fixtures/dictionary_of_names.xml +4 -0
  72. data/test/fixtures/dictionary_of_texts.xml +10 -0
  73. data/test/fixtures/library.xml +30 -0
  74. data/test/fixtures/library_uppercase.xml +30 -0
  75. data/test/fixtures/muffins.xml +3 -0
  76. data/test/fixtures/nameless_ageless_youth.xml +2 -0
  77. data/test/fixtures/node_with_attr_name_conflicts.xml +1 -0
  78. data/test/fixtures/node_with_name_conflicts.xml +4 -0
  79. data/test/fixtures/numerology.xml +4 -0
  80. data/test/fixtures/person.xml +1 -0
  81. data/test/fixtures/person_with_guarded_mothers.xml +13 -0
  82. data/test/fixtures/person_with_mothers.xml +10 -0
  83. data/test/mocks/dictionaries.rb +57 -0
  84. data/test/mocks/mocks.rb +279 -0
  85. data/test/roxml_test.rb +58 -0
  86. data/test/support/fixtures.rb +11 -0
  87. data/test/test_helper.rb +6 -0
  88. data/test/unit/definition_test.rb +235 -0
  89. data/test/unit/deprecations_test.rb +24 -0
  90. data/test/unit/to_xml_test.rb +81 -0
  91. data/test/unit/xml_attribute_test.rb +39 -0
  92. data/test/unit/xml_block_test.rb +81 -0
  93. data/test/unit/xml_bool_test.rb +122 -0
  94. data/test/unit/xml_convention_test.rb +150 -0
  95. data/test/unit/xml_hash_test.rb +115 -0
  96. data/test/unit/xml_initialize_test.rb +49 -0
  97. data/test/unit/xml_name_test.rb +141 -0
  98. data/test/unit/xml_namespace_test.rb +31 -0
  99. data/test/unit/xml_object_test.rb +206 -0
  100. data/test/unit/xml_required_test.rb +94 -0
  101. data/test/unit/xml_text_test.rb +71 -0
  102. data/website/index.html +98 -0
  103. metadata +248 -0
@@ -0,0 +1,71 @@
1
+ require_relative './../test_helper'
2
+
3
+ class TestXMLText < ActiveSupport::TestCase
4
+ # Test a simple mapping with no composition
5
+ def test_valid_simple
6
+ book = Book.from_xml(fixture(:book_valid))
7
+ assert_equal("The PickAxe", book.title)
8
+ assert_equal("David Thomas, Andrew Hunt & Dave Thomas", book.author)
9
+
10
+ assert_equal xml_fixture(:book_valid).to_s.gsub("\n", ''), book.to_xml.to_s.gsub("\n", '')
11
+ end
12
+
13
+ def test_without_needed_from
14
+ assert !Library.from_xml(fixture(:library_uppercase)).name
15
+ end
16
+
17
+ def test_with_needed_from
18
+ assert_equal "Ruby library", Library.from_xml(fixture(:library)).name
19
+ assert_equal "Ruby library", UppercaseLibrary.from_xml(fixture(:library_uppercase)).name
20
+ end
21
+
22
+ def test_as_array
23
+ assert_equal ["David Thomas","Andrew Hunt","Dave Thomas"].sort,
24
+ BookWithAuthors.from_xml(fixture(:book_with_authors)).authors.sort
25
+ end
26
+
27
+ def test_empty_array_result_returned_properly
28
+ empty_array = Class.new do
29
+ include ROXML
30
+
31
+ xml_reader :missing_array, :as => [], :from => 'missing'
32
+ end
33
+
34
+ obj = empty_array.from_xml('<empty_array></empty_array>')
35
+ assert_equal [], obj.missing_array
36
+ end
37
+
38
+ def test_text_modification
39
+ person = Person.from_xml(fixture(:person))
40
+ assert_equal("Ben Franklin", person.name)
41
+ person.name = "Fred"
42
+ xml=person.to_xml.to_s
43
+ assert(/Fred/=~xml)
44
+ end
45
+
46
+ def test_default_initialization
47
+ person = PersonWithMotherOrMissing.from_xml(fixture(:nameless_ageless_youth))
48
+ assert_equal "Anonymous", person.name
49
+ end
50
+
51
+ def test_default_initialization_of_content
52
+ person = Person.from_xml(fixture(:nameless_ageless_youth))
53
+ assert_equal "Unknown", person.name
54
+ end
55
+
56
+ def test_recursive_with_default_initialization
57
+ p = PersonWithMotherOrMissing.from_xml(fixture(:person_with_mothers))
58
+ assert_equal 'Unknown', p.mother.mother.mother.name
59
+ end
60
+
61
+ def test_get_with_block
62
+ p = Book.from_xml(fixture(:book_valid))
63
+ assert_equal 357, p.pages
64
+ end
65
+
66
+ def test_no_name_clashes
67
+ n = NodeWithNameConflicts.from_xml(fixture(:node_with_name_conflicts))
68
+ assert_equal "Just junk... really", n.content
69
+ assert_equal "Cartwheel", n.name
70
+ end
71
+ end
@@ -0,0 +1,98 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
+
8
+ <title>Empact/roxml @ GitHub</title>
9
+
10
+ <style type="text/css">
11
+ body {
12
+ margin-top: 1.0em;
13
+ background-color: #baafdb;
14
+ font-family: "helvetica";
15
+ color: #000000;
16
+ }
17
+ #container {
18
+ margin: 0 auto;
19
+ width: 700px;
20
+ }
21
+ h1 { font-size: 3.8em; color: #455024; margin-bottom: 3px; }
22
+ h1 .small { font-size: 0.4em; }
23
+ h1 a { text-decoration: none }
24
+ h2 { font-size: 1.5em; color: #455024; }
25
+ h3 { text-align: center; color: #455024; }
26
+ a { color: #455024; }
27
+ .description { font-size: 1.2em; margin-bottom: 30px; margin-top: 30px; font-style: italic;}
28
+ .download { float: right; }
29
+ pre { background: #000; color: #fff; padding: 15px;}
30
+ hr { border: 0; width: 80%; border-bottom: 1px solid #aaa}
31
+ .footer { text-align:center; padding-top:30px; font-style: italic; }
32
+ </style>
33
+
34
+ </head>
35
+
36
+ <body>
37
+ <a href="http://github.com/Empact/roxml"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
38
+
39
+ <div id="container">
40
+
41
+ <div class="download">
42
+ <a href="http://github.com/Empact/roxml/zipball/master">
43
+ <img border="0" width="90" src="http://github.com/images/modules/download/zip.png"></a>
44
+ <a href="http://github.com/Empact/roxml/tarball/master">
45
+ <img border="0" width="90" src="http://github.com/images/modules/download/tar.png"></a>
46
+ </div>
47
+
48
+ <h1><a href="http://github.com/Empact/roxml">roxml</a>
49
+ <span class="small">by <a href="http://github.com/Empact">Empact</a></small></h1>
50
+
51
+ <div class="description">
52
+ ROXML is a module for binding Ruby classes to XML. It supports custom mapping and bidirectional marshaling between Ruby and XML using annotation-style class methods. ROXML supports the Nokogiri and LibXML XML processors.
53
+ </div>
54
+
55
+ <p>We may not want to work with XML, but we don't always get to pick just how our data comes. If you do need to do serious work with XML, ROXML is here to make it nice.
56
+
57
+ Use xpath-based xml declarations to map an XML response into an extensible object, use that object, and then ouput it back to xml as it came.
58
+
59
+ Aside from the basics, ROXML has a lot of little goodies to make these definitions minimal and readable, which are worth digging in for. See the 'xml_convention' method for easily referencing xml which uses other naming conventions. See the handling of '?' in accessor names, the application of blocks and such for other manipulations.
60
+
61
+ And finally, if you use this library, feel free to push code back my way. I'll be looking forward to it.</p><h2>Dependencies</h2>
62
+ <p>activesupport >= 2.1.0</p>
63
+ <h2>Install</h2>
64
+ <p>'gem install roxml' will install the latest stable <a href="http://rubyforge.org/frs/?group_id=305">rubyforge version</a></p>
65
+ <h2>License</h2>
66
+ <p>MIT License</p>
67
+ <h2>Authors</h2>
68
+ <p>Ben Woosley (ben.woosley@gmail.com)
69
+ <br/>Anders Engström (anders.engstrom@gnejs.net)
70
+ <br/>James Thompson (james@plainprograms.com)
71
+ <br/>James Healy (jimmy@deefa.com)
72
+ <br/>Zak Mandhro (mandhro@yahoo.com)
73
+ <br/>Russ Olsen (russell.olsen@gmail.com)</p>
74
+ <h2>Contact</h2>
75
+ <p>Ben Woosley (Ben.Woosley@gmail.com)
76
+ <br/> </p>
77
+
78
+
79
+ <h2>Download</h2>
80
+ <p>
81
+ You can download this project in either
82
+ <a href="http://github.com/Empact/roxml/zipball/master">zip</a> or
83
+ <a href="http://github.com/Empact/roxml/tarball/master">tar</a> formats.
84
+ </p>
85
+ <p>You can also clone the project with <a href="http://git-scm.com">Git</a>
86
+ by running:
87
+ <pre>$ git clone git://github.com/Empact/roxml</pre>
88
+ </p>
89
+
90
+ <div class="footer">
91
+ get the source code on GitHub : <a href="http://github.com/Empact/roxml">Empact/roxml</a>
92
+ </div>
93
+
94
+ </div>
95
+
96
+
97
+ </body>
98
+ </html>
metadata ADDED
@@ -0,0 +1,248 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: representable
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ - alpha1
10
+ version: 0.0.1.alpha1
11
+ platform: ruby
12
+ authors:
13
+ - Nick Sutterer
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-29 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 3
31
+ - 0
32
+ - 0
33
+ version: 3.0.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: hooks
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: nokogiri
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: i18n
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ type: :runtime
74
+ version_requirements: *id004
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ prerelease: false
78
+ requirement: &id005 !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ type: :development
87
+ version_requirements: *id005
88
+ - !ruby/object:Gem::Dependency
89
+ name: test_xml
90
+ prerelease: false
91
+ requirement: &id006 !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ type: :development
100
+ version_requirements: *id006
101
+ description: CMaps representation documents from and to Ruby objects. Includes XML and JSON support, plain properties and compositions.
102
+ email:
103
+ - apotonick@gmail.com
104
+ executables: []
105
+
106
+ extensions: []
107
+
108
+ extra_rdoc_files: []
109
+
110
+ files:
111
+ - .gitignore
112
+ - .gitmodules
113
+ - .rspec
114
+ - Gemfile
115
+ - History.txt
116
+ - LICENSE
117
+ - README.rdoc
118
+ - Rakefile
119
+ - TODO
120
+ - VERSION
121
+ - examples/amazon.rb
122
+ - examples/current_weather.rb
123
+ - examples/dashed_elements.rb
124
+ - examples/library.rb
125
+ - examples/posts.rb
126
+ - examples/rails.rb
127
+ - examples/twitter.rb
128
+ - examples/xml/active_record.xml
129
+ - examples/xml/amazon.xml
130
+ - examples/xml/current_weather.xml
131
+ - examples/xml/dashed_elements.xml
132
+ - examples/xml/posts.xml
133
+ - examples/xml/twitter.xml
134
+ - lib/representable.rb
135
+ - lib/representable/definition.rb
136
+ - lib/representable/nokogiri_extensions.rb
137
+ - lib/representable/references.rb
138
+ - lib/representable/version.rb
139
+ - lib/representable/xml.rb
140
+ - representable.gemspec
141
+ - spec/definition_spec.rb
142
+ - spec/examples/active_record_spec.rb
143
+ - spec/examples/amazon_spec.rb
144
+ - spec/examples/current_weather_spec.rb
145
+ - spec/examples/dashed_elements_spec.rb
146
+ - spec/examples/library_spec.rb
147
+ - spec/examples/post_spec.rb
148
+ - spec/examples/twitter_spec.rb
149
+ - spec/roxml_integration_test.rb
150
+ - spec/roxml_spec.rb
151
+ - spec/shared_specs.rb
152
+ - spec/spec_helper.rb
153
+ - spec/support/libxml.rb
154
+ - spec/support/nokogiri.rb
155
+ - spec/xml/array_spec.rb
156
+ - spec/xml/attributes_spec.rb
157
+ - spec/xml/encoding_spec.rb
158
+ - spec/xml/namespace_spec.rb
159
+ - spec/xml/namespaces_spec.rb
160
+ - spec/xml/object_spec.rb
161
+ - spec/xml/parser_spec.rb
162
+ - spec/xml/text_spec.rb
163
+ - test/fixtures/book_malformed.xml
164
+ - test/fixtures/book_pair.xml
165
+ - test/fixtures/book_text_with_attribute.xml
166
+ - test/fixtures/book_valid.xml
167
+ - test/fixtures/book_with_authors.xml
168
+ - test/fixtures/book_with_contributions.xml
169
+ - test/fixtures/book_with_contributors.xml
170
+ - test/fixtures/book_with_contributors_attrs.xml
171
+ - test/fixtures/book_with_default_namespace.xml
172
+ - test/fixtures/book_with_depth.xml
173
+ - test/fixtures/book_with_octal_pages.xml
174
+ - test/fixtures/book_with_publisher.xml
175
+ - test/fixtures/book_with_wrapped_attr.xml
176
+ - test/fixtures/dictionary_of_attr_name_clashes.xml
177
+ - test/fixtures/dictionary_of_attrs.xml
178
+ - test/fixtures/dictionary_of_guarded_names.xml
179
+ - test/fixtures/dictionary_of_mixeds.xml
180
+ - test/fixtures/dictionary_of_name_clashes.xml
181
+ - test/fixtures/dictionary_of_names.xml
182
+ - test/fixtures/dictionary_of_texts.xml
183
+ - test/fixtures/library.xml
184
+ - test/fixtures/library_uppercase.xml
185
+ - test/fixtures/muffins.xml
186
+ - test/fixtures/nameless_ageless_youth.xml
187
+ - test/fixtures/node_with_attr_name_conflicts.xml
188
+ - test/fixtures/node_with_name_conflicts.xml
189
+ - test/fixtures/numerology.xml
190
+ - test/fixtures/person.xml
191
+ - test/fixtures/person_with_guarded_mothers.xml
192
+ - test/fixtures/person_with_mothers.xml
193
+ - test/mocks/dictionaries.rb
194
+ - test/mocks/mocks.rb
195
+ - test/roxml_test.rb
196
+ - test/support/fixtures.rb
197
+ - test/test_helper.rb
198
+ - test/unit/definition_test.rb
199
+ - test/unit/deprecations_test.rb
200
+ - test/unit/to_xml_test.rb
201
+ - test/unit/xml_attribute_test.rb
202
+ - test/unit/xml_block_test.rb
203
+ - test/unit/xml_bool_test.rb
204
+ - test/unit/xml_convention_test.rb
205
+ - test/unit/xml_hash_test.rb
206
+ - test/unit/xml_initialize_test.rb
207
+ - test/unit/xml_name_test.rb
208
+ - test/unit/xml_namespace_test.rb
209
+ - test/unit/xml_object_test.rb
210
+ - test/unit/xml_required_test.rb
211
+ - test/unit/xml_text_test.rb
212
+ - website/index.html
213
+ has_rdoc: true
214
+ homepage: http://representable.apotomo.de
215
+ licenses: []
216
+
217
+ post_install_message:
218
+ rdoc_options: []
219
+
220
+ require_paths:
221
+ - lib
222
+ required_ruby_version: !ruby/object:Gem::Requirement
223
+ none: false
224
+ requirements:
225
+ - - ">="
226
+ - !ruby/object:Gem::Version
227
+ segments:
228
+ - 0
229
+ version: "0"
230
+ required_rubygems_version: !ruby/object:Gem::Requirement
231
+ none: false
232
+ requirements:
233
+ - - ">"
234
+ - !ruby/object:Gem::Version
235
+ segments:
236
+ - 1
237
+ - 3
238
+ - 1
239
+ version: 1.3.1
240
+ requirements: []
241
+
242
+ rubyforge_project:
243
+ rubygems_version: 1.3.7
244
+ signing_key:
245
+ specification_version: 3
246
+ summary: Maps representation documents from and to Ruby objects. Includes XML and JSON support, plain properties and compositions.
247
+ test_files: []
248
+