roxml 3.2.2 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ == 3.3.0 (February 9, 2012)
2
+
3
+ * major enhancement
4
+
5
+ * Don't extend/modify the XML parser
6
+
1
7
  == 3.1.6 (September 9, 2010)
2
8
 
3
9
  * bug fix
data/Rakefile CHANGED
@@ -26,19 +26,15 @@ Jeweler::GemcutterTasks.new
26
26
 
27
27
  Dir['tasks/**/*.rake'].each { |t| load t }
28
28
 
29
- task :default => [:test, :spec, 'test:load']
30
- task :all => [:libxml, :nokogiri, 'test:load']
29
+ task :default => [:test, :spec]
30
+ task :all => [:libxml, :nokogiri]
31
31
  task :libxml => ['test:libxml', 'spec:libxml']
32
32
  task :nokogiri => ['test:nokogiri', 'spec:nokogiri']
33
33
 
34
34
 
35
35
  require 'rdoc/task'
36
36
  RDoc::Task.new do |rdoc|
37
- if File.exist?('VERSION')
38
- version = File.read('VERSION')
39
- else
40
- version = ""
41
- end
37
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
38
 
43
39
  rdoc.rdoc_dir = 'rdoc'
44
40
  rdoc.title = "roxml #{version}"
@@ -93,11 +89,6 @@ namespace :test do
93
89
  Rake::Task["test"].invoke
94
90
  end
95
91
 
96
- task :load do
97
- `ruby test/load_test.rb`
98
- puts "Load Success!" if $?.success?
99
- end
100
-
101
92
  desc "Runs tests under RCOV"
102
93
  task :rcov do
103
94
  system "rcov -T --no-html -x '^/' #{FileList['test/unit/*_test.rb']}"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.2
1
+ 3.3.0
@@ -14,7 +14,7 @@ require 'roxml/definition'
14
14
  require 'roxml/xml'
15
15
 
16
16
  module ROXML # :nodoc:
17
- VERSION = '3.2.1'
17
+ VERSION = File.read('VERSION')
18
18
 
19
19
  def self.included(base) # :nodoc:
20
20
  base.class_eval do
@@ -44,42 +44,26 @@ module ROXML
44
44
  def save_doc(doc, path)
45
45
  doc.save(path)
46
46
  end
47
- end
48
47
 
49
- Document = LibXML::XML::Document
50
- Node = LibXML::XML::Node
48
+ def default_namespace(doc)
49
+ doc = doc.doc if doc.respond_to?(:doc)
50
+ default = doc.root.namespaces.default
51
+ default.prefix || 'xmlns' if default
52
+ end
51
53
 
52
- module NamespacedSearch
53
- def roxml_search(xpath, roxml_namespaces = {})
54
- if namespaces.default
54
+ def search(xml, xpath, roxml_namespaces = {})
55
+ if xml.namespaces.default
55
56
  roxml_namespaces = {:xmlns => namespaces.default.href}.merge(roxml_namespaces)
56
57
  end
57
58
  if roxml_namespaces.present?
58
- find(xpath, roxml_namespaces.map {|prefix, href| [prefix, href].join(':') })
59
+ xml.find(xpath, roxml_namespaces.map {|prefix, href| [prefix, href].join(':') })
59
60
  else
60
- find(xpath)
61
+ xml.find(xpath)
61
62
  end
62
63
  end
63
64
  end
64
65
 
65
- class Document
66
- include NamespacedSearch
67
-
68
- def default_namespace
69
- default = namespaces.default
70
- default.prefix || 'xmlns' if default
71
- end
72
-
73
- private
74
- delegate :namespaces, :to => :root
75
- end
76
-
77
- class Node
78
- include NamespacedSearch
79
-
80
- def default_namespace
81
- doc.default_namespace
82
- end
83
- end
66
+ Document = LibXML::XML::Document
67
+ Node = LibXML::XML::Node
84
68
  end
85
69
  end
@@ -46,37 +46,24 @@ module ROXML
46
46
  file << doc.serialize
47
47
  end
48
48
  end
49
- end
50
-
51
- Document = Nokogiri::XML::Document
52
- Element = Nokogiri::XML::Element
53
- Node = Nokogiri::XML::Node
54
-
55
- class Document
56
- alias :roxml_search :search
57
-
58
- def default_namespace
59
- 'xmlns' if root.namespaces['xmlns']
60
- end
61
- end
62
49
 
