Skip to content

Commit

Permalink
Use new autocmd interface of dbext 8.00
Browse files Browse the repository at this point in the history
  • Loading branch information
tpope committed Oct 30, 2008
1 parent a754e87 commit 6205a40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
10 changes: 7 additions & 3 deletions autoload/rails.vim
Expand Up @@ -3710,10 +3710,10 @@ function! s:app_dbext_settings(environment) dict
endfunction

function! s:BufDatabase(...)
let self = rails#app()
if exists("s:lock_database") || !exists('g:loaded_dbext')
if exists("s:lock_database") || !exists('g:loaded_dbext') || !exists('b:rails_root')
return
endif
let self = rails#app()
let s:lock_database = 1
if (a:0 && a:1 > 1)
call self.cache.clear('dbext_settings')
Expand All @@ -3723,6 +3723,7 @@ function! s:BufDatabase(...)
else
let env = s:environment()
endif
unlet! b:dbext_buffer_defaulted
if (!self.cache.has('dbext_settings') || !has_key(self.cache.get('dbext_settings'),env)) && (g:rails_dbext + (a:0 ? a:1 : 0)) <= 0
unlet! s:lock_database
return
Expand Down Expand Up @@ -4225,7 +4226,9 @@ function! RailsBufInit(path)
call s:BufSettings()
call s:BufCommands()
call s:BufAbbreviations()
call s:BufDatabase()
if exists("g:loaded_dbext") && g:loaded_dbext < 800
call s:BufDatabase()
endif
" snippetsEmu.vim
if exists('g:loaded_snippet')
silent! runtime! ftplugin/rails_snippets.vim
Expand Down Expand Up @@ -4370,6 +4373,7 @@ augroup railsPluginAuto
autocmd User BufEnterRails call s:RefreshBuffer()
autocmd User BufEnterRails call s:resetomnicomplete()
autocmd User BufEnterRails call s:BufDatabase(-1)
autocmd User dbextPreConnection call s:BufDatabase(1)
autocmd BufWritePost */config/database.yml call rails#cache_clear("dbext_settings")
autocmd BufWritePost */test/test_helper.rb call rails#cache_clear("user_assertions")
autocmd BufWritePost */config/routes.rb call rails#cache_clear("named_routes")
Expand Down
13 changes: 8 additions & 5 deletions doc/rails.txt
Expand Up @@ -681,16 +681,19 @@ place) are also covered in this section.
is installed. Loads the {environment} configuration
(defaults to $RAILS_ENV or development) from
config/database.yml and uses it to configure dbext.
The configuration is cached until a different Rails
application is edited. This command is called for you
automatically when |g:rails_dbext| is set (default on
non-Windows systems).
The configuration is cached on a per application
basis. With dbext versions 8.00 and newer, this
command is called automatically when needed. For
older versions, it is called automatically when
rails.vim loads if |g:rails_dbext| is set (which it is
by default).

*rails-:Rdbext!*
:Rdbext! [{environment}]
Load the database configuration as above, and then
attempt a CREATE DATABASE for it. This is primarily
useful for demonstrations.
useful for demonstrations, and has been largely
superseded by |:Rake| db:create.

*rails-surround*
The |surround| plugin available from vim.org enables adding and removing
Expand Down

0 comments on commit 6205a40

Please sign in to comment.