Change ruby generation to be a little more ruby-esque

Cleaned up some very long lines, added indentation, and shortened
the repetitive parts of the model mustache template.
This commit is contained in:
Duane Johnson 2013-08-30 17:07:11 -06:00
parent 450b3c7ed5
commit 7d6660d56c
2 changed files with 23 additions and 29 deletions

View File

@ -22,7 +22,12 @@ class {{classname}}
{{/requiredParamCount}} {{/requiredParamCount}}
# set default values and merge with input # set default values and merge with input
options = { {{#allParams}}:{{{paramName}}} => {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}} }.merge(opts) options = {
{{#allParams}}
:{{paramName}} => {{paramName}}{{#hasMore}},
{{/hasMore}}
{{/allParams}}
}.merge(opts)
#resource path #resource path
path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', escapeString({{paramName}})) path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', escapeString({{paramName}}))

View File

@ -5,44 +5,33 @@ class {{classname}}
attr_accessor {{#vars}}:{{{name}}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{newline}} attr_accessor {{#vars}}:{{{name}}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{newline}}
# :internal => :external # :internal => :external
def self.attribute_map def self.attribute_map
{ {
{{#vars}} {{#vars}}
:{{{name}}} => :{{{baseName}}}{{#hasMore}}, {{/hasMore}} :{{{name}}} => :{{{baseName}}}{{#hasMore}},
{{/vars}}{{newline}} {{/hasMore}}
} {{/vars}}{{newline}}
}
end end
def initialize(attributes = {}) def initialize(attributes = {})
return if attributes.empty?
# Morph attribute keys into undescored rubyish style # Morph attribute keys into undescored rubyish style
if attributes.to_s != "" {{#vars}}
if self.class.attribute_map[:"{{{name}}}"]
{{#vars}} {{#isContainer}}
if {{classname}}.attribute_map["{{{name}}}".to_sym] != nil if (value = attributes["{{{baseName}}}"]).is_a?(Array)
name = "{{{name}}}".to_sym @{{{name}}} = value{{#complexType}}.map{ |v| {{complexType}}.new(v) }{{/complexType}}
value = attributes["{{{baseName}}}"] end
{{#isContainer}} {{/isContainer}}{{^isContainer}}
if value.is_a?(Array) @{{{name}}} = attributes["{{{baseName}}}"]
array = Array.new {{/isContainer}}
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
{{/vars}}{{newline}}
end end
def to_body def to_body
body = {} body = {}
{{classname}}.attribute_map.each_pair do |key,value| self.class.attribute_map.each_pair do |key, value|
body[value] = self.send(key) unless self.send(key).nil? body[value] = self.send(key) unless self.send(key).nil?
end end
body body