xommelier 0.1.14 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/lib/xommelier/version.rb +1 -1
- data/lib/xommelier/xml/element/serialization.rb +20 -4
- data/lib/xommelier/xml/element.rb +1 -1
- data/lib/xommelier/xml/namespace.rb +9 -1
- metadata +3 -9
data/Gemfile
CHANGED
data/lib/xommelier/version.rb
CHANGED
@@ -22,13 +22,17 @@ module Xommelier
|
|
22
22
|
alias_method :parse, :from_xml
|
23
23
|
alias_method :from_xommelier, :from_xml
|
24
24
|
|
25
|
+
def ns_element(ns, element)
|
26
|
+
[ns, element].compact.join(':')
|
27
|
+
end
|
28
|
+
|
25
29
|
def element_xpath(xmldoc = nil, name = nil)
|
26
|
-
|
30
|
+
ns_element(xmlns_xpath(xmldoc), name || element_name)
|
27
31
|
end
|
28
32
|
|
29
33
|
def xmlns_xpath(xml_document = nil)
|
30
34
|
if xml_document
|
31
|
-
prefix = xml_document.namespaces.key(xmlns.uri)
|
35
|
+
prefix = xml_document.namespaces.key(xmlns.try(:uri))
|
32
36
|
(prefix =~ /:/) ? prefix[6..-1] : prefix
|
33
37
|
else
|
34
38
|
xmlns.as
|
@@ -49,7 +53,7 @@ module Xommelier
|
|
49
53
|
end
|
50
54
|
|
51
55
|
self.class.attributes.each do |name, options|
|
52
|
-
|
56
|
+
deserialize_attribute(name, options)
|
53
57
|
end
|
54
58
|
|
55
59
|
self.class.elements.each do |name, options|
|
@@ -130,6 +134,8 @@ module Xommelier
|
|
130
134
|
|
131
135
|
protected
|
132
136
|
|
137
|
+
delegate :ns_element, to: 'self.class'
|
138
|
+
|
133
139
|
def element_xpath(xmldoc = self.xml_document, name = nil)
|
134
140
|
self.class.element_xpath(xmldoc, name)
|
135
141
|
end
|
@@ -160,10 +166,20 @@ module Xommelier
|
|
160
166
|
attributes[name] = value.to_xommelier
|
161
167
|
end
|
162
168
|
|
169
|
+
def deserialize_attribute(name, options = nil)
|
170
|
+
options ||= self.element_options(name)
|
171
|
+
ns = options[:ns]
|
172
|
+
if ns.default? || ns == xmlns
|
173
|
+
send(name, @_xml_node[options[:attribute_name]])
|
174
|
+
else
|
175
|
+
send(name, @_xml_node.attribute_with_ns(options[:attribute_name].to_s, ns.uri.to_s).try(:value))
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
163
179
|
def deserialize_element(name, options = nil)
|
164
180
|
options ||= self.element_options(name)
|
165
181
|
type = options[:type]
|
166
|
-
nodes = @_xml_node.xpath("./#{options[:ns].as
|
182
|
+
nodes = @_xml_node.xpath("./#{ns_element(options[:ns].as, options[:element_name])}", options[:ns].to_hash)
|
167
183
|
if nodes.any?
|
168
184
|
case options[:count]
|
169
185
|
when :any, :many
|
@@ -12,7 +12,7 @@ module Xommelier
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
attr_reader :uri, :options, :
|
15
|
+
attr_reader :uri, :options, :elements, :attributes
|
16
16
|
alias to_s uri
|
17
17
|
|
18
18
|
def initialize(uri, options = {}, &block)
|
@@ -27,6 +27,10 @@ module Xommelier
|
|
27
27
|
scoped(&block) if block_given?
|
28
28
|
end
|
29
29
|
|
30
|
+
def as
|
31
|
+
@as unless default?
|
32
|
+
end
|
33
|
+
|
30
34
|
def ns
|
31
35
|
Xommelier::Xml::Namespace.registry
|
32
36
|
end
|
@@ -69,6 +73,10 @@ module Xommelier
|
|
69
73
|
end
|
70
74
|
end
|
71
75
|
|
76
|
+
def default?
|
77
|
+
uri.to_s == DEFAULT_NS
|
78
|
+
end
|
79
|
+
|
72
80
|
def to_hash
|
73
81
|
{as.to_s => uri.to_s}
|
74
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xommelier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -141,21 +141,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
141
|
- - ! '>='
|
142
142
|
- !ruby/object:Gem::Version
|
143
143
|
version: '0'
|
144
|
-
segments:
|
145
|
-
- 0
|
146
|
-
hash: 4544361787088539035
|
147
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
145
|
none: false
|
149
146
|
requirements:
|
150
147
|
- - ! '>='
|
151
148
|
- !ruby/object:Gem::Version
|
152
149
|
version: '0'
|
153
|
-
segments:
|
154
|
-
- 0
|
155
|
-
hash: 4544361787088539035
|
156
150
|
requirements: []
|
157
151
|
rubyforge_project: xommelier
|
158
|
-
rubygems_version: 1.8.
|
152
|
+
rubygems_version: 1.8.24
|
159
153
|
signing_key:
|
160
154
|
specification_version: 3
|
161
155
|
summary: Xommelier is an XML Sommelier
|