ruby.model.mustache Maven / Gradle / Ivy
{{#models}}
{{#model}}
class {{classname}}
attr_accessor {{#vars}}:{{{name}}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{newline}}
# :internal => :external
def self.attribute_map
{
{{#vars}}
:{{{name}}} => :{{{baseName}}}{{#hasMore}}, {{/hasMore}}
{{/vars}}{{newline}}
}
end
def initialize(attributes = {})
# Morph attribute keys into undescored rubyish style
if attributes.to_s != ""
{{#vars}}
if {{classname}}.attribute_map["{{{name}}}".to_sym] != nil
name = "{{{name}}}".to_sym
value = attributes["{{{baseName}}}"]
{{#isContainer}}
if value.is_a?(Array)
array = Array.new
value.each do |arrayValue|
{{#isPrimitiveType}}array.push arrayValue
{{/isPrimitiveType}}
{{#complexType}}array.push {{complexType}}.new(arrayValue)
{{/complexType}}
end
send("#{name}=", array) if self.respond_to?(name)
end
{{/isContainer}}
{{^isContainer}}
send("#{name}=", value) if self.respond_to?(name)
{{/isContainer}}
end
{{/vars}}
end
end
def to_body
body = {}
{{classname}}.attribute_map.each_pair do |key,value|
body[value] = self.send(key) unless self.send(key).nil?
end
body
end
end
{{/model}}
{{/models}}