13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/nomad/stanza/serializer.rb', line 13
def build_proc(obj, key, id = nil)
proc do
add *[key, id].compact do
obj.class.schema.each do |key|
k = key.name
v = obj.attributes[k]
if k == :id or v.nil?
next
elsif v.is_a? Nomad::Stanza::Base
if v.class.has_attribute?(:id)
instance_eval &build_proc(v, k, v.id)
else
instance_eval &build_proc(v, k)
end
elsif v.is_a? Array
member = obj.class.schema.key(k).type.type.member
if member.is_a? Class and member.ancestors.include? Nomad::Stanza::Base
v.each do |i|
if i.class.has_attribute?(:id)
instance_eval &build_proc(i, k, i.id)
else
instance_eval &build_proc(i, k)
end
end
else
add k, v
end
else
add k, v
end
end
end
end
end
|