63
- module NodeExtensions
64
- def roxml_search(xpath, roxml_namespaces = {})
65
- xpath = "./#{xpath}"
66
- (roxml_namespaces.present? ? search(xpath, roxml_namespaces) : search(xpath))
50
+ def default_namespace(doc)
51
+ doc = doc.document if doc.respond_to?(:document)
52
+ 'xmlns' if doc.root.namespaces['xmlns']
67
53
  end
68
54
 
69
- def default_namespace
70
- document.default_namespace
55
+ def search(xml, xpath, roxml_namespaces = {})
56
+ case xml
57
+ when Nokogiri::XML::Document
58
+ xml.search(xpath, roxml_namespaces)
59
+ else
60
+ xpath = "./#{xpath}"
61
+ (roxml_namespaces.present? ? xml.search(xpath, roxml_namespaces) : xml.search(xpath))
62
+ end
71
63
  end
72
64
  end
73
65
 
74
- class Element
75
- include NodeExtensions
76
- end
77
-
78
- class Node
79
- include NodeExtensions
80
- end
66
+ Document = Nokogiri::XML::Document
67
+ Node = Nokogiri::XML::Node
81
68
  end
82
69
  end
@@ -60,11 +60,9 @@ module ROXML
60
60
  end
61
61
 
62
62
  def apply_blocks(val)
63
- begin
64
- blocks.inject(val) {|val, block| block.call(val) }
65
- rescue Exception => ex
66
- raise ex, "#{accessor}: #{ex.message}"
67
- end
63
+ blocks.inject(val) {|val, block| block.call(val) }
64
+ rescue Exception => ex
65
+ raise ex, "#{accessor}: #{ex.message}"
68
66
  end
69
67
 
70
68
  def freeze(val)
@@ -90,26 +88,25 @@ module ROXML
90
88
 
91
89
  def wrap(xml, opts = {:always_create => false})
92
90
  wrap_with = @auto_vals ? auto_wrapper : wrapper
93
-
91
+
94
92
  return xml if !wrap_with || xml.name == wrap_with
95
93
 
96
94
  wraps = wrap_with.to_s.split('/')
97
- wraps.inject(xml) do |node,wrap|
98
- if !opts[:always_create] && (child = node.children.find {|c| c.name == wrap })
95
+ wraps.inject(xml) do |node,wrap|
96
+ if !opts[:always_create] && (child = node.children.find {|c| c.name == wrap })
99
97
  child
100
98
  else
101
- XML.add_node(node, wrap)
99
+ XML.add_node(node, wrap)
102
100
  end
103
- end
104
-
101
+ end
105
102
  end
106
103
 
107
104
  def nodes_in(xml)
108
- @default_namespace = xml.default_namespace
109
- vals = xml.roxml_search(xpath, @instance.class.roxml_namespaces)
105
+ @default_namespace = XML.default_namespace(xml)
106
+ vals = XML.search(xml, xpath, @instance.class.roxml_namespaces)
110
107
 
111
108
  if several? && vals.empty? && !wrapper && auto_xpath
112
- vals = xml.roxml_search(auto_xpath, @instance.class.roxml_namespaces)
109
+ vals = XML.search(xml, auto_xpath, @instance.class.roxml_namespaces)
113
110
  @auto_vals = !vals.empty?
114
111
  end
115
112
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "roxml"
8
- s.version = "3.2.2"
8
+ s.version = "3.3.0"
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 = "2012-01-30"
12
+ s.date = "2012-02-10"
13
13
  s.description = "ROXML is a Ruby library designed to make it easier for Ruby developers to work with XML.\nUsing simple annotations, it enables Ruby classes to be mapped to XML. ROXML takes care\nof the marshalling and unmarshalling of mapped attributes so that developers can focus on\nbuilding first-class Ruby classes. As a result, ROXML simplifies the development of\nRESTful applications, Web Services, and XML-RPC.\n"
14
14
  s.email = "ben.woosley@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -107,7 +107,6 @@ Gem::Specification.new do |s|
107
107
  "test/fixtures/person.xml",
108
108
  "test/fixtures/person_with_guarded_mothers.xml",
109
109
  "test/fixtures/person_with_mothers.xml",
110
- "test/load_test.rb",
111
110
  "test/mocks/dictionaries.rb",
112
111
  "test/mocks/mocks.rb",
113
112
  "test/support/fixtures.rb",
@@ -2,36 +2,36 @@ require 'spec_helper'
2
2
  require_relative './../../examples/person'
3
3
 
4
4
  describe Person do
5
-
6
- before do
7
- @person = Person.new
8
- @person.name = 'John Doe'
9
- @person.lat = '40.715224'
10
- @person.long = '-74.005966'
11
- @person.street = 'Evergreen Terrace'
12
- @person.city = 'Springfield'
13
- @person.zip = '2342'
14
- end
15
5
 
