Skip to content

Commit e6d3b1c

Browse files
committed
Add support for unreleased DB plugin
1 parent c08c87c commit e6d3b1c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

autoload/rails.vim

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4405,6 +4405,32 @@ endfunction
44054405

44064406
call s:add_methods('app', ['db_config', 'db_url', 'dbext_settings'])
44074407

4408+
function! rails#db_canonicalize(url) abort
4409+
let app = rails#app(db#url#file_path(a:url))
4410+
if empty(app)
4411+
throw 'DB: Not a Rails app'
4412+
endif
4413+
let env = db#url#fragment(a:url)
4414+
let url = empty(env) ? app.db_url() : app.db_url(env)
4415+
if empty(url)
4416+
throw 'DB: No Rails database for environment '.env
4417+
endif
4418+
let url = substitute(url, '^[^:]*\ze:', '\=get(g:db_adapters, submatch(0), submatch(0))', '')
4419+
let url = substitute(url, '^[^:]*://\%([^/@]*@\)\=\zs\%(localhost\)\=\([/?].*\)\=[?&]socket=\([^&]*\)', '\2\1', '')
4420+
let url = substitute(url, '[?&].*', '', '')
4421+
let url = substitute(url, '^mysql://\ze[^@]*$', 'mysql://root@', '')
4422+
return url
4423+
endfunction
4424+
4425+
function! rails#db_test_directory(path) abort
4426+
return filereadable(a:path . '/config/environment.rb') && isdirectory(a:path . '/app')
4427+
endfunction
4428+
4429+
function! rails#db_complete_fragment(url, ...) abort
4430+
let app = rails#app(db#url#file_path(a:url))
4431+
return len(app) ? app.environments() : []
4432+
endfunction
4433+
44084434
" }}}1
44094435
" Abbreviations {{{1
44104436

plugin/rails.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ augroup END
111111

112112
command! -bang -bar -nargs=* -count -complete=customlist,rails#complete_rails Rails execute rails#command(<bang>0, '<mods>', !<count> && <line1> ? -1 : <count>, <q-args>)
113113

114+
" }}}1
115+
" db.vim support {{{1
116+
117+
118+
call extend(g:, {'db_adapters': {}}, 'keep')
119+
call extend(g:db_adapters, {
120+
\ 'oracle-enhanced': 'oracle',
121+
\ 'mysql2': 'mysql',
122+
\ 'sqlite3': 'sqlite'}, 'keep')
123+
124+
let g:db_adapter_rails = 'rails#db_'
125+
114126
" }}}1
115127
" abolish.vim support {{{1
116128

0 commit comments

Comments
 (0)