Skip to content

Commit 0d056dc

Browse files
committed
Support :R and :A in timestamped migrations
Inside of self.up or self.down, :R jumps to the migration in that direction. Outside, :R always goes up, and :A goes down, like the old behavior.
1 parent 419f006 commit 0d056dc

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

autoload/rails.vim

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,10 +2865,6 @@ function! s:readable_related(...) dict abort
28652865
endif
28662866
elseif f =~ '\<config/routes\.rb$' | return "config/database.yml"
28672867
elseif f =~ '\<config/environment\.rb$' | return "config/routes.rb"
2868-
elseif f =~ '\<db/migrate/\d\d\d_'
2869-
let num = matchstr(f,'\<db/migrate/0*\zs\d\+\ze_')+1
2870-
let migr = self.app().migration(num)
2871-
return migr == '' ? "db/schema.rb" : migr
28722868
elseif t =~ '^view-layout\>'
28732869
return s:sub(s:sub(s:sub(f,'/views/','/controllers/'),'/layouts/(\k+)\..*$','/\1_controller.rb'),'<application_controller\.rb$','application.rb')
28742870
elseif t =~ '^view\>'
@@ -2907,9 +2903,17 @@ function! s:readable_related(...) dict abort
29072903
elseif f =~ '\<config/database\.yml$' | return "config/routes.rb"
29082904
elseif f =~ '\<config/routes\.rb$' | return "config/environment.rb"
29092905
elseif f =~ '\<config/environment\.rb$' | return "config/database.yml"
2910-
elseif f =~ '\<db/migrate/\d\d\d_'
2911-
let num = matchstr(f,'\<db/migrate/0*\zs\d\+\ze_')-1
2912-
return self.app().migration(num)
2906+
elseif f =~ '\<db/migrate/'
2907+
let migrations = sort(self.app().relglob('db/migrate/','*','.rb'))
2908+
let me = matchstr(f,'\<db/migrate/\zs.*\ze\.rb$')
2909+
if !exists('l:lastmethod') || lastmethod == 'down'
2910+
let candidates = reverse(filter(copy(migrations),'v:val < me'))
2911+
let migration = "db/migrate/".get(candidates,0,migrations[-1]).".rb"
2912+
else
2913+
let candidates = filter(copy(migrations),'v:val > me')
2914+
let migration = "db/migrate/".get(candidates,0,migrations[0]).".rb"
2915+
endif
2916+
return migration . (exists('l:lastmethod') && lastmethod != '' ? '#'.lastmethod : '')
29132917
elseif f =~ '\<application\.js$'
29142918
return "app/helpers/application_helper.rb"
29152919
elseif t =~ '^javascript\>'

0 commit comments

Comments
 (0)