Skip to content

Commit f596f7e

Browse files
authored
Merge pull request #3117 from github/koesie10/fix-ruby-modules
Add support for models on types for Ruby
2 parents 87e42b4 + 0a4d28e commit f596f7e

File tree

3 files changed

+87
-7
lines changed

3 files changed

+87
-7
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;

extensions/ql-vscode/src/view/model-editor/MethodName.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,27 @@ const Name = styled.span`
77
word-break: break-all;
88
`;
99

10+
const TypeMethodName = (method: Method) => {
11+
if (!method.typeName) {
12+
return <>{method.methodName}</>;
13+
}
14+
15+
if (!method.methodName) {
16+
return <>{method.typeName}</>;
17+
}
18+
19+
return (
20+
<>
21+
{method.typeName}.{method.methodName}
22+
</>
23+
);
24+
};
25+
1026
export const MethodName = (method: Method): JSX.Element => {
1127
return (
1228
<Name>
1329
{method.packageName && <>{method.packageName}.</>}
14-
{method.typeName}.{method.methodName}
30+
<TypeMethodName {...method} />
1531
{method.methodParameters}
1632
</Name>
1733
);

extensions/ql-vscode/src/view/model-editor/__tests__/MethodName.spec.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,48 @@ describe(MethodName.name, () => {
2424
const name = `${method.typeName}.${method.methodName}${method.methodParameters}`;
2525
expect(screen.getByText(name)).toBeInTheDocument();
2626
});
27+
28+
it("renders method name without method name but with parameters", () => {
29+
const method = createMethod({
30+
packageName: "",
31+
methodName: "",
32+
});
33+
render(method);
34+
35+
const name = `${method.typeName}${method.methodParameters}`;
36+
expect(screen.getByText(name)).toBeInTheDocument();
37+
});
38+
39+
it("renders method name without method name and parameters", () => {
40+
const method = createMethod({
41+
packageName: "",
42+
methodName: "",
43+
methodParameters: "",
44+
});
45+
render(method);
46+
47+
const name = `${method.typeName}`;
48+
expect(screen.getByText(name)).toBeInTheDocument();
49+
});
50+
51+
it("renders method name without package and type name", () => {
52+
const method = createMethod({
53+
packageName: "",
54+
typeName: "",
55+
});
56+
render(method);
57+
58+
const name = `${method.methodName}${method.methodParameters}`;
59+
expect(screen.getByText(name)).toBeInTheDocument();
60+
});
61+
62+
it("renders method name without type name", () => {
63+
const method = createMethod({
64+
typeName: "",
65+
});
66+
render(method);
67+
68+
const name = `${method.packageName}.${method.methodName}${method.methodParameters}`;
69+
expect(screen.getByText(name)).toBeInTheDocument();
70+
});
2771
});

0 commit comments

Comments
 (0)