Skip to content

Commit d0a1275

Browse files
authored
Merge pull request #3216 from github/koesie10/move-ruby-access-paths
Move Ruby access paths functions to separate file
2 parents 1b73767 + ac745a6 commit d0a1275

File tree

2 files changed

+48
-42
lines changed

2 files changed

+48
-42
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export function parseRubyMethodFromPath(path: string): string {
2+
const match = path.match(/Method\[([^\]]+)].*/);
3+
if (match) {
4+
return match[1];
5+
} else {
6+
return "";
7+
}
8+
}
9+
10+
export function parseRubyAccessPath(path: string): {
11+
methodName: string;
12+
path: string;
13+
} {
14+
const match = path.match(/Method\[([^\]]+)]\.(.*)/);
15+
if (match) {
16+
return { methodName: match[1], path: match[2] };
17+
} else {
18+
return { methodName: "", path: "" };
19+
}
20+
}
21+
22+
export function rubyMethodSignature(typeName: string, methodName: string) {
23+
return `${typeName}#${methodName}`;
24+
}
25+
26+
export function rubyMethodPath(methodName: string) {
27+
if (methodName === "") {
28+
return "";
29+
}
30+
31+
return `Method[${methodName}]`;
32+
}
33+
34+
export function rubyPath(methodName: string, path: string) {
35+
const methodPath = rubyMethodPath(methodName);
36+
if (methodPath === "") {
37+
return path;
38+
}
39+
40+
return `${methodPath}.${path}`;
41+
}

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

+7-42
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,13 @@ import { Mode } from "../../shared/mode";
44
import { parseGenerateModelResults } from "./generate";
55
import type { MethodArgument } from "../../method";
66
import { getArgumentsList } from "../../method";
7-
8-
function parseRubyMethodFromPath(path: string): string {
9-
const match = path.match(/Method\[([^\]]+)].*/);
10-
if (match) {
11-
return match[1];
12-
} else {
13-
return "";
14-
}
15-
}
16-
17-
function parseRubyAccessPath(path: string): {
18-
methodName: string;
19-
path: string;
20-
} {
21-
const match = path.match(/Method\[([^\]]+)]\.(.*)/);
22-
if (match) {
23-
return { methodName: match[1], path: match[2] };
24-
} else {
25-
return { methodName: "", path: "" };
26-
}
27-
}
28-
29-
function rubyMethodSignature(typeName: string, methodName: string) {
30-
return `${typeName}#${methodName}`;
31-
}
32-
33-
function rubyMethodPath(methodName: string) {
34-
if (methodName === "") {
35-
return "";
36-
}
37-
38-
return `Method[${methodName}]`;
39-
}
40-
41-
function rubyPath(methodName: string, path: string) {
42-
const methodPath = rubyMethodPath(methodName);
43-
if (methodPath === "") {
44-
return path;
45-
}
46-
47-
return `${methodPath}.${path}`;
48-
}
7+
import {
8+
parseRubyAccessPath,
9+
parseRubyMethodFromPath,
10+
rubyMethodPath,
11+
rubyMethodSignature,
12+
rubyPath,
13+
} from "./access-paths";
4914

5015
export const ruby: ModelsAsDataLanguage = {
5116
availableModes: [Mode.Framework],

0 commit comments

Comments
 (0)