Class: RailsAiBridge::ViewFileAnalyzer
- Inherits:
-
Object
- Object
- RailsAiBridge::ViewFileAnalyzer
- Defined in:
- lib/rails_ai_bridge/view_file_analyzer.rb
Overview
Extracts edit-focused metadata from a single view file.
Class Method Summary collapse
-
.call(root:, relative_path:) ⇒ Hash
Reads a single view file under
app/viewsand extracts editing hints.
Class Method Details
.call(root:, relative_path:) ⇒ Hash
Reads a single view file under app/views and extracts editing hints.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rails_ai_bridge/view_file_analyzer.rb', line 14 def call(root:, relative_path:) views_root = File.('app/views', root.to_s) requested = File.(relative_path.to_s, views_root) raise SecurityError, "Path not allowed: #{relative_path}" unless requested.start_with?("#{views_root}/") || requested == views_root raise Errno::ENOENT, relative_path unless File.file?(requested) content = File.read(requested) relative = requested.delete_prefix("#{views_root}/") { path: relative, template_engine: File.extname(relative).delete('.'), partial: File.basename(relative).start_with?('_'), renders: extract_renders(content), turbo_frames: extract_turbo_frames(content), stimulus_controllers: extract_stimulus_controllers(content), stimulus_actions: extract_stimulus_actions(content), content: content } end |