From 7d6660d56c5334b6cdee7ea7622d7521aeaf5a73 Mon Sep 17 00:00:00 2001 From: Duane Johnson Date: Fri, 30 Aug 2013 17:07:11 -0600 Subject: [PATCH] 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. --- src/main/resources/ruby/api.mustache | 7 +++- src/main/resources/ruby/model.mustache | 45 ++++++++++---------------- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/main/resources/ruby/api.mustache b/src/main/resources/ruby/api.mustache index d623028e5d3..b2c546b011e 100644 --- a/src/main/resources/ruby/api.mustache +++ b/src/main/resources/ruby/api.mustache @@ -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}})) diff --git a/src/main/resources/ruby/model.mustache b/src/main/resources/ruby/model.mustache index 083570fa4b9..5e6739bd46c 100644 --- a/src/main/resources/ruby/model.mustache +++ b/src/main/resources/ruby/model.mustache @@ -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