Merge pull request #3117 from github/koesie10/fix-ruby-modules

Add support for models on types for Ruby
This commit is contained in:
Koen Vlaswinkel
2023-12-08 14:42:23 +01:00
committed by GitHub
3 changed files with 87 additions and 7 deletions

View File

@@ -29,6 +29,23 @@ function rubyMethodSignature(typeName: string, methodName: string) {
return `${typeName}#${methodName}`;
}
function rubyMethodPath(methodName: string) {
if (methodName === "") {
return "";
}
return `Method[${methodName}]`;
}
function rubyPath(methodName: string, path: string) {
const methodPath = rubyMethodPath(methodName);
if (methodPath === "") {
return path;
}
return `${methodPath}.${path}`;
}
export const ruby: ModelsAsDataLanguage = {
availableModes: [Mode.Framework],
createMethodSignature: ({ typeName, methodName }) =>
@@ -42,7 +59,7 @@ export const ruby: ModelsAsDataLanguage = {
// );
generateMethodDefinition: (method) => [
method.typeName,
`Method[${method.methodName}].${method.output}`,
rubyPath(method.methodName, method.output),
method.kind,
],
readModeledMethod: (row) => {
@@ -71,8 +88,11 @@ export const ruby: ModelsAsDataLanguage = {
// string type, string path, string kind
// );
generateMethodDefinition: (method) => {
const path = `Method[${method.methodName}].${method.input}`;
return [method.typeName, path, method.kind];
return [
method.typeName,
rubyPath(method.methodName, method.input),
method.kind,
];
},
readModeledMethod: (row) => {
const typeName = row[0] as string;
@@ -101,7 +121,7 @@ export const ruby: ModelsAsDataLanguage = {
// );
generateMethodDefinition: (method) => [
method.typeName,
`Method[${method.methodName}]`,
rubyMethodPath(method.methodName),
method.input,
method.output,
method.kind,
@@ -131,7 +151,7 @@ export const ruby: ModelsAsDataLanguage = {
// );
generateMethodDefinition: (method) => [
method.typeName,
`Method[${method.methodName}]`,
rubyMethodPath(method.methodName),
method.kind,
],
readModeledMethod: (row) => {
@@ -157,7 +177,7 @@ export const ruby: ModelsAsDataLanguage = {
generateMethodDefinition: (method) => [
method.relatedTypeName,
method.typeName,
`Method[${method.methodName}].${method.path}`,
rubyPath(method.methodName, method.path),
],
readModeledMethod: (row) => {
const typeName = row[1] as string;

View File

@@ -7,11 +7,27 @@ const Name = styled.span`
word-break: break-all;
`;
const TypeMethodName = (method: Method) => {
if (!method.typeName) {
return <>{method.methodName}</>;
}
if (!method.methodName) {
return <>{method.typeName}</>;
}
return (
<>
{method.typeName}.{method.methodName}
</>
);
};
export const MethodName = (method: Method): JSX.Element => {
return (
<Name>
{method.packageName && <>{method.packageName}.</>}
{method.typeName}.{method.methodName}
<TypeMethodName {...method} />
{method.methodParameters}
</Name>
);

View File

@@ -24,4 +24,48 @@ describe(MethodName.name, () => {
const name = `${method.typeName}.${method.methodName}${method.methodParameters}`;
expect(screen.getByText(name)).toBeInTheDocument();
});
it("renders method name without method name but with parameters", () => {
const method = createMethod({
packageName: "",
methodName: "",
});
render(method);
const name = `${method.typeName}${method.methodParameters}`;
expect(screen.getByText(name)).toBeInTheDocument();
});
it("renders method name without method name and parameters", () => {
const method = createMethod({
packageName: "",
methodName: "",
methodParameters: "",
});
render(method);
const name = `${method.typeName}`;
expect(screen.getByText(name)).toBeInTheDocument();
});
it("renders method name without package and type name", () => {
const method = createMethod({
packageName: "",
typeName: "",
});
render(method);
const name = `${method.methodName}${method.methodParameters}`;
expect(screen.getByText(name)).toBeInTheDocument();
});
it("renders method name without type name", () => {
const method = createMethod({
typeName: "",
});
render(method);
const name = `${method.packageName}.${method.methodName}${method.methodParameters}`;
expect(screen.getByText(name)).toBeInTheDocument();
});
});