16
- it 'should only contain one location element' do
17
- @person.to_xml.roxml_search('location').count.should == 1
18
- end
6
+ before do
7
+ @person = Person.new
8
+ @person.name = 'John Doe'
9
+ @person.lat = '40.715224'
10
+ @person.long = '-74.005966'
11
+ @person.street = 'Evergreen Terrace'
12
+ @person.city = 'Springfield'
13
+ @person.zip = '2342'
14
+ end
19
15
 
20
- describe '#to_xml' do
21
- before do
22
- @xml_generated = @person.to_xml.to_s.gsub("\n",'').squeeze(' ')
23
- end
16
+ it 'should only contain one location element' do
17
+ ROXML::XML.search(@person.to_xml, 'location').count.should == 1
18
+ end
24
19
 
25
- it 'should generate the expected xml' do
26
- xml_file = File.read(xml_for('person')).gsub("\n",'').squeeze(' ')
27
- xml_file.should == @xml_generated
28
- end
20
+ describe '#to_xml' do
21
+ before do
22
+ @xml_generated = @person.to_xml.to_s.gsub("\n",'').squeeze(' ')
23
+ end
29
24
 
30
- it 'should generate identical xml after a full roundtrip' do
31
- p = Person.from_xml(@xml_generated)
32
- xml_roundtrip = p.to_xml.to_s.gsub("\n",'').squeeze(' ')
33
- xml_roundtrip.should == @xml_generated
34
- end
35
- end
25
+ it 'should generate the expected xml' do
26
+ xml_file = File.read(xml_for('person')).gsub("\n",'').squeeze(' ')
27
+ xml_file.should == @xml_generated
28
+ end
29
+
30
+ it 'should generate identical xml after a full roundtrip' do
31
+ p = Person.from_xml(@xml_generated)
32
+ xml_roundtrip = p.to_xml.to_s.gsub("\n",'').squeeze(' ')
33
+ xml_roundtrip.should == @xml_generated
34
+ end
35
+ end
36
36
 
37
37
  end
@@ -1,34 +1,42 @@
1
1
  require_relative './spec_helper'
2
2
 
3
- describe ROXML, "#from_xml" do
4
- shared_examples_for "from_xml call" do
5
- it "should fetch values" do
6
- book = BookWithContributors.from_xml(@path)
7
- book.title.should == "Programming Ruby - 2nd Edition"
8
- book.contributors.map(&:name).should == ["David Thomas","Andrew Hunt","Chad Fowler"]
3
+ describe ROXML do
4
+ describe "::VERSION" do
5
+ it "should be equal to the VERSION file contents" do
6
+ ROXML::VERSION.should == File.read('VERSION')
9
7
  end
10
8
  end
11
9
 
12
- context "called with PathName" do
13
- before do
14
- @path = Pathname.new(fixture_path(:book_with_contributors))
10
+ describe "#from_xml" do
11
+ shared_examples_for "from_xml call" do
12
+ it "should fetch values" do
13
+ book = BookWithContributors.from_xml(@path)
14
+ book.title.should == "Programming Ruby - 2nd Edition"
15
+ book.contributors.map(&:name).should == ["David Thomas","Andrew Hunt","Chad Fowler"]
16
+ end
15
17
  end
16
- it_should_behave_like "from_xml call"
17
- end
18
18
 
19
- context "called with File" do
20
- before do
21
- @path = File.new(fixture_path(:book_with_contributors))
19
+ context "called with PathName" do
20
+ before do
21
+ @path = Pathname.new(fixture_path(:book_with_contributors))
22
+ end
23
+ it_should_behave_like "from_xml call"
22
24
  end
23
- it_should_behave_like "from_xml call"
24
- end
25
25
 
26
- context "called with URI" do
27
- before do
28
- require 'uri'
29
- @path = URI.parse("file://#{File.expand_path(File.expand_path(fixture_path(:book_with_contributors)))}")
26
+ context "called with File" do
27
+ before do
28
+ @path = File.new(fixture_path(:book_with_contributors))
29
+ end
30
+ it_should_behave_like "from_xml call"
31
+ end
32
+
33
+ context "called with URI" do
34
+ before do
35
+ require 'uri'
36
+ @path = URI.parse("file://#{File.expand_path(File.expand_path(fixture_path(:book_with_contributors)))}")
37
+ end
38
+ it_should_behave_like "from_xml call"
30
39
  end
31
- it_should_behave_like "from_xml call"
32
40
  end
33
41
  end
34
42
 
@@ -1,12 +1,6 @@
1
1
  require_relative './../spec_helper.rb'
