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}}
# 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
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}}
# :internal => :external
def self.attribute_map
{
{
{{#vars}}
:{{{name}}} => :{{{baseName}}}{{#hasMore}}, {{/hasMore}}
{{/vars}}{{newline}}
}
:{{{name}}} => :{{{baseName}}}{{#hasMore}},
{{/hasMore}}
{{/vars}}{{newline}}
}
end
def initialize(attributes = {})
return if attributes.empty?
# 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}}
{{#vars}}
if self.class.attribute_map[:"{{{name}}}"]
{{#isContainer}}
if (value = attributes["{{{baseName}}}"]).is_a?(Array)
@{{{name}}} = value{{#complexType}}.map{ |v| {{complexType}}.new(v) }{{/complexType}}
end
{{/isContainer}}{{^isContainer}}
@{{{name}}} = attributes["{{{baseName}}}"]
{{/isContainer}}
end
{{/vars}}{{newline}}
end
def to_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?
end
body