Skip to content

Commit cccd2ad

Browse files
Travis Jefferytpope
authored andcommitted
Add :Rschema navigation command
1 parent defddd2 commit cccd2ad

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

autoload/rails.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,7 @@ function! s:BufFinderCommands()
21322132
call s:addfilecmds("controller")
21332133
call s:addfilecmds("mailer")
21342134
call s:addfilecmds("migration")
2135+
call s:addfilecmds("schema")
21352136
call s:addfilecmds("observer")
21362137
call s:addfilecmds("helper")
21372138
call s:addfilecmds("layout")
@@ -2287,6 +2288,14 @@ function! s:migrationList(A,L,P)
22872288
endif
22882289
endfunction
22892290

2291+
function! s:schemaList(A,L,P)
2292+
let tables = s:readfile(rails#app().path('db/schema.rb'))
2293+
let table_re = '^\s\+create_table\s["'':]\zs[^"'',]*\ze'
2294+
call map(tables,'matchstr(v:val, table_re)')
2295+
call filter(tables,'strlen(v:val)')
2296+
return s:autocamelize(tables, a:A)
2297+
endfunction
2298+
22902299
function! s:unittestList(A,L,P)
22912300
let found = []
22922301
if rails#app().has('test')
@@ -2516,6 +2525,15 @@ function! s:migrationEdit(cmd,...)
25162525
endif
25172526
endfunction
25182527

2528+
function! s:schemaEdit(cmd,...)
2529+
let cmd = s:findcmdfor(a:cmd)
2530+
let schema = 'db/'.s:environment().'_structure.sql'
2531+
if rails#app().has_file('db/schema.rb') || !rails#app().has_file(schema)
2532+
let schema = 'db/schema.rb'
2533+
endif
2534+
call s:findedit(cmd,schema.(a:0 ? '#'.a:1 : ''))
2535+
endfunction
2536+
25192537
function! s:fixturesEdit(cmd,...)
25202538
if a:0
25212539
let c = rails#underscore(a:1)

doc/rails.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ itself!).
271271
:Rmodel |rails-:Rmodel|
272272
:Robserver |rails-:Robserver|
273273
:Rplugin |rails-:Rplugin|
274+
:Rschema |rails-:Rschema|
274275
:Rspec |rails-:Rspec|
275276
:Rstylesheet |rails-:Rstylesheet|
276277
:Rtask |rails-:Rtask|
@@ -378,6 +379,10 @@ itself!).
378379
command is only defined if there is a spec folder in
379380
the root of the application.
380381

382+
*rails-:Rschema*
383+
:Rschema [{table}] Edit the schema and optionally jump to the specified
384+
table.
385+
381386
*rails-:Rstylesheet*
382387
:Rstylesheet [{name}] Edit the stylesheet for the specified name or current
383388
controller. Also supports Sass and SCSS.

0 commit comments

Comments
 (0)