2
2
 
3
3
  describe ROXML::XML do
4
- it "should raise on malformed xml" do
5
- if ROXML::XML_PARSER == 'libxml' # nokogiri is less strict and auto-closes for some reason
6
- proc { Book.from_xml(fixture(:book_malformed)) }.should raise_error(LibXML::XML::Error)
7
- end
8
- end
9
-
10
4
  it "should escape invalid characters on output to text node" do
11
5
  node = ROXML::XML.new_node("entities")
12
6
  ROXML::XML.set_content(node, " < > ' \" & ")
@@ -41,13 +41,13 @@ class TestToXmlWithBlocks < ActiveSupport::TestCase
41
41
  def test_pagecount_serialized_properly_after_modification
42
42
  b = Book.from_xml(fixture(:book_valid))
43
43
  xml = xml_fixture(:book_valid)
44
- assert_equal '357', xml.roxml_search('pagecount').first.content
44
+ assert_equal '357', ROXML::XML.search(xml, 'pagecount').first.content
45
45
  assert_equal 357, b.pages
46
46
 
47
47
  b.pages = 500
48
48
  doc = ROXML::XML::Document.new()
49
49
  doc.root = b.to_xml
50
- assert_equal '500', doc.roxml_search('pagecount').first.content
50
+ assert_equal '500', ROXML::XML.search(doc, 'pagecount').first.content
51
51
  end
52
52
  end
53
53
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2
4
+ version: 3.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,11 +12,11 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-01-30 00:00:00.000000000 Z
15
+ date: 2012-02-10 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
19
- requirement: &70164162904540 !ruby/object:Gem::Requirement
19
+ requirement: &70220601835920 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
22
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: 2.3.0
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70164162904540
27
+ version_requirements: *70220601835920
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: nokogiri
30
- requirement: &70164162900300 !ruby/object:Gem::Requirement
30
+ requirement: &70220601835200 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: 1.3.3
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *70164162900300
38
+ version_requirements: *70220601835200
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: rake
41
- requirement: &70164162909420 !ruby/object:Gem::Requirement
41
+ requirement: &70220601834620 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ! '>='
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: '0'
47
47
  type: :development
48
48
  prerelease: false
49
- version_requirements: *70164162909420
49
+ version_requirements: *70220601834620
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: jeweler
52
- requirement: &70164162927020 !ruby/object:Gem::Requirement
52
+ requirement: &70220601834040 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ! '>='
@@ -57,10 +57,10 @@ dependencies:
57
57
  version: '0'
58
58
  type: :development
59
59
  prerelease: false
60
- version_requirements: *70164162927020
60
+ version_requirements: *70220601834040
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
- requirement: &70164162923220 !ruby/object:Gem::Requirement
63
+ requirement: &70220601833200 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ! '>='
@@ -68,10 +68,10 @@ dependencies:
68
68
  version: 2.0.0
69
69
  type: :development
70
70
  prerelease: false
71
- version_requirements: *70164162923220
71
+ version_requirements: *70220601833200
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: sqlite3-ruby
74
- requirement: &70164162944020 !ruby/object:Gem::Requirement
74
+ requirement: &70220601832560 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
77
  - - ! '>='
@@ -79,10 +79,10 @@ dependencies:
79
79
  version: 1.2.4
80
80
  type: :development
81
81
  prerelease: false
82
- version_requirements: *70164162944020
82
+ version_requirements: *70220601832560
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activerecord
85
- requirement: &70164162960820 !ruby/object:Gem::Requirement
85
+ requirement: &70220601831960 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
88
  - - ! '>='
@@ -90,7 +90,7 @@ dependencies:
90
90
  version: 2.2.2
91
91
  type: :development
92
92
  prerelease: false
93
- version_requirements: *70164162960820
93
+ version_requirements: *70220601831960
94
94
  description: ! 'ROXML is a Ruby library designed to make it easier for Ruby developers
95
95
  to work with XML.
96
96
 
@@ -203,7 +203,6 @@ files:
203
203
  - test/fixtures/person.xml
204
204
  - test/fixtures/person_with_guarded_mothers.xml
205
205
  - test/fixtures/person_with_mothers.xml
206
- - test/load_test.rb
207
206
  - test/mocks/dictionaries.rb
208
207
  - test/mocks/mocks.rb
209
208
  - test/support/fixtures.rb
@@ -1,6 +0,0 @@
1
- require 'fileutils'
2
- FileUtils.cd(File.dirname(__FILE__))
3
-
4
- require 'rubygems'
5
- require 'roxml'
6
- puts ROXML::VERSION