Class: Ontrac::WebServices::Definitions::Base
- Inherits:
-
Object
- Object
- Ontrac::WebServices::Definitions::Base
show all
- Includes:
- Nokogiri
- Defined in:
- lib/ontrac/web_services/definitions/base.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.attr_accessor(*args) ⇒ Object
8
9
10
11
|
# File 'lib/ontrac/web_services/definitions/base.rb', line 8
def self.attr_accessor(*args)
(@attributes ||= []).concat(args)
super
end
|
.attributes ⇒ Object
13
14
15
|
# File 'lib/ontrac/web_services/definitions/base.rb', line 13
def self.attributes
return (@attributes ||= [])
end
|
.basename ⇒ Object
17
18
19
|
# File 'lib/ontrac/web_services/definitions/base.rb', line 17
def self.basename
ActiveSupport::Inflector.camelize(self.name.gsub(/^.*::/, ''))
end
|
Instance Method Details
#to_xml ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/ontrac/web_services/definitions/base.rb', line 21
def to_xml
xml_builder = Nokogiri::XML::Builder.new
xml_builder.send(self.class.basename) do |xml|
self.class.attributes.each do |attribute_name|
(values = *self.send(attribute_name)).each do |attribute_value|
xml_attr_name = respond_to?("#{attribute_name}_to_xml_name") ?
send("#{attribute_name}_to_xml_name") :
ActiveSupport::Inflector.camelize(attribute_name, false)
if (attribute_value.is_a?(Base))
xml.doc.root << attribute_value.to_xml
else
xml.send(xml_attr_name, attribute_value)
end
end
end
end
xml_builder.doc.root
end
|