Skip to content

Commit

Permalink
Merge branch 'release-0.1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
meisyal committed Apr 29, 2017
2 parents 206ee87 + f340c24 commit 47874f1
Show file tree
Hide file tree
Showing 6 changed files with 5,948 additions and 88 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Andrias Meisyal
Copyright (c) 2016-2017 Andrias Meisyal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ take a moment to look over the [contributing guidelines][contributing] first.
This extension is released under the terms of MIT License. See the
[LICENSE][license] file for more details.

Copyright © 2016 Andrias Meisyal.
Copyright © 2016-2017 Andrias Meisyal.

[staruml]: http://staruml.io
[umlconcept]:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"homepage": "https://github.com/meisyal/staruml-ruby",
"issues": "https://github.com/meisyal/staruml-ruby/issues",
"keywords": ["ruby"],
"version": "0.1.4",
"version": "0.1.5",
"author": {
"name": "Andrias Meisyal",
"email": "andriasonline@gmail.com",
Expand Down
102 changes: 24 additions & 78 deletions ruby-code-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,18 @@ define(function (require, exports, module) {

codeWriter.writeLine(terms.join('') + ')');
codeWriter.indent();
for (var j = 0; j < len; j++) {
if (!element.attributes[j].isStatic) {
codeWriter.writeLine('@' + element.attributes[j].name + ' = ' +
element.attributes[j].name);
for (var i = 0; i < len; i++) {
if (!element.attributes[i].isStatic) {
codeWriter.writeLine('@' + element.attributes[i].name + ' = ' +
element.attributes[i].name);
}
}

var associations = this.getClassAssociation(codeWriter, element);
if (associations.length) {
for (var k = 0; k < associations.length; k++) {
codeWriter.writeLine('@' + associations[k] + ' = ' +
codeWriter.toCamelCase(associations[k]) + '.new');
for (var i = 0; i < associations.length; i++) {
codeWriter.writeLine('@' + associations[i] + ' = ' +
codeWriter.toCamelCase(associations[i]) + '.new');
}
}

Expand All @@ -193,15 +193,7 @@ define(function (require, exports, module) {
}
};

RubyCodeGenerator.prototype.writeAttributeAccessor = function (type, visibility, codeWriter, element, options) {
if (type === 'short') {
this.writeShortAttributeAccessor(visibility, codeWriter, element, options);
} else if (type === 'long') {
this.writeLongAttributeAccessor(visibility, codeWriter, element);
}
};

RubyCodeGenerator.prototype.writeShortAttributeAccessor = function (visibility, codeWriter, element, options) {
RubyCodeGenerator.prototype.writeAttributeAccessor = function (visibility, codeWriter, element, options) {
var readerAttributeTerms = [];
var accessorAttributeTerms = [];
var len = element.attributes.length;
Expand Down Expand Up @@ -234,59 +226,27 @@ define(function (require, exports, module) {
}
};

RubyCodeGenerator.prototype.writeLongAttributeAccessor = function (visibility, codeWriter, element) {
RubyCodeGenerator.prototype.writeConstant = function (codeWriter, element) {
var len = element.attributes.length;
var attributeVisibility;
var attributeLastIndex;

for (var i = 0; i < len; i++) {
attributeVisibility = this.getVisibility(element.attributes[i]);

if (attributeVisibility === visibility) {
attributeLastIndex = i;
}
}

for (var i = 0; i < len; i++) {
attributeVisibility = this.getVisibility(element.attributes[i]);

if (attributeVisibility === visibility && !element.attributes[i].isStatic) {
this.writeSetterGetterMethod(codeWriter, element.attributes[i]);

if (i !== attributeLastIndex) {
codeWriter.writeLine();
if (element.attributes[i].isReadOnly && element.attributes[i].isStatic) {
codeWriter.writeLine(element.attributes[i].name + ' = ' +
element.attributes[i].defaultValue);
if (this.getVisibility(element.attributes[i]) === 'private') {
codeWriter.writeLine('private_constant :' + element.attributes[i].name);
}
}
}
};

RubyCodeGenerator.prototype.writeSetterGetterMethod = function (codeWriter, attribute) {
codeWriter.writeLine('def ' + attribute.name);
codeWriter.indent();
codeWriter.writeLine('@' + attribute.name);
codeWriter.outdent();
codeWriter.writeLine('end');

if (!attribute.isReadOnly) {
codeWriter.writeLine();
codeWriter.writeLine('def ' + attribute.name + '=(value)');
codeWriter.indent();
codeWriter.writeLine('@' + attribute.name + ' = value');
codeWriter.outdent();
codeWriter.writeLine('end');
}
};

RubyCodeGenerator.prototype.writeConstant = function (codeWriter, element) {
RubyCodeGenerator.prototype.writeClassVariable = function (codeWriter, element) {
var len = element.attributes.length;

for (var i = 0; i < len; i++) {
if (element.attributes[i].isStatic) {
codeWriter.writeLine(element.attributes[i].name + ' = ' +
if (!element.attributes[i].isReadOnly && element.attributes[i].isStatic) {
codeWriter.writeLine('@@' + element.attributes[i].name + ' = ' +
element.attributes[i].defaultValue);
if (this.getVisibility(element.attributes[i]) === 'private') {
codeWriter.writeLine('private_constant :' + element.attributes[i].name);
}
}
}
};
Expand Down Expand Up @@ -347,13 +307,8 @@ define(function (require, exports, module) {
codeWriter.writeLine('protected');
codeWriter.indent();
if (protectedAttributeLength) {
if (options.useAttributeAccessor) {
this.writeAttributeAccessor('short', 'protected', codeWriter, element, options);
codeWriter.writeLine();
} else if (!options.useAttributeAccessor) {
this.writeAttributeAccessor('long', 'protected', codeWriter, element, options);
codeWriter.writeLine();
}
this.writeAttributeAccessor('protected', codeWriter, element, options);
codeWriter.writeLine();
}

codeWriter.outdent();
Expand All @@ -371,13 +326,8 @@ define(function (require, exports, module) {
codeWriter.writeLine('private');
codeWriter.indent();
if (privateAttributeLength) {
if (options.useAttributeAccessor) {
this.writeAttributeAccessor('short', 'private', codeWriter, element, options);
codeWriter.writeLine();
} else if (!options.useAttributeAccessor) {
this.writeAttributeAccessor('long', 'private', codeWriter, element, options);
codeWriter.writeLine();
}
this.writeAttributeAccessor('private', codeWriter, element, options);
codeWriter.writeLine();
}

codeWriter.outdent();
Expand Down Expand Up @@ -525,15 +475,16 @@ define(function (require, exports, module) {

var attributeCount = this.countAttributeByVisibility(element);
var publicAttributeLength = attributeCount[0];
if (options.useAttributeAccessor && publicAttributeLength) {
this.writeAttributeAccessor('short', 'public', codeWriter, element, options);
if (publicAttributeLength) {
this.writeAttributeAccessor('public', codeWriter, element, options);
if (!staticAttributeCount) {
codeWriter.writeLine();
}
}

if (staticAttributeCount) {
this.writeConstant(codeWriter, element);
this.writeClassVariable(codeWriter, element);
codeWriter.writeLine();
}

Expand All @@ -542,11 +493,6 @@ define(function (require, exports, module) {
codeWriter.writeLine();
}

if (!options.useAttributeAccessor && publicAttributeLength) {
this.writeAttributeAccessor('long', 'public', codeWriter, element, options);
codeWriter.writeLine();
}

codeWriter.outdent();
this.writeMethodByVisibility(codeWriter, element, options);

Expand Down
7 changes: 0 additions & 7 deletions ruby-preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ define(function (require, exports, module) {
type: 'Check',
default: true,
},
'ruby.gen.useAttributeAccessor': {
text: 'Attribute accessor',
description: 'Use shortcut for attribute accessors (writer and reader).',
type: 'Check',
default: false,
},
'ruby.gen.toStringMethod': {
text: 'The to_s method',
description: 'Generate to_s method that returns a string representation of the object.',
Expand All @@ -59,7 +53,6 @@ define(function (require, exports, module) {
useTab: PreferenceManager.get('ruby.gen.useTab'),
indentSpaces: PreferenceManager.get('ruby.gen.indentSpaces'),
initializeMethod: PreferenceManager.get('ruby.gen.initializeMethod'),
useAttributeAccessor: PreferenceManager.get('ruby.gen.useAttributeAccessor'),
rubyToStringMethod: PreferenceManager.get('ruby.gen.toStringMethod'),
documentation: PreferenceManager.get('ruby.gen.documentation'),
};
Expand Down
Loading

0 comments on commit 47874f1

Please sign in to comment.