roxml 3.1.5 → 3.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/{spec/spec.opts → .rspec} +0 -0
- data/History.txt +12 -1
- data/README.rdoc +19 -2
- data/Rakefile +11 -13
- data/VERSION +1 -1
- data/examples/amazon.rb +1 -1
- data/examples/current_weather.rb +1 -1
- data/examples/dashed_elements.rb +1 -1
- data/examples/posts.rb +1 -1
- data/examples/rails.rb +1 -1
- data/examples/twitter.rb +1 -1
- data/lib/roxml.rb +8 -1
- data/lib/roxml/definition.rb +6 -4
- data/lib/roxml/xml.rb +3 -3
- data/lib/roxml/xml/parsers/libxml.rb +46 -52
- data/lib/roxml/xml/parsers/nokogiri.rb +46 -41
- data/lib/roxml/xml/references.rb +25 -18
- data/roxml.gemspec +10 -8
- data/spec/definition_spec.rb +8 -7
- data/spec/examples/active_record_spec.rb +3 -2
- data/spec/examples/amazon_spec.rb +2 -2
- data/spec/examples/current_weather_spec.rb +2 -2
- data/spec/examples/dashed_elements_spec.rb +2 -2
- data/spec/examples/library_spec.rb +5 -5
- data/spec/examples/post_spec.rb +2 -2
- data/spec/examples/twitter_spec.rb +2 -2
- data/spec/roxml_spec.rb +2 -2
- data/spec/shared_specs.rb +2 -2
- data/spec/spec_helper.rb +3 -4
- data/spec/xml/array_spec.rb +36 -0
- data/spec/xml/attributes_spec.rb +5 -5
- data/spec/xml/encoding_spec.rb +38 -7
- data/spec/xml/namespace_spec.rb +4 -4
- data/spec/xml/namespaces_spec.rb +1 -1
- data/spec/xml/object_spec.rb +5 -5
- data/spec/xml/parser_spec.rb +8 -13
- data/spec/xml/text_spec.rb +5 -5
- data/test/mocks/dictionaries.rb +1 -1
- data/test/mocks/mocks.rb +1 -1
- data/test/support/fixtures.rb +1 -1
- data/test/test_helper.rb +5 -5
- data/test/unit/definition_test.rb +5 -5
- data/test/unit/deprecations_test.rb +1 -1
- data/test/unit/to_xml_test.rb +4 -4
- data/test/unit/xml_attribute_test.rb +1 -1
- data/test/unit/xml_block_test.rb +1 -1
- data/test/unit/xml_bool_test.rb +1 -1
- data/test/unit/xml_convention_test.rb +1 -1
- data/test/unit/xml_hash_test.rb +1 -1
- data/test/unit/xml_initialize_test.rb +1 -1
- data/test/unit/xml_name_test.rb +2 -2
- data/test/unit/xml_namespace_test.rb +1 -1
- data/test/unit/xml_object_test.rb +3 -4
- data/test/unit/xml_required_test.rb +1 -1
- data/test/unit/xml_text_test.rb +1 -1
- metadata +63 -27
data/lib/roxml/xml/references.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module ROXML
|
2
2
|
class RequiredElementMissing < Exception # :nodoc:
|
3
3
|
end
|
4
|
-
|
4
|
+
|
5
5
|
#
|
6
6
|
# Internal base class that represents an XML - Class binding.
|
7
7
|
#
|
@@ -52,7 +52,7 @@ module ROXML
|
|
52
52
|
def namespacify(what)
|
53
53
|
if what.to_s.present? && !what.to_s.include?(':') && opts.namespace != false
|
54
54
|
[opts.namespace, @instance.class.roxml_namespace, @default_namespace].each do |namespace|
|
55
|
-
return opts.namespace == '*' ? "*[local-name()='#{what}']" : "#{namespace}:#{what}" if namespace
|
55
|
+
return opts.namespace == '*' ? (what == '*' ? "*" : "*[local-name()='#{what}']") : "#{namespace}:#{what}" if namespace
|
56
56
|
end
|
57
57
|
end
|
58
58
|
what
|
@@ -98,15 +98,15 @@ module ROXML
|
|
98
98
|
if !opts[:always_create] && (child = xml.children.find {|c| c.name == wrap_with })
|
99
99
|
return child
|
100
100
|
end
|
101
|
-
|
101
|
+
XML.add_node(xml, wrap_with.to_s)
|
102
102
|
end
|
103
103
|
|
104
104
|
def nodes_in(xml)
|
105
105
|
@default_namespace = xml.default_namespace
|
106
|
-
vals = xml.
|
106
|
+
vals = xml.roxml_search(xpath, @instance.class.roxml_namespaces)
|
107
107
|
|
108
108
|
if several? && vals.empty? && !wrapper && auto_xpath
|
109
|
-
vals = xml.
|
109
|
+
vals = xml.roxml_search(auto_xpath, @instance.class.roxml_namespaces)
|
110
110
|
@auto_vals = !vals.empty?
|
111
111
|
end
|
112
112
|
|
@@ -136,12 +136,12 @@ module ROXML
|
|
136
136
|
if array?
|
137
137
|
values.each do |value|
|
138
138
|
wrap(xml, :always_create => true).tap do |node|
|
139
|
-
node
|
139
|
+
XML.set_attribute(node, name, value.to_s)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
else
|
143
143
|
wrap(xml).tap do |xml|
|
144
|
-
xml
|
144
|
+
XML.set_attribute(xml, name, values.to_s)
|
145
145
|
end
|
146
146
|
end
|
147
147
|
end
|
@@ -177,10 +177,10 @@ module ROXML
|
|
177
177
|
xml.name = value
|
178
178
|
elsif array?
|
179
179
|
value.each do |v|
|
180
|
-
add(
|
180
|
+
add(XML.add_node(xml, name), v)
|
181
181
|
end
|
182
182
|
else
|
183
|
-
add(
|
183
|
+
add(XML.add_node(xml, name), value)
|
184
184
|
end
|
185
185
|
end
|
186
186
|
end
|
@@ -210,13 +210,20 @@ module ROXML
|
|
210
210
|
|
211
211
|
def add(dest, value)
|
212
212
|
if cdata?
|
213
|
-
|
213
|
+
XML.add_cdata(dest, value.to_s)
|
214
214
|
else
|
215
|
-
dest
|
215
|
+
XML.set_content(dest, value.to_s)
|
216
216
|
end
|
217
217
|
end
|
218
218
|
end
|
219
219
|
|
220
|
+
class XMLNameSpaceRef < XMLRef # :nodoc:
|
221
|
+
private
|
222
|
+
def fetch_value(xml)
|
223
|
+
xml.namespace.prefix
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
220
227
|
class XMLHashRef < XMLTextRef # :nodoc:
|
221
228
|
delegate :hash, :to => :opts
|
222
229
|
|
@@ -235,7 +242,7 @@ module ROXML
|
|
235
242
|
def update_xml(xml, value)
|
236
243
|
wrap(xml).tap do |xml|
|
237
244
|
value.each_pair do |k, v|
|
238
|
-
node =
|
245
|
+
node = XML.add_node(xml, hash.wrapper)
|
239
246
|
@key.update_xml(node, k)
|
240
247
|
@value.update_xml(node, v)
|
241
248
|
end
|
@@ -289,14 +296,14 @@ module ROXML
|
|
289
296
|
params = {:name => name, :namespace => opts.namespace}
|
290
297
|
if array?
|
291
298
|
value.each do |v|
|
292
|
-
|
299
|
+
XML.add_child(xml, v.to_xml(params))
|
293
300
|
end
|
294
301
|
elsif value.is_a?(ROXML)
|
295
|
-
|
302
|
+
XML.add_child(xml, value.to_xml(params))
|
296
303
|
else
|
297
|
-
|
298
|
-
|
299
|
-
|
304
|
+
XML.add_node(xml, name).tap do |node|
|
305
|
+
XML.set_content(node, value.to_xml)
|
306
|
+
end
|
300
307
|
end
|
301
308
|
end
|
302
309
|
end
|
@@ -312,4 +319,4 @@ module ROXML
|
|
312
319
|
end
|
313
320
|
end
|
314
321
|
end
|
315
|
-
end
|
322
|
+
end
|
data/roxml.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{roxml}
|
8
|
-
s.version = "3.1.
|
8
|
+
s.version = "3.1.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ben Woosley", "Zak Mandhro", "Anders Engstrom", "Russ Olsen"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-11-03}
|
13
13
|
s.description = %q{ROXML is a Ruby library designed to make it easier for Ruby developers to work with XML.
|
14
14
|
Using simple annotations, it enables Ruby classes to be mapped to XML. ROXML takes care
|
15
15
|
of the marshalling and unmarshalling of mapped attributes so that developers can focus on
|
@@ -24,6 +24,7 @@ RESTful applications, Web Services, and XML-RPC.
|
|
24
24
|
s.files = [
|
25
25
|
".gitignore",
|
26
26
|
".gitmodules",
|
27
|
+
".rspec",
|
27
28
|
"History.txt",
|
28
29
|
"LICENSE",
|
29
30
|
"README.rdoc",
|
@@ -61,10 +62,10 @@ RESTful applications, Web Services, and XML-RPC.
|
|
61
62
|
"spec/examples/twitter_spec.rb",
|
62
63
|
"spec/roxml_spec.rb",
|
63
64
|
"spec/shared_specs.rb",
|
64
|
-
"spec/spec.opts",
|
65
65
|
"spec/spec_helper.rb",
|
66
66
|
"spec/support/libxml.rb",
|
67
67
|
"spec/support/nokogiri.rb",
|
68
|
+
"spec/xml/array_spec.rb",
|
68
69
|
"spec/xml/attributes_spec.rb",
|
69
70
|
"spec/xml/encoding_spec.rb",
|
70
71
|
"spec/xml/namespace_spec.rb",
|
@@ -127,7 +128,7 @@ RESTful applications, Web Services, and XML-RPC.
|
|
127
128
|
s.rdoc_options = ["--charset=UTF-8"]
|
128
129
|
s.require_paths = ["lib"]
|
129
130
|
s.rubyforge_project = %q{roxml}
|
130
|
-
s.rubygems_version = %q{1.3.
|
131
|
+
s.rubygems_version = %q{1.3.7}
|
131
132
|
s.summary = %q{Ruby Object to XML mapping library}
|
132
133
|
s.test_files = [
|
133
134
|
"spec/definition_spec.rb",
|
@@ -143,6 +144,7 @@ RESTful applications, Web Services, and XML-RPC.
|
|
143
144
|
"spec/spec_helper.rb",
|
144
145
|
"spec/support/libxml.rb",
|
145
146
|
"spec/support/nokogiri.rb",
|
147
|
+
"spec/xml/array_spec.rb",
|
146
148
|
"spec/xml/attributes_spec.rb",
|
147
149
|
"spec/xml/encoding_spec.rb",
|
148
150
|
"spec/xml/namespace_spec.rb",
|
@@ -182,23 +184,23 @@ RESTful applications, Web Services, and XML-RPC.
|
|
182
184
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
183
185
|
s.specification_version = 3
|
184
186
|
|
185
|
-
if Gem::Version.new(Gem::
|
187
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
186
188
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.0"])
|
187
189
|
s.add_runtime_dependency(%q<nokogiri>, [">= 1.3.3"])
|
188
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
190
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
189
191
|
s.add_development_dependency(%q<sqlite3-ruby>, [">= 1.2.4"])
|
190
192
|
s.add_development_dependency(%q<activerecord>, [">= 2.2.2"])
|
191
193
|
else
|
192
194
|
s.add_dependency(%q<activesupport>, [">= 2.3.0"])
|
193
195
|
s.add_dependency(%q<nokogiri>, [">= 1.3.3"])
|
194
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
196
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
195
197
|
s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.4"])
|
196
198
|
s.add_dependency(%q<activerecord>, [">= 2.2.2"])
|
197
199
|
end
|
198
200
|
else
|
199
201
|
s.add_dependency(%q<activesupport>, [">= 2.3.0"])
|
200
202
|
s.add_dependency(%q<nokogiri>, [">= 1.3.3"])
|
201
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
203
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
202
204
|
s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.4"])
|
203
205
|
s.add_dependency(%q<activerecord>, [">= 2.2.2"])
|
204
206
|
end
|
data/spec/definition_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative './spec_helper'
|
2
3
|
|
3
4
|
describe ROXML::Definition do
|
4
5
|
describe "#name_explicit?" do
|
@@ -13,7 +14,7 @@ describe ROXML::Definition do
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
+
shared_examples_for "DateTime reference" do
|
17
18
|
it "should return nil on empty string" do
|
18
19
|
@subject.blocks.first.call(" ").should be_nil
|
19
20
|
end
|
@@ -29,7 +30,7 @@ describe ROXML::Definition do
|
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
|
33
|
+
shared_examples_for "Date reference" do
|
33
34
|
it "should return nil on empty string" do
|
34
35
|
@subject.blocks.first.call(" ").should be_nil
|
35
36
|
end
|
@@ -128,7 +129,7 @@ describe ROXML::Definition do
|
|
128
129
|
end
|
129
130
|
|
130
131
|
describe "=> {}" do
|
131
|
-
|
132
|
+
shared_examples_for "hash options declaration" do
|
132
133
|
it "should represent a hash" do
|
133
134
|
@opts.hash?.should be_true
|
134
135
|
end
|
@@ -210,7 +211,7 @@ describe ROXML::Definition do
|
|
210
211
|
proc { ROXML::Definition.new(:count, :as => :foat) }.should raise_error(ArgumentError)
|
211
212
|
end
|
212
213
|
|
213
|
-
|
214
|
+
shared_examples_for "block shorthand type declaration" do
|
214
215
|
it "should translate nil to nil" do
|
215
216
|
@definition.blocks.first.call(nil).should be_nil
|
216
217
|
end
|
@@ -390,7 +391,7 @@ describe ROXML::Definition do
|
|
390
391
|
end
|
391
392
|
|
392
393
|
describe ":from" do
|
393
|
-
|
394
|
+
shared_examples_for "attribute reference" do
|
394
395
|
it "should be interpreted as :attr" do
|
395
396
|
@opts.sought_type.should == :attr
|
396
397
|
end
|
@@ -450,7 +451,7 @@ describe ROXML::Definition do
|
|
450
451
|
|
451
452
|
describe "options" do
|
452
453
|
|
453
|
-
|
454
|
+
shared_examples_for "boolean option" do
|
454
455
|
it "should be recognized" do
|
455
456
|
ROXML::Definition.new(:author, :from => :content, @option => true).respond_to?(:"#{@option}?")
|
456
457
|
ROXML::Definition.new(:author, :from => :content, @option => true).send(:"#{@option}?").should be_true
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative './../spec_helper'
|
2
|
+
require_relative './../../examples/library'
|
3
3
|
|
4
4
|
describe Library do
|
5
5
|
before :all do
|
@@ -17,7 +17,7 @@ describe Library do
|
|
17
17
|
|
18
18
|
describe "#to_xml" do
|
19
19
|
it "should contain the expected information" do
|
20
|
-
@lib.to_xml.to_s.should == ROXML::XML
|
20
|
+
@lib.to_xml.to_s.should == ROXML::XML.parse_string(%{<library><NAME><![CDATA[Favorite Books]]></NAME><novel ISBN='0201710897'><title>The PickAxe</title><description><![CDATA[Best Ruby book out there!]]></description><author>David Thomas, Andrew Hunt, Dave Thomas</author><publisher><name>Addison Wesley Longman, Inc.</name></publisher></novel></library>}).root.to_s
|
21
21
|
end
|
22
22
|
|
23
23
|
context "when written to a file" do
|
@@ -25,7 +25,7 @@ describe Library do
|
|
25
25
|
@path = "spec/examples/library.xml"
|
26
26
|
@doc = ROXML::XML::Document.new
|
27
27
|
@doc.root = @lib.to_xml
|
28
|
-
|
28
|
+
ROXML::XML.save_doc(@doc, @path)
|
29
29
|
end
|
30
30
|
|
31
31
|
after :all do
|
@@ -33,7 +33,7 @@ describe Library do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should be contain the expected xml" do
|
36
|
-
ROXML::XML
|
36
|
+
ROXML::XML.parse_string(File.read(@path)).to_s.should == ROXML::XML.parse_string(%{<?xml version="1.0"?><library><NAME><![CDATA[Favorite Books]]></NAME><novel ISBN='0201710897'><title>The PickAxe</title><description><![CDATA[Best Ruby book out there!]]></description><author>David Thomas, Andrew Hunt, Dave Thomas</author><publisher><name>Addison Wesley Longman, Inc.</name></publisher></novel></library>}).to_s
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should be re-parsable via .from_xml" do
|
data/spec/examples/post_spec.rb
CHANGED
data/spec/roxml_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
require_relative './spec_helper'
|
2
2
|
|
3
3
|
describe ROXML, "#from_xml" do
|
4
|
-
|
4
|
+
shared_examples_for "from_xml call" do
|
5
5
|
it "should fetch values" do
|
6
6
|
book = BookWithContributors.from_xml(@path)
|
7
7
|
book.title.should == "Programming Ruby - 2nd Edition"
|
data/spec/shared_specs.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
require_relative './spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
shared_examples_for "freezable xml reference" do
|
4
4
|
describe "with :frozen option" do
|
5
5
|
it "should be frozen" do
|
6
6
|
@frozen.frozen?.should be_true
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'pathname'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
require 'spec/shared_specs' if defined?(Spec)
|
3
|
+
require_relative './../test/support/fixtures'
|
4
|
+
require_relative './../lib/roxml'
|
5
|
+
require_relative './shared_specs'
|
7
6
|
|
8
7
|
def xml_for(name)
|
9
8
|
Pathname.new(File.dirname(__FILE__)).expand_path.dirname.join("examples/xml/#{name}.xml")
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative './../spec_helper'
|
2
|
+
|
3
|
+
module ArraySpec
|
4
|
+
class Book
|
5
|
+
include ROXML
|
6
|
+
xml_reader :id, :as => Integer
|
7
|
+
xml_reader :title
|
8
|
+
end
|
9
|
+
|
10
|
+
class Store
|
11
|
+
include ROXML
|
12
|
+
xml_reader :books, :from => 'books', :as => [Book]
|
13
|
+
end
|
14
|
+
|
15
|
+
class MyXml
|
16
|
+
include ROXML
|
17
|
+
xml_reader :store, :as => Store
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
describe ":as => []" do
|
23
|
+
context "with plural from" do
|
24
|
+
it "should accept the plural name as the name for each item" do
|
25
|
+
ArraySpec::MyXml.from_xml(%(
|
26
|
+
<myxml>
|
27
|
+
<store>
|
28
|
+
<books><id>1</id><title>first book</title></books>
|
29
|
+
<books><id>2</id><title>second book</title></books>
|
30
|
+
<books><id>3</id><title>third book</title></books>
|
31
|
+
</store>
|
32
|
+
</myxml>
|
33
|
+
)).store.books.size.should == 3
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/xml/attributes_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
require_relative './../spec_helper'
|
2
2
|
|
3
3
|
describe ROXML::XMLAttributeRef do
|
4
4
|
before do
|
5
|
-
@xml = ROXML::XML
|
5
|
+
@xml = ROXML::XML.parse_string %(
|
6
6
|
<myxml>
|
7
7
|
<node name="first" />
|
8
8
|
<node name="second" />
|
@@ -31,7 +31,7 @@ describe ROXML::XMLAttributeRef do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should output all instances" do
|
34
|
-
xml = ROXML::XML
|
34
|
+
xml = ROXML::XML.new_node('myxml')
|
35
35
|
@ref.update_xml(xml, ["first", "second", "third"])
|
36
36
|
xml.to_s.squeeze(' ').should == @xml.root.to_s.squeeze(' ')
|
37
37
|
end
|
@@ -39,7 +39,7 @@ describe ROXML::XMLAttributeRef do
|
|
39
39
|
|
40
40
|
context "when the namespaces are different" do
|
41
41
|
before do
|
42
|
-
@xml = ROXML::XML
|
42
|
+
@xml = ROXML::XML.parse_string %(
|
43
43
|
<document>
|
44
44
|
<myxml xmlns="http://example.com/three" xmlns:one="http://example.com/one" xmlns:two="http://example.com/two">
|
45
45
|
<one:node name="first" />
|
@@ -62,7 +62,7 @@ describe ROXML::XMLAttributeRef do
|
|
62
62
|
|
63
63
|
it "should output all instances with namespaces" do
|
64
64
|
pending "Full namespace write support"
|
65
|
-
xml = ROXML::XML
|
65
|
+
xml = ROXML::XML.new_node('result')
|
66
66
|
@ref.update_xml(xml, ["first", "second", "third"])
|
67
67
|
xml.should == @xml.root
|
68
68
|
end
|