Module: RailsAiContext::PathResolver

Defined in:
lib/rails_ai_context/path_resolver.rb

Overview

Resolves where a kind of Rails app code can live for a given app root. Conventional layout first, then packwerk packs (packs//app/), then in-repo engines (engines//app/), then any configured extra_app_paths. Only existing directories are returned so callers can glob the list without their own existence guards.

Class Method Summary collapse

Class Method Details

.controller_dirs(root) ⇒ Object



14
# File 'lib/rails_ai_context/path_resolver.rb', line 14

def controller_dirs(root) = dirs_for(root, "app/controllers")

.dirs_for(root, kind) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rails_ai_context/path_resolver.rb', line 18

def dirs_for(root, kind)
  root = root.to_s
  candidates = [ File.join(root, kind) ]
  candidates += Dir.glob(File.join(root, "packs", "*", kind)).sort
  candidates += Dir.glob(File.join(root, "engines", "*", kind)).sort
  Array(RailsAiContext.configuration.extra_app_paths).each do |extra|
    candidates << File.join(root, extra, kind)
    # `custom/app` is the natural way to write an entry whose tree is
    # custom/app/models; appending the full kind would look in
    # custom/app/app/models and silently miss. Accept both spellings.
    if extra.to_s.chomp("/").end_with?("/app") || extra.to_s.chomp("/") == "app"
      candidates << File.join(root, extra, kind.delete_prefix("app/"))
    end
  end
  candidates.uniq.select { |dir| Dir.exist?(dir) }
end

.model_dirs(root) ⇒ Object



12
# File 'lib/rails_ai_context/path_resolver.rb', line 12

def model_dirs(root) = dirs_for(root, "app/models")

.view_dirs(root) ⇒ Object



16
# File 'lib/rails_ai_context/path_resolver.rb', line 16

def view_dirs(root) = dirs_for(root, "app/views")