Skip to content
Browse files

Add :Rschema navigation command

  • Loading branch information...
1 parent defddd2 commit 2746f45c8c3c932ab7da65e2ace80329468b8817 Travis Jeffery committed with
Showing with 25 additions and 0 deletions.
  1. +19 −0 autoload/rails.vim
  2. +6 −0 doc/rails.txt
View
19 autoload/rails.vim
@@ -2132,6 +2132,7 @@ function! s:BufFinderCommands()
call s:addfilecmds("controller")
call s:addfilecmds("mailer")
call s:addfilecmds("migration")
+ call s:addfilecmds("schema")
call s:addfilecmds("observer")
call s:addfilecmds("helper")
call s:addfilecmds("layout")
@@ -2287,6 +2288,14 @@ function! s:migrationList(A,L,P)
endif
endfunction
+function! s:schemaList(A,L,P)
+ let tables = s:readfile(rails#app().path('db/schema.rb'))
+ let table_re = '^\s\+create_table\s["'':]\zs[^"'',]*\ze'
+ call map(tables,'matchstr(v:val, table_re)')
+ call filter(tables,'strlen(v:val)')
+ return s:autocamelize(tables, a:A)
+endfunction
+
function! s:unittestList(A,L,P)
let found = []
if rails#app().has('test')
@@ -2516,6 +2525,16 @@ function! s:migrationEdit(cmd,...)
endif
endfunction
+function! s:schemaEdit(cmd,...)
+ let cmd = s:findcmdfor(a:cmd)
+ let schema = 'db/'.s:environment().'_structure.sql'
+ if rails#app().has_file('db/schema.rb') || !rails#app().has_file(schema)
+ let schema = 'db/schema.rb'
+ endif
+ let table = (a:0 ? a:1 : s:gsub(rails#pluralize(s:model(1)),'/','_'))
+ call s:findedit(cmd,schema.'#'.table)
+endfunction
+
function! s:fixturesEdit(cmd,...)
if a:0
let c = rails#underscore(a:1)
View
6 doc/rails.txt
@@ -271,6 +271,7 @@ itself!).
:Rmodel |rails-:Rmodel|
:Robserver |rails-:Robserver|
:Rplugin |rails-:Rplugin|
+:Rschema |rails-:Rschema|
:Rspec |rails-:Rspec|
:Rstylesheet |rails-:Rstylesheet|
:Rtask |rails-:Rtask|
@@ -378,6 +379,11 @@ itself!).
command is only defined if there is a spec folder in
the root of the application.
+ *rails-:Rschema*
+:Rschema [{table}] Edit the schema and jump to the specified table or the
+ table for the current model. If you want to jump to
+ the top of the schema, use |:Rmigration| 0 instead.
+
*rails-:Rstylesheet*
:Rstylesheet [{name}] Edit the stylesheet for the specified name or current
controller. Also supports Sass and SCSS.

0 comments on commit 2746f45

Please sign in to comment.
Something went wrong with that request. Please try again.