eagletmt/switch_point — pull request #2 by ryopeko (2014-06-23 06:08:30+00:00)
Title: Add transaction_with for transaction multiple models related

This feature supports transaction using multi models.
Using multi models in a transaction...

```ruby
class Book1 < ActiveRecord::Base
use_switch_point :db1
end

class Book2 < ActiveRecord::Base
use_switch_point :db1
end

transaction do
Book1.with_writable do
#insert, update, delete, etc...
end

Book2.with_writable do
#insert, update, delete, etc...
end
end
```

It is not "DRY".

In this case, Book1 and Book2 has a same db connection.
Therefore, we do not need that write twice a "with_writable".

When we write code like this, we must think that switch "readable, writable".

And, transaction must need a same connection.

Now, using this patch...
```ruby
Book1.transaction_with(Book2) do
#insert, update, delete, etc...
end
```

It is "DRY" and easier to understand the intention.

Also, user does not run of unintended query to DB.
(ex. User did not know Book2 using other DB.)

It will raise a exception in that case.
```ruby
class Book3 < ActiveRecord::Base
use_switch_point :db2
end

Book1.transaction_with(Book2, Book3) do
#insert, update, delete, etc...
end

#=> raise RuntimeError
```

But, this method is declarative.
You can switch a connection in a block of transaction_with.