happymapper 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.1.7 2009-01-29
2
+ * 1 minor enhancement
3
+ * Support dashes in elements (Josh Nichols)
4
+
1
5
  == 0.1.6 2009-01-17
2
6
  * 1 minor enhancement:
3
7
  * added support for nested collection elements (Justin Marney)
data/Manifest CHANGED
@@ -1,7 +1,9 @@
1
1
  examples/amazon.rb
2
2
  examples/current_weather.rb
3
+ examples/dashed_elements.rb
3
4
  examples/post.rb
4
5
  examples/twitter.rb
6
+ happymapper.gemspec
5
7
  History
6
8
  lib/happymapper/attribute.rb
7
9
  lib/happymapper/element.rb
@@ -14,6 +16,7 @@ Manifest
14
16
  Rakefile
15
17
  README
16
18
  spec/fixtures/address.xml
19
+ spec/fixtures/commit.xml
17
20
  spec/fixtures/current_weather.xml
18
21
  spec/fixtures/pita.xml
19
22
  spec/fixtures/posts.xml
data/TODO CHANGED
@@ -1,2 +1 @@
1
- * doesn't do xml namespaces really (does work with default namespace though)
2
- * switch gem management to echoe as i did with httparty
1
+ * doesn't do xml namespaces really (does work with default namespace though)
@@ -0,0 +1,23 @@
1
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require File.join(dir, 'happymapper')
3
+
4
+ file_contents = File.read(dir + '/../spec/fixtures/commit.xml')
5
+
6
+ module GitHub
7
+ class Commit
8
+ include HappyMapper
9
+
10
+ tag "commit"
11
+
12
+ element :url, String
13
+ element :tree, String
14
+ element :message, String
15
+ element :id, String
16
+ element :'committed-date', Date
17
+ end
18
+ end
19
+
20
+ commits = GitHub::Commit.parse(file_contents)
21
+ commits.each do |commit|
22
+ puts commit.committed_date, commit.url, commit.id
23
+ end
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{happymapper}
5
- s.version = "0.1.6"
5
+ s.version = "0.1.7"
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
- s.date = %q{2009-01-17}
9
+ s.date = %q{2009-01-28}
10
10
  s.description = %q{object to xml mapping library}
11
11
  s.email = %q{nunemaker@gmail.com}
12
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/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/current_weather.xml", "spec/fixtures/pita.xml", "spec/fixtures/posts.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"]
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", "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/pita.xml", "spec/fixtures/posts.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!}
@@ -99,13 +99,15 @@ module HappyMapper
99
99
  def create_collection(nodes, namespace=nil)
100
100
  nodes.inject([]) do |acc, el|
101
101
  obj = new
102
- attributes.each { |attr| obj.send("#{attr.name}=", attr.from_xml_node(el)) }
103
- elements.each { |elem| obj.send("#{elem.name}=", elem.from_xml_node(el, namespace)) }
102
+ attributes.each { |attr| obj.send("#{normalize_name attr.name}=", attr.from_xml_node(el)) }
103
+ elements.each { |elem| obj.send("#{normalize_name elem.name}=", elem.from_xml_node(el, namespace)) }
104
104
  acc << obj
105
105
  end
106
106
  end
107
107
 
108
108
  def create_getter(name)
109
+ name = normalize_name(name)
110
+
109
111
  class_eval <<-EOS, __FILE__, __LINE__
110
112
  def #{name}
111
113
  @#{name}
@@ -114,6 +116,8 @@ module HappyMapper
114
116
  end
115
117
 
116
118
  def create_setter(name)
119
+ name = normalize_name(name)
120
+
117
121
  class_eval <<-EOS, __FILE__, __LINE__
118
122
  def #{name}=(value)
119
123
  @#{name} = value
@@ -122,9 +126,15 @@ module HappyMapper
122
126
  end
123
127
 
124
128
  def create_accessor(name)
129
+ name = normalize_name(name)
130
+
125
131
  create_getter(name)
126
132
  create_setter(name)
127
133
  end
134
+
135
+ def normalize_name(name)
136
+ name.gsub('-', '_')
137
+ end
128
138
  end
129
139
  end
130
140
 
@@ -1,3 +1,3 @@
1
1
  module HappyMapper
2
- Version = '0.1.6'
2
+ Version = '0.1.7'
3
3
  end
@@ -0,0 +1,52 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <commit>
3
+ <removed type="array">
4
+ <removed>
5
+ <filename>commands.rb</filename>
6
+ </removed>
7
+ <removed>
8
+ <filename>helpers.rb</filename>
9
+ </removed>
10
+ </removed>
11
+ <added type="array">
12
+ <added>
13
+ <filename>commands/commands.rb</filename>
14
+ </added>
15
+ <added>
16
+ <filename>commands/helpers.rb</filename>
17
+ </added>
18
+ </added>
19
+ <message>move commands.rb and helpers.rb into commands/ dir</message>
20
+ <modified type="array">
21
+ <modified>
22
+ <diff>@@ -56,7 +56,7 @@ module GitHub
23
+ end
24
+
25
+ def load(file)
26
+ - file[0] == ?/ ? super : super(BasePath + "/#{file}")
27
+ + file[0] == ?/ ? super : super(BasePath + "/commands/#{file}")
28
+ end
29
+
30
+ def debug(*messages)</diff>
31
+ <filename>lib/github.rb</filename>
32
+ </modified>
33
+ </modified>
34
+ <parents type="array">
35
+ <parent>
36
+ <id>d462d2a2e60438ded3dd9e8e6593ca4146c5a0ba</id>
37
+ </parent>
38
+ </parents>
39
+ <url>http://github.com/defunkt/github-gem/commit/c26d4ce9807ecf57d3f9eefe19ae64e75bcaaa8b</url>
40
+ <author>
41
+ <name>Chris Wanstrath</name>
42
+ <email>chris@ozmm.org</email>
43
+ </author>
44
+ <id>c26d4ce9807ecf57d3f9eefe19ae64e75bcaaa8b</id>
45
+ <committed-date>2008-03-02T16:45:41-08:00</committed-date>
46
+ <authored-date>2008-03-02T16:45:41-08:00</authored-date>
47
+ <tree>28a1a1ca3e663d35ba8bf07d3f1781af71359b76</tree>
48
+ <committer>
49
+ <name>Chris Wanstrath</name>
50
+ <email>chris@ozmm.org</email>
51
+ </committer>
52
+ </commit>
@@ -20,4 +20,4 @@
20
20
  <post href="http://codeclimber.blogspot.com/2008/06/using-ruby-for-imap-with-gmail.html" hash="33bbf2492beac5fbf1fc167014060067" description="CodeClimber: using Ruby for IMAP with Gmail" tag="email gems gmail google imap rails railstips ruby" time="2008-07-05T20:06:47Z" others="118" extended="how to check gmail using ruby's IMAP libraries. the key is to use the login method instead of the authenticate one."/>
