Navegador

navegador / navegador / enrichment / rails.py
Blame History Raw 59 lines
1
"""
2
Rails framework enricher.
3
4
Promotes generic graph nodes to Rails semantic types:
5
- Controller (files under controllers/)
6
- Model (files under models/)
7
- Route (routes.rb)
8
- Job (files under jobs/)
9
- Concern (files under concerns/)
10
"""
11
12
from navegador.enrichment.base import EnrichmentResult, FrameworkEnricher
13
14
15
class RailsEnricher(FrameworkEnricher):
16
"""Enriches a navegador graph with Rails-specific semantics."""
17
18
@property
19
def framework_name(self) -> str:
20
return "rails"
21
22
@property
23
def detection_patterns(self) -> list[str]:
24
return ["rails", "active_record", "action_controller"]
25
26
@property
27
def detection_files(self) -> list[str]:
28
return ["Gemfile"]
29
30
def enrich(self) -> EnrichmentResult:
31
result = EnrichmentResult()
32
33
# Each tuple: (file_path_fragment, semantic_type, pattern_key)
34
promotions = [
35
("controllers/", "RailsController", "controllers"),
36
("models/", "RailsModel", "models"),
37
("routes.rb", "RailsRoute", "routes"),
38
("jobs/", "RailsJob", "jobs"),
39
("concerns/", "RailsConcern", "concerns"),
40
]
41
42
for path_fragment, semantic_type, pattern_key in promotions:
43
query_result = self.store.query(
44
"MATCH (n) WHERE n.file_path IS NOT NULL "
45
"AND n.file_path CONTAINS $fragment "
46
"RETURN n.name, n.file_path",
47
{"fragment": path_fragment},
48
)
49
rows = query_result.result_set or []
50
count = 0
51
for row in rows:
52
name, file_path = row[0], row[1]
53
self._promote_node(name, file_path, semantic_type)
54
count += 1
55
result.promoted += 1
56
result.patterns_found[pattern_key] = count
57
58
return result
59

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button