xml_resource 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xml_resource/model.rb +2 -2
- data/lib/xml_resource/version.rb +1 -1
- data/test/data/orders.xml +3 -0
- data/test/models/contact.rb +1 -1
- data/test/models/order.rb +2 -1
- data/test/xml_resource_test.rb +8 -2
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de1ab78fcc96262051a83dcdb86d0ffcefb32c91
|
4
|
+
data.tar.gz: 61e48f997133bc8a877a5185556365b164ad1567
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13ea4d58a8fbed8d619cffd73b46e2ef5db4af97a7653b8b9d717a64cac0909e08f0118d1386ce37d5e09a7e5d89d3bf8247a76fa89dd0ce3676021804e87587
|
7
|
+
data.tar.gz: e3d202e1fa89698f9bf2a851e45d9b2dac3bc06b65752189b889407331155901161ea9221f757d23d8b4fe3082d53add71b607edad5b64e2eeb5a4eb0e2c5228
|
data/lib/xml_resource/model.rb
CHANGED
@@ -132,8 +132,8 @@ module XmlResource
|
|
132
132
|
when :float then value.to_f
|
133
133
|
when :boolean then cast_to_boolean(value)
|
134
134
|
when :decimal then BigDecimal.new(value)
|
135
|
-
when :date then Date.parse(value)
|
136
|
-
when :
|
135
|
+
when :date then value.presence && Date.parse(value)
|
136
|
+
when :time then value.presence && Time.parse(value)
|
137
137
|
else
|
138
138
|
raise XmlResource::TypeCastError, "don't know how to cast #{value.inspect} to #{type}"
|
139
139
|
end
|
data/lib/xml_resource/version.rb
CHANGED
data/test/data/orders.xml
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
<info>
|
6
6
|
<foo type="bar">A</foo>
|
7
7
|
<date>2012-08-27</date>
|
8
|
+
<created_at>2017-06-15 12:00:00</created_at>
|
8
9
|
<foo type="non">sense</foo>
|
9
10
|
</info>
|
10
11
|
<shipping_cost>12.99</shipping_cost>
|
@@ -31,6 +32,7 @@
|
|
31
32
|
<foo type="non">blubb</foo>
|
32
33
|
<foo type="bar">B</foo>
|
33
34
|
<date>2012-08-26</date>
|
35
|
+
<created_at>2017-01-15 12:00:00</created_at>
|
34
36
|
</info>
|
35
37
|
<shipping_cost>10</shipping_cost>
|
36
38
|
<customer>
|
@@ -60,6 +62,7 @@
|
|
60
62
|
<foo type="non">wah</foo>
|
61
63
|
<foo type="bar">C</foo>
|
62
64
|
<date>2012-08-25</date>
|
65
|
+
<created_at></created_at>
|
63
66
|
</info>
|
64
67
|
<shipping_cost>-12.99</shipping_cost>
|
65
68
|
<contact>
|
data/test/models/contact.rb
CHANGED
data/test/models/order.rb
CHANGED
@@ -6,7 +6,8 @@ class Order
|
|
6
6
|
has_attribute :foobar, :xpath => 'info/foo[@type="bar"]'
|
7
7
|
has_attribute :finished, :type => :boolean
|
8
8
|
has_attribute :shipping_cost, :type => :decimal
|
9
|
-
|
9
|
+
has_attribute :created_at, type: :time, xpath: 'info/created_at'
|
10
|
+
|
10
11
|
has_object :customer, :class_name => "Contact"
|
11
12
|
has_object :contact
|
12
13
|
|
data/test/xml_resource_test.rb
CHANGED
@@ -20,7 +20,7 @@ class XmlResourceTest < ActiveSupport::TestCase
|
|
20
20
|
test 'Instantiation of objects' do
|
21
21
|
assert_equal "Mister Spock", @orders.first.customer.name
|
22
22
|
assert_equal "Käptn Kirk", @orders.second.customer.name
|
23
|
-
|
23
|
+
assert_nil @orders.third.customer
|
24
24
|
assert_equal ['E F', 'A B', 'C D'], @orders.map(&:contact).map(&:name)
|
25
25
|
end
|
26
26
|
|
@@ -77,10 +77,16 @@ class XmlResourceTest < ActiveSupport::TestCase
|
|
77
77
|
assert_equal 'foo', gadget.name
|
78
78
|
end
|
79
79
|
assert_raise ArgumentError do
|
80
|
-
|
80
|
+
Gadget.new(nil, magic: 6)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
+
test 'Time attributes are parsed with respect of time zones' do
|
85
|
+
assert_equal Time.parse('2017-06-15 12:00:00 +0200'), @orders[0].created_at
|
86
|
+
assert_equal '2017-01-15 12:00:00 +0100', @orders[1].created_at.to_s
|
87
|
+
assert_nil @orders[2].created_at
|
88
|
+
end
|
89
|
+
|
84
90
|
private
|
85
91
|
|
86
92
|
def load_xml(name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: Create object trees out of XML documents
|
56
70
|
email:
|
57
71
|
- mtgrosser@gmx.net
|
@@ -99,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
113
|
version: '0'
|
100
114
|
requirements: []
|
101
115
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
116
|
+
rubygems_version: 2.6.11
|
103
117
|
signing_key:
|
104
118
|
specification_version: 4
|
105
119
|
summary: Turn XML into Ruby objects
|