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 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
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{happymapper}
5
- s.version = "0.2.1"
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", "lib/libxml_ext/libxml_helper.rb", "README", "TODO"]
13
- s.files = ["examples/amazon.rb", "examples/current_weather.rb", "examples/dashed_elements.rb", "examples/post.rb", "examples/twitter.rb", "History", "lib/happymapper/attribute.rb", "lib/happymapper/element.rb", "lib/happymapper/item.rb", "lib/happymapper/version.rb", "lib/happymapper.rb", "lib/libxml_ext/libxml_helper.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", "happymapper.gemspec"]
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!}
@@ -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 get_tag_name
69
- @tag_name ||= begin
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.to_libxml_doc.root
79
+ node = XML::Parser.string(xml).parse.root
85
80
  end
86
81
 
87
- root = node.name == get_tag_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 += get_tag_name
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
@@ -1,3 +1,3 @@
1
1
  module HappyMapper
2
- Version = '0.2.1'
2
+ Version = '0.2.2'
3
3
  end
@@ -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.get_tag_name.should == '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.get_tag_name.should == '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.get_tag_name.should == 'FooBar'
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: happymapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -44,7 +44,6 @@ extra_rdoc_files:
44
44
  - lib/happymapper/item.rb
45
45
  - lib/happymapper/version.rb
46
46
  - lib/happymapper.rb
47
- - lib/libxml_ext/libxml_helper.rb
48
47
  - README
49
48
  - TODO
50
49
  files:
@@ -53,13 +52,13 @@ files:
53
52
  - examples/dashed_elements.rb
54
53
  - examples/post.rb
55
54
  - examples/twitter.rb
55
+ - happymapper.gemspec
56
56
  - History
57
57
  - lib/happymapper/attribute.rb
58
58
  - lib/happymapper/element.rb
59
59
  - lib/happymapper/item.rb
60
60
  - lib/happymapper/version.rb
61
61
  - lib/happymapper.rb
62
- - lib/libxml_ext/libxml_helper.rb
63
62
  - License
64
63
  - Manifest
65
64
  - Rakefile
@@ -85,7 +84,6 @@ files:
85
84
  - TODO
86
85
  - website/css/common.css
87
86
  - website/index.html
88
- - happymapper.gemspec
89
87
  has_rdoc: true
90
88
  homepage: http://happymapper.rubyforge.org
91
89
  post_install_message: May you have many happy mappings!
@@ -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