Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/ensure_connected.rb

Overview

ensure that your database connection is valid before executing a method see gist.github.com/238999 see axonflux.com/resque-to-the-rescue-but-a-gotcha-dont-forget

Instance Method Summary collapse

Instance Method Details

#ensure_connected(method) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/ensure_connected.rb', line 5

def ensure_connected(method)
  define_method("#{method}_with_verified_connections") do |*args|
    ActiveRecord::Base.connection_handler.verify_active_connections!
    send("#{method}_without_verified_connections", *args)
  end
  alias_method_chain method, :verified_connections
end