Merge pull request #87 from canadaduane/rubyclean

Change ruby generation to be a little more ruby-esque
This commit is contained in:
Tony Tam 2013-09-02 21:17:15 -07:00
commit 8ad07d069c
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

@ -7,42 +7,31 @@ class {{classname}}
def self.attribute_map def self.attribute_map
{ {
{{#vars}} {{#vars}}
:{{{name}}} => :{{{baseName}}}{{#hasMore}}, {{/hasMore}} :{{{name}}} => :{{{baseName}}}{{#hasMore}},
{{/hasMore}}
{{/vars}}{{newline}} {{/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}} {{#vars}}
if {{classname}}.attribute_map["{{{name}}}".to_sym] != nil if self.class.attribute_map[:"{{{name}}}"]
name = "{{{name}}}".to_sym
value = attributes["{{{baseName}}}"]
{{#isContainer}} {{#isContainer}}
if value.is_a?(Array) if (value = attributes["{{{baseName}}}"]).is_a?(Array)
array = Array.new @{{{name}}} = value{{#complexType}}.map{ |v| {{complexType}}.new(v) }{{/complexType}}
value.each do |arrayValue|
{{#isPrimitiveType}}array.push arrayValue
{{/isPrimitiveType}}
{{#complexType}}array.push {{complexType}}.new(arrayValue)
{{/complexType}}
end end
send("#{name}=", array) if self.respond_to?(name) {{/isContainer}}{{^isContainer}}
end @{{{name}}} = attributes["{{{baseName}}}"]
{{/isContainer}}
{{^isContainer}}
send("#{name}=", value) if self.respond_to?(name)
{{/isContainer}} {{/isContainer}}
end end
{{/vars}} {{/vars}}{{newline}}
end
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