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/
Class Method Summary collapse
- .controller_dirs(root) ⇒ Object
- .dirs_for(root, kind) ⇒ Object
- .model_dirs(root) ⇒ Object
- .view_dirs(root) ⇒ Object
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 |