21
21
  <post href="http://xullicious.blogspot.com/2008/07/updated-curb-multi-interface-patch.html" hash="f95dcc012bdc13bc26bace3ceed10656" description="Xul for thought: Updated curb multi interface patch" tag="curl ruby http" time="2008-07-03T21:52:45Z" others="1" extended="Really cool multi curl stuff to rapidly hit urls."/>
22
22
  </posts>
23
- <!-- fe04.api.del.ac4.yahoo.net uncompressed/chunked Sat Aug 9 00:20:11 PDT 2008 -->
23
+ <!-- fe04.api.del.ac4.yahoo.net uncompressed/chunked Sat Aug 9 00:20:11 PDT 2008 -->
@@ -89,6 +89,20 @@ module PITA
89
89
  end
90
90
  end
91
91
 
92
+ module GitHub
93
+ class Commit
94
+ include HappyMapper
95
+
96
+ tag "commit"
97
+
98
+ element :url, String
99
+ element :tree, String
100
+ element :message, String
101
+ element :id, String
102
+ element :'committed-date', Date
103
+ end
104
+ end
105
+
92
106
  describe HappyMapper do
93
107
 
94
108
  describe "being included into another class" do
@@ -112,6 +126,12 @@ describe HappyMapper do
112
126
  }.should change(Foo, :attributes)
113
127
  end
114
128
 
129
+ it "should allow adding an attribute containing a dash" do
130
+ lambda {
131
+ Foo.attribute :'bar-baz', String
132
+ }.should change(Foo, :attributes)
133
+ end
134
+
115
135
  it "should be able to get all attributes in array" do
116
136
  Foo.attribute :name, String
117
137
  Foo.attributes.size.should == 1
@@ -122,6 +142,13 @@ describe HappyMapper do
122
142
  Foo.element :name, String
123
143
  }.should change(Foo, :elements)
124
144
  end
145
+
146
+ it "should allow adding an element containing a dash" do
147
+ lambda {
148
+ Foo.element :'bar-baz', String
149
+ }.should change(Foo, :elements)
150
+
151
+ end
125
152
 
126
153
  it "should be able to get all elements in array" do
127
154
  Foo.element(:name, String)
@@ -291,4 +318,20 @@ describe HappyMapper do
291
318
  @third.places[1].name.should == 'Home'
292
319
  end
293
320
  end
294
- end
321
+
322
+ describe "#parse (with xml that has elements with dashes in them)" do
323
+ before do
324
+ file_contents = File.read(File.dirname(__FILE__) + '/fixtures/commit.xml')
325
+ @commit = GitHub::Commit.parse(file_contents).first
326
+ end
327
+
328
+ it "should properly create objects" do
329
+ @commit.message.should == "move commands.rb and helpers.rb into commands/ dir"
330
+ @commit.url.should == "http://github.com/defunkt/github-gem/commit/c26d4ce9807ecf57d3f9eefe19ae64e75bcaaa8b"
331
+ @commit.id.should == "c26d4ce9807ecf57d3f9eefe19ae64e75bcaaa8b"
332
+ @commit.committed_date.should == Date.parse("2008-03-02T16:45:41-08:00")
333
+ @commit.tree.should == "28a1a1ca3e663d35ba8bf07d3f1781af71359b76"
334
+ end
335
+
336
+ end
337
+ end
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.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-17 00:00:00 -05:00
12
+ date: 2009-01-28 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -50,8 +50,10 @@ extra_rdoc_files:
50
50
  files:
51
51
  - examples/amazon.rb
52
52
  - examples/current_weather.rb
53
+ - examples/dashed_elements.rb
53
54
  - examples/post.rb
54
55
  - examples/twitter.rb
56
+ - happymapper.gemspec
55
57
  - History
56
58
  - lib/happymapper/attribute.rb
57
59
  - lib/happymapper/element.rb
@@ -64,6 +66,7 @@ files:
64
66
  - Rakefile
65
67
  - README
66
68
  - spec/fixtures/address.xml
69
+ - spec/fixtures/commit.xml
67
70
  - spec/fixtures/current_weather.xml
68
71
  - spec/fixtures/pita.xml
69
72
  - spec/fixtures/posts.xml
@@ -78,7 +81,6 @@ files:
78
81
  - TODO
79
82
  - website/css/common.css
80
83
  - website/index.html
81
- - happymapper.gemspec
82
84
  has_rdoc: true
83
85
  homepage: http://happymapper.rubyforge.org
84
86
  post_install_message: May you have many happy mappings!