@@ -4569,6 +4569,35 @@ function! s:app_engines() dict abort
45694569 return self .cache.get (' engines' )
45704570endfunction
45714571
4572+ function ! s: app_smart_projections () dict abort
4573+ let ts = getftime (self .path (' app/' ))
4574+ if self .cache.needs (' smart_projections' , ts )
4575+ let dict = {}
4576+ for dir in self .relglob (' app/' , ' *s' , ' /' )
4577+ let singular = rails#singularize (dir )
4578+ let glob = ' app/' . dir . ' /*_' . singular . ' .rb'
4579+ if dir !~# ' \v^%(assets|models|views)$' &&
4580+ \ ! has_key (s: default_projections , glob ) &&
4581+ \ ! empty (self .relglob (' ' , glob ))
4582+ let dict [glob ] = {' type' : s: gsub (tolower (singular), ' \A+' , ' ' )}
4583+ endif
4584+ endfor
4585+ if has_key (dict , ' app/mailers/*_mailer.rb' ) || self .has_rails5 ()
4586+ let dict [' app/mailers/*_mailer.rb' ] = {
4587+ \ " affinity" : " controller" ,
4588+ \ " template" : [" class {camelcase|capitalize|colons}Mailer < ActionMailer::Base" , " end" ],
4589+ \ " type" : " mailer" }
4590+ else
4591+ let dict [' app/mailers/*.rb' ] = {
4592+ \ " affinity" : " controller" ,
4593+ \ " template" : [" class {camelcase|capitalize|colons} < ActionMailer::Base" , " end" ],
4594+ \ " type" : " mailer" }
4595+ endif
4596+ call self .cache.set (' smart_projections' , dict , ts )
4597+ endif
4598+ return self .cache.get (' smart_projections' )
4599+ endfunction
4600+
45724601function ! s: extend_projection (dest, src ) abort
45734602 let dest = copy (a: dest )
45744603 for key in keys (a: src )
@@ -4642,11 +4671,6 @@ let s:default_projections = {
46424671 \ " template" : [" class {camelcase|capitalize|colons}Job < ActiveJob::Base" , " end" ],
46434672 \ " type" : " job"
46444673 \ },
4645- \ " app/mailers/*.rb" : {
4646- \ " affinity" : " controller" ,
4647- \ " template" : [" class {camelcase|capitalize|colons} < ActionMailer::Base" , " end" ],
4648- \ " type" : " mailer"
4649- \ },
46504674 \ " app/models/*.rb" : {
46514675 \ " affinity" : " model" ,
46524676 \ " template" : [" class {camelcase|capitalize|colons}" , " end" ],
@@ -4857,6 +4881,7 @@ function! s:app_projections() dict abort
48574881 call s: combine_projections (dict , v )
48584882 endif
48594883 endfor
4884+ call s: combine_projections (dict , self .smart_projections ())
48604885 call s: combine_projections (dict , get (g: , ' rails_projections' , ' ' ))
48614886 for gem in keys (get (g: , ' rails_gem_projections' , {}))
48624887 if self .has_gem (gem)
@@ -4898,7 +4923,7 @@ function! s:app_projections() dict abort
48984923 return dict
48994924endfunction
49004925
4901- call s: add_methods (' app' , [' gems' , ' has_gem' , ' engines' , ' projections' ])
4926+ call s: add_methods (' app' , [' gems' , ' has_gem' , ' engines' , ' smart_projections ' , ' projections' ])
49024927
49034928let s: transformations = {}
49044929
0 commit comments