peanuts 2.1.1 → 2.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -3
- data/lib/peanuts.rb +2 -0
- data/lib/peanuts/converters.rb +2 -0
- data/lib/peanuts/mappable.rb +2 -0
- data/lib/peanuts/mapper.rb +2 -0
- data/lib/peanuts/mappings.rb +2 -0
- data/lib/peanuts/xml.rb +2 -0
- data/lib/peanuts/xml/libxml.rb +14 -2
- data/spec/cat_spec.rb +41 -37
- metadata +30 -16
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'rake'
|
|
5
5
|
require 'rake/clean'
|
6
6
|
require 'rake/gempackagetask'
|
7
7
|
require 'rake/rdoctask'
|
8
|
-
require '
|
8
|
+
require 'rspec/core/rake_task'
|
9
9
|
|
10
10
|
Rake::GemPackageTask.new(Gem::Specification.load('peanuts.gemspec')) do |p|
|
11
11
|
p.need_tar = true
|
@@ -24,6 +24,6 @@ end
|
|
24
24
|
desc 'Run specs'
|
25
25
|
task :test => :spec
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
Rspec::Core::RakeTask.new do |t|
|
28
|
+
|
29
29
|
end
|
data/lib/peanuts.rb
CHANGED
data/lib/peanuts/converters.rb
CHANGED
data/lib/peanuts/mappable.rb
CHANGED
data/lib/peanuts/mapper.rb
CHANGED
data/lib/peanuts/mappings.rb
CHANGED
data/lib/peanuts/xml.rb
CHANGED
data/lib/peanuts/xml/libxml.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'libxml'
|
2
4
|
require 'forwardable'
|
3
5
|
require 'uri'
|
@@ -153,9 +155,9 @@ module Peanuts
|
|
153
155
|
def value
|
154
156
|
case @reader.node_type
|
155
157
|
when RD::TYPE_ELEMENT
|
156
|
-
@reader.read_string
|
158
|
+
_string(@reader.read_string)
|
157
159
|
else
|
158
|
-
@reader.has_value? ? @reader.value : nil
|
160
|
+
@reader.has_value? ? _string(@reader.value) : nil
|
159
161
|
end
|
160
162
|
end
|
161
163
|
|
@@ -177,6 +179,16 @@ module Peanuts
|
|
177
179
|
end
|
178
180
|
|
179
181
|
private
|
182
|
+
if ''.respond_to?(:force_encoding)
|
183
|
+
def _string(v)
|
184
|
+
v.force_encoding(Encoding::UTF_8)
|
185
|
+
end
|
186
|
+
else
|
187
|
+
def _string(v)
|
188
|
+
v
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
180
192
|
def read
|
181
193
|
case @reader.node_type
|
182
194
|
when RD::TYPE_ATTRIBUTE
|
data/spec/cat_spec.rb
CHANGED
@@ -1,56 +1,59 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
4
|
|
3
5
|
require 'bigdecimal'
|
4
|
-
require 'test/unit'
|
5
6
|
require 'rubygems'
|
6
7
|
require 'peanuts'
|
8
|
+
require 'rspec'
|
7
9
|
|
10
|
+
module Caturday
|
11
|
+
class Cheezburger
|
12
|
+
include Peanuts::MappableObject
|
8
13
|
|
9
|
-
|
10
|
-
|
14
|
+
attribute :weight, :float
|
15
|
+
attribute :price, :decimal
|
11
16
|
|
12
|
-
|
13
|
-
|
17
|
+
def initialize(weight = nil, price = nil)
|
18
|
+
@weight, @price = weight, price
|
19
|
+
end
|
14
20
|
|
15
|
-
|
16
|
-
|
17
|
-
|
21
|
+
def eql?(other)
|
22
|
+
other && weight == other.weight && price == other.price
|
23
|
+
end
|
18
24
|
|
19
|
-
|
20
|
-
other && weight == other.weight && price == other.price
|
25
|
+
alias == eql?
|
21
26
|
end
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
class Paws
|
27
|
-
include Peanuts::MappableObject
|
28
|
+
class Paws
|
29
|
+
include Peanuts::MappableObject
|
28
30
|
|
29
|
-
|
30
|
-
end
|
31
|
+
elements :paws, :name => :paw, :ns => 'urn:x-lol'
|
32
|
+
end
|
31
33
|
|
32
|
-
class Cat
|
33
|
-
|
34
|
+
class Cat
|
35
|
+
include Peanuts::MappableObject
|
34
36
|
|
35
|
-
|
37
|
+
namespaces :lol => 'urn:x-lol', :kthnx => 'urn:x-lol:kthnx'
|
36
38
|
|
37
|
-
|
39
|
+
root 'kitteh', :ns => 'urn:x-lol'
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
+
attribute :has_tail?, :boolean, :name => 'has-tail', :ns => :kthnx
|
42
|
+
attribute :ears, :integer
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
+
element :ration, [:string], :name => :eats, :ns => :kthnx
|
45
|
+
element :name, :ns => 'urn:x-lol:kthnx'
|
44
46
|
|
45
|
-
|
47
|
+
shallow :paws, Paws
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
-
|
49
|
+
shallow :pals, :ns => :kthnx do
|
50
|
+
elements :friends, :name => :pal
|
51
|
+
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
element :cheezburger, Caturday::Cheezburger
|
54
|
+
element :moar_cheezburgers do
|
55
|
+
elements :cheezburger, Caturday::Cheezburger
|
56
|
+
end
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
@@ -80,13 +83,13 @@ shared_examples_for 'my cat' do
|
|
80
83
|
end
|
81
84
|
|
82
85
|
it 'should has cheezburger' do
|
83
|
-
@cat.cheezburger.should be_kind_of Cheezburger
|
86
|
+
@cat.cheezburger.should be_kind_of Caturday::Cheezburger
|
84
87
|
end
|
85
88
|
|
86
89
|
it 'should has 2 moar good cheezburgerz' do
|
87
90
|
@cat.moar_cheezburgers.cheezburger.should == [
|
88
|
-
Cheezburger.new(685.940, BigDecimal('19')),
|
89
|
-
Cheezburger.new(9356.7, BigDecimal('7.40'))]
|
91
|
+
Caturday::Cheezburger.new(685.940, BigDecimal('19')),
|
92
|
+
Caturday::Cheezburger.new(9356.7, BigDecimal('7.40'))]
|
90
93
|
end
|
91
94
|
end
|
92
95
|
|
@@ -103,6 +106,7 @@ end
|
|
103
106
|
shared_examples_for 'sample kitteh' do
|
104
107
|
before :all do
|
105
108
|
@xml_fragment = <<-EOS
|
109
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
106
110
|
<kitteh xmlns='urn:x-lol' xmlns:kthnx='urn:x-lol:kthnx' ears=' 2 ' kthnx:has-tail=' yes '>
|
107
111
|
<name xmlns='urn:x-lol:kthnx'>
|
108
112
|
Silly
|
@@ -130,7 +134,7 @@ shared_examples_for 'sample kitteh' do
|
|
130
134
|
</moar_cheezburgers>
|
131
135
|
</kitteh>
|
132
136
|
EOS
|
133
|
-
@cat = Cat.from_xml(@xml_fragment)
|
137
|
+
@cat = Caturday::Cat.from_xml(@xml_fragment)
|
134
138
|
@cheezburger = @cat.cheezburger
|
135
139
|
end
|
136
140
|
|
@@ -144,7 +148,7 @@ describe 'My cat' do
|
|
144
148
|
it_should_behave_like 'sample kitteh'
|
145
149
|
|
146
150
|
before :all do
|
147
|
-
@cat = Cat.from_xml(@cat.to_xml)
|
151
|
+
@cat = Caturday::Cat.from_xml(@cat.to_xml)
|
148
152
|
end
|
149
153
|
end
|
150
154
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peanuts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 2
|
7
|
+
- 1
|
8
|
+
- 4
|
9
|
+
version: 2.1.4
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Igor Gunko
|
@@ -9,29 +14,36 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-18 00:00:00 +02:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: libxml-ruby
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
|
-
- -
|
25
|
+
- - ~>
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 1
|
30
|
+
- 3
|
23
31
|
version: 1.1.3
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: rspec
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
|
-
- -
|
39
|
+
- - ~>
|
32
40
|
- !ruby/object:Gem::Version
|
33
|
-
|
34
|
-
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 0
|
44
|
+
version: "2.0"
|
45
|
+
type: :development
|
46
|
+
version_requirements: *id002
|
35
47
|
description: " Peanuts is an XML to Ruby and back again mapping library.\n"
|
36
48
|
email: tekmon@gmail.com
|
37
49
|
executables: []
|
@@ -67,18 +79,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
79
|
requirements:
|
68
80
|
- - ">="
|
69
81
|
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
70
84
|
version: "0"
|
71
|
-
version:
|
72
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
86
|
requirements:
|
74
87
|
- - ">="
|
75
88
|
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
76
91
|
version: "0"
|
77
|
-
version:
|
78
92
|
requirements: []
|
79
93
|
|
80
94
|
rubyforge_project:
|
81
|
-
rubygems_version: 1.3.
|
95
|
+
rubygems_version: 1.3.6
|
82
96
|
signing_key:
|
83
97
|
specification_version: 2
|
84
98
|
summary: Making XML <-> Ruby binding easy
|