MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / resolveModel

Function resolveModel

src/resolution/frameworks/ruby.ts:401–429  ·  view source on GitHub ↗
(name: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

399}
400
401function resolveModel(name: string, context: ResolutionContext): string | null {
402 // Try direct file path lookup first (Rails convention: CamelCase -> snake_case.rb)
403 const snakeName = name.replace(/([A-Z])/g, '_$1').toLowerCase().slice(1);
404 const possiblePaths = [
405 `app/models/${snakeName}.rb`,
406 `app/models/concerns/${snakeName}.rb`,
407 ];
408
409 for (const modelPath of possiblePaths) {
410 if (context.fileExists(modelPath)) {
411 const nodes = context.getNodesInFile(modelPath);
412 const modelNode = nodes.find(
413 (n) => n.kind === 'class' && n.name === name
414 );
415 if (modelNode) {
416 return modelNode.id;
417 }
418 }
419 }
420
421 // Fall back to name-based lookup
422 const candidates = context.getNodesByName(name);
423 const modelNode = candidates.find(
424 (n) => n.kind === 'class' && n.filePath.includes('app/models/')
425 );
426 if (modelNode) return modelNode.id;
427
428 return null;
429}
430
431function resolveController(name: string, context: ResolutionContext): string | null {
432 // Try direct file path lookup first

Callers 1

resolveFunction · 0.85

Calls 3

fileExistsMethod · 0.80
getNodesInFileMethod · 0.65
getNodesByNameMethod · 0.65

Tested by

no test coverage detected