Skip to content

Commit e191b24

Browse files
Justin Constantinotpope
authored andcommitted
Recognize indented ActiveRecord models
Allow leading whitespace in regular expressions to recognize ActiveRecord models that are indented (e.g. inside modules).
1 parent 2b33a3d commit e191b24

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

autoload/rails.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,15 +822,15 @@ function! s:readable_calculate_file_type() dict abort
822822
let r = "model-concern"
823823
elseif f =~# '^app/models/'
824824
let top = "\n".join(s:readbuf(full_path,50),"\n")
825-
let class = matchstr(top,"\n".'class\s\+\S\+\s*<\s*\<\zs\S\+\>')
825+
let class = matchstr(top,"\n".'\s*class\s\+\S\+\s*<\s*\<\zs\S\+\>')
826826
let type = tolower(matchstr(class, '^Application\zs[A-Z]\w*$\|^Acti\w\w\zs[A-Z]\w*\ze::Base'))
827827
if type ==# 'mailer' || f =~# '_mailer\.rb$'
828828
let r = 'mailer'
829829
elseif class ==# 'ActiveRecord::Observer'
830830
let r = 'model-observer'
831831
elseif !empty(type)
832832
let r = 'model-'.type
833-
elseif top =~# '^\%(self\.\%(table_name\|primary_key\)\|has_one\|has_many\|belongs_to\)\>'
833+
elseif top =~# '\n\s*\%(self\.\%(table_name\|primary_key\)\|has_one\|has_many\|belongs_to\)\>'
834834
let r = 'model-record'
835835
else
836836
let r = 'model'

0 commit comments

Comments
 (0)