Navegador

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

Keyboard Shortcuts

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