Class: RailsAiBridge::ViewFileAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/view_file_analyzer.rb

Overview

Extracts edit-focused metadata from a single view file.

Class Method Summary collapse

Class Method Details

.call(root:, relative_path:, app: nil) ⇒ Hash

Reads a single view file under app/views and extracts editing hints.

Parameters:

  • root (String, Pathname)

    Rails root path

  • app (Rails::Application, nil) (defaults to: nil)

    optional app used to resolve configured +app/views+ paths

  • relative_path (String)

    path relative to app/views

Returns:

  • (Hash)

    normalized metadata for the requested view file

Raises:

  • (SecurityError)

    when the path escapes app/views

  • (Errno::ENOENT)

    when the file does not exist



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rails_ai_bridge/view_file_analyzer.rb', line 15

def call(root:, relative_path:, app: nil)
  context = ViewContext.new(root:, app:)
  view_file = resolve_view_file(context, relative_path)
  relative = view_file.relative_path

  content = File.read(view_file.path)

  {
    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