Skip to content

Commit 0a4d28e

Browse files
committed
Fix empty method names in output for Ruby
This fixes the output of the Ruby MaD models when the method name is empty which can happen when the model applies to a type rather than to a method.
1 parent 0195607 commit 0a4d28e

File tree

1 file changed

+26
-6
lines changed
  • extensions/ql-vscode/src/model-editor/languages/ruby

1 file changed

+26
-6
lines changed

extensions/ql-vscode/src/model-editor/languages/ruby/index.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ function rubyMethodSignature(typeName: string, methodName: string) {
2929
return `${typeName}#${methodName}`;
3030
}
3131

32+
function rubyMethodPath(methodName: string) {
33+
if (methodName === "") {
34+
return "";
35+
}
36+
37+
return `Method[${methodName}]`;
38+
}
39+
40+
function rubyPath(methodName: string, path: string) {
41+
const methodPath = rubyMethodPath(methodName);
42+
if (methodPath === "") {
43+
return path;
44+
}
45+
46+
return `${methodPath}.${path}`;
47+
}
48+
3249
export const ruby: ModelsAsDataLanguage = {
3350
availableModes: [Mode.Framework],
3451
createMethodSignature: ({ typeName, methodName }) =>
@@ -42,7 +59,7 @@ export const ruby: ModelsAsDataLanguage = {
4259
// );
4360
generateMethodDefinition: (method) => [
4461
method.typeName,
45-
`Method[${method.methodName}].${method.output}`,
62+
rubyPath(method.methodName, method.output),
4663
method.kind,
4764
],
4865
readModeledMethod: (row) => {
@@ -71,8 +88,11 @@ export const ruby: ModelsAsDataLanguage = {
7188
// string type, string path, string kind
7289
// );
7390
generateMethodDefinition: (method) => {
74-
const path = `Method[${method.methodName}].${method.input}`;
75-
return [method.typeName, path, method.kind];
91+
return [
92+
method.typeName,
93+
rubyPath(method.methodName, method.input),
94+
method.kind,
95+
];
7696
},
7797
readModeledMethod: (row) => {
7898
const typeName = row[0] as string;
@@ -101,7 +121,7 @@ export const ruby: ModelsAsDataLanguage = {
101121
// );
102122
generateMethodDefinition: (method) => [
103123
method.typeName,
104-
`Method[${method.methodName}]`,
124+
rubyMethodPath(method.methodName),
105125
method.input,
106126
method.output,
107127
method.kind,
@@ -131,7 +151,7 @@ export const ruby: ModelsAsDataLanguage = {
131151
// );
132152
generateMethodDefinition: (method) => [
133153
method.typeName,
134-
`Method[${method.methodName}]`,
154+
rubyMethodPath(method.methodName),
135155
method.kind,
136156
],
137157
readModeledMethod: (row) => {
@@ -157,7 +177,7 @@ export const ruby: ModelsAsDataLanguage = {
157177
generateMethodDefinition: (method) => [
158178
method.relatedTypeName,
159179
method.typeName,
160-
`Method[${method.methodName}].${method.path}`,
180+
rubyPath(method.methodName, method.path),
161181
],
162182
readModeledMethod: (row) => {
163183
const typeName = row[1] as string;

0 commit comments

Comments
 (0)