jnunemaker-happymapper 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History +6 -0
- data/Manifest +1 -1
- data/happymapper.gemspec +3 -3
- data/lib/happymapper/version.rb +1 -1
- data/lib/happymapper.rb +5 -11
- data/spec/happymapper_spec.rb +3 -3
- metadata +1 -3
- data/lib/libxml_ext/libxml_helper.rb +0 -55
data/History
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 0.2.2
|
2
|
+
* 2 minor tweaks
|
3
|
+
* removed GC.start (libxml recommended this) as setting nodes to nil should be enough, specs run 3-4x faster (Brandon Keepers)
|
4
|
+
* renamed get_tag_name to tag_name (Brandon Keepers)
|
5
|
+
* removed libxml helpers as they are no longer needed
|
6
|
+
|
1
7
|
== 0.2.1
|
2
8
|
* 1 minor fix, 3 major enhancements
|
3
9
|
* fixed warnings about using XML::Parser (mojodna)
|
data/Manifest
CHANGED
@@ -3,13 +3,13 @@ examples/current_weather.rb
|
|
3
3
|
examples/dashed_elements.rb
|
4
4
|
examples/post.rb
|
5
5
|
examples/twitter.rb
|
6
|
+
happymapper.gemspec
|
6
7
|
History
|
7
8
|
lib/happymapper/attribute.rb
|
8
9
|
lib/happymapper/element.rb
|
9
10
|
lib/happymapper/item.rb
|
10
11
|
lib/happymapper/version.rb
|
11
12
|
lib/happymapper.rb
|
12
|
-
lib/libxml_ext/libxml_helper.rb
|
13
13
|
License
|
14
14
|
Manifest
|
15
15
|
Rakefile
|
data/happymapper.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{happymapper}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["John Nunemaker"]
|
9
9
|
s.date = %q{2009-01-29}
|
10
10
|
s.description = %q{object to xml mapping library}
|
11
11
|
s.email = %q{nunemaker@gmail.com}
|
12
|
-
s.extra_rdoc_files = ["lib/happymapper/attribute.rb", "lib/happymapper/element.rb", "lib/happymapper/item.rb", "lib/happymapper/version.rb", "lib/happymapper.rb", "
|
13
|
-
s.files = ["examples/amazon.rb", "examples/current_weather.rb", "examples/dashed_elements.rb", "examples/post.rb", "examples/twitter.rb", "happymapper.gemspec", "History", "lib/happymapper/attribute.rb", "lib/happymapper/element.rb", "lib/happymapper/item.rb", "lib/happymapper/version.rb", "lib/happymapper.rb", "
|
12
|
+
s.extra_rdoc_files = ["lib/happymapper/attribute.rb", "lib/happymapper/element.rb", "lib/happymapper/item.rb", "lib/happymapper/version.rb", "lib/happymapper.rb", "README", "TODO"]
|
13
|
+
s.files = ["examples/amazon.rb", "examples/current_weather.rb", "examples/dashed_elements.rb", "examples/post.rb", "examples/twitter.rb", "happymapper.gemspec", "History", "lib/happymapper/attribute.rb", "lib/happymapper/element.rb", "lib/happymapper/item.rb", "lib/happymapper/version.rb", "lib/happymapper.rb", "License", "Manifest", "Rakefile", "README", "spec/fixtures/address.xml", "spec/fixtures/commit.xml", "spec/fixtures/current_weather.xml", "spec/fixtures/family_tree.xml", "spec/fixtures/multiple_namespaces.xml", "spec/fixtures/pita.xml", "spec/fixtures/posts.xml", "spec/fixtures/product_default_namespace.xml", "spec/fixtures/product_no_namespace.xml", "spec/fixtures/product_single_namespace.xml", "spec/fixtures/radar.xml", "spec/fixtures/statuses.xml", "spec/happymapper_attribute_spec.rb", "spec/happymapper_element_spec.rb", "spec/happymapper_item_spec.rb", "spec/happymapper_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "TODO", "website/css/common.css", "website/index.html"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://happymapper.rubyforge.org}
|
16
16
|
s.post_install_message = %q{May you have many happy mappings!}
|
data/lib/happymapper/version.rb
CHANGED
data/lib/happymapper.rb
CHANGED
@@ -4,11 +4,8 @@ $:.unshift(dir) unless $:.include?(dir) || $:.include?(File.expand_path(dir))
|
|
4
4
|
require 'date'
|
5
5
|
require 'time'
|
6
6
|
require 'rubygems'
|
7
|
-
|
8
7
|
gem 'libxml-ruby', '= 0.9.8'
|
9
8
|
require 'xml'
|
10
|
-
require 'libxml_ext/libxml_helper'
|
11
|
-
|
12
9
|
|
13
10
|
class Boolean; end
|
14
11
|
|
@@ -65,10 +62,8 @@ module HappyMapper
|
|
65
62
|
@tag_name = new_tag_name.to_s
|
66
63
|
end
|
67
64
|
|
68
|
-
def
|
69
|
-
@tag_name ||=
|
70
|
-
to_s.split('::')[-1].downcase
|
71
|
-
end
|
65
|
+
def tag_name
|
66
|
+
@tag_name ||= to_s.split('::')[-1].downcase
|
72
67
|
end
|
73
68
|
|
74
69
|
def parse(xml, options = {})
|
@@ -81,10 +76,10 @@ module HappyMapper
|
|
81
76
|
if xml.is_a?(XML::Document)
|
82
77
|
node = xml.root
|
83
78
|
else
|
84
|
-
node = xml.
|
79
|
+
node = XML::Parser.string(xml).parse.root
|
85
80
|
end
|
86
81
|
|
87
|
-
root = node.name ==
|
82
|
+
root = node.name == tag_name
|
88
83
|
end
|
89
84
|
|
90
85
|
# This is the entry point into the parsing pipeline, so the default
|
@@ -97,7 +92,7 @@ module HappyMapper
|
|
97
92
|
|
98
93
|
xpath = root ? '/' : './/'
|
99
94
|
xpath += "#{namespace}:" if namespace
|
100
|
-
xpath +=
|
95
|
+
xpath += tag_name
|
101
96
|
# puts "parse: #{xpath}"
|
102
97
|
|
103
98
|
nodes = node.find(xpath)
|
@@ -119,7 +114,6 @@ module HappyMapper
|
|
119
114
|
|
120
115
|
# per http://libxml.rubyforge.org/rdoc/classes/LibXML/XML/Document.html#M000354
|
121
116
|
nodes = nil
|
122
|
-
GC.start
|
123
117
|
|
124
118
|
if options[:single] || root
|
125
119
|
collection.first
|
data/spec/happymapper_spec.rb
CHANGED
@@ -307,17 +307,17 @@ describe HappyMapper do
|
|
307
307
|
end
|
308
308
|
|
309
309
|
it "should default tag name to lowercase class" do
|
310
|
-
Foo.
|
310
|
+
Foo.tag_name.should == 'foo'
|
311
311
|
end
|
312
312
|
|
313
313
|
it "should default tag name of class in modules to the last constant lowercase" do
|
314
314
|
module Bar; class Baz; include HappyMapper; end; end
|
315
|
-
Bar::Baz.
|
315
|
+
Bar::Baz.tag_name.should == 'baz'
|
316
316
|
end
|
317
317
|
|
318
318
|
it "should allow setting tag name" do
|
319
319
|
Foo.tag('FooBar')
|
320
|
-
Foo.
|
320
|
+
Foo.tag_name.should == 'FooBar'
|
321
321
|
end
|
322
322
|
|
323
323
|
it "should allow setting a namespace" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jnunemaker-happymapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -42,7 +42,6 @@ extra_rdoc_files:
|
|
42
42
|
- lib/happymapper/item.rb
|
43
43
|
- lib/happymapper/version.rb
|
44
44
|
- lib/happymapper.rb
|
45
|
-
- lib/libxml_ext/libxml_helper.rb
|
46
45
|
- README
|
47
46
|
- TODO
|
48
47
|
files:
|
@@ -58,7 +57,6 @@ files:
|
|
58
57
|
- lib/happymapper/item.rb
|
59
58
|
- lib/happymapper/version.rb
|
60
59
|
- lib/happymapper.rb
|
61
|
-
- lib/libxml_ext/libxml_helper.rb
|
62
60
|
- License
|
63
61
|
- Manifest
|
64
62
|
- Rakefile
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require "xml/libxml"
|
2
|
-
|
3
|
-
class XML::Node
|
4
|
-
##
|
5
|
-
# Open up XML::Node from libxml and add convenience methods inspired
|
6
|
-
# by hpricot.
|
7
|
-
# (http://code.whytheluckystiff.net/hpricot/wiki/HpricotBasics)
|
8
|
-
|
9
|
-
# find the child node with the given xpath
|
10
|
-
def at(xpath)
|
11
|
-
self.find_first(xpath)
|
12
|
-
end
|
13
|
-
|
14
|
-
# find the array of child nodes matching the given xpath
|
15
|
-
def search(xpath)
|
16
|
-
results = self.find(xpath).to_a
|
17
|
-
if block_given?
|
18
|
-
results.each do |result|
|
19
|
-
yield result
|
20
|
-
end
|
21
|
-
end
|
22
|
-
return results
|
23
|
-
end
|
24
|
-
|
25
|
-
# alias for search
|
26
|
-
def /(xpath)
|
27
|
-
search(xpath)
|
28
|
-
end
|
29
|
-
|
30
|
-
# return the inner contents of this node as a string
|
31
|
-
def inner_xml
|
32
|
-
child.to_s
|
33
|
-
end
|
34
|
-
|
35
|
-
# alias for inner_xml
|
36
|
-
def inner_html
|
37
|
-
inner_xml
|
38
|
-
end
|
39
|
-
|
40
|
-
# return this node and its contents as an xml string
|
41
|
-
def to_xml
|
42
|
-
self.to_s
|
43
|
-
end
|
44
|
-
|
45
|
-
# alias for path
|
46
|
-
def xpath
|
47
|
-
self.path
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class String
|
52
|
-
def to_libxml_doc
|
53
|
-
XML::Parser.string(self).parse
|
54
|
-
end
|
55
|
-
end
|