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
47
48
|
# File 'lib/roundtrip_xml/utils.rb', line 17
def new_roxml_class(name, parent = Object, &block)
Class.new(parent) do
include ROXML
include PlainAccessors
xml_convention :dasherize
xml_name name
def attributes
self.class.roxml_attrs
end
def self.class_name
name_to_sym_helper self.tag_name
end
def to_hash
attributes.inject({}) do |hash, a|
value = a.to_ref(self).to_xml(self)
value = value.to_hash if value.respond_to? :to_hash
hash[a.accessor] = value
hash
end
end
def self.unique_parent_accessors
plain = Set.new(plain_accessors.map {|accessor| accessor.to_s.gsub(VAR_SUFIX, '').to_sym})
parent_accessors = Set.new(roxml_attrs.map { |attr| attr.accessor })
parent_accessors - plain
end
class_eval &block if block_given?
end
end
|