lib/dm-transactions.rb
def link(*things)
      unless none?
        raise "Illegal state for link: #{state}"
      end

      things.each do |thing|
        case thing
          when DataMapper::Adapters::AbstractAdapter
            @adapters[thing] = :none
          when DataMapper::Repository
            link(thing.adapter)
          when DataMapper::Model
            link(*thing.repositories)
          when DataMapper::Resource
            link(thing.model)
          when Array
            link(*thing)
          else
            raise "Unknown argument to #{self.class}#link: #{thing.inspect} (#{thing.class})"
        end
      end

      if block_given?
        commit { |*block_args| yield(*block_args) }
      else
        self
      end
    end
def link(*things)
      unless none?
        raise "Illegal state for link: #{state}"
      end

      things.each do |thing|
        case thing
          when DataMapper::Adapters::AbstractAdapter
            @adapters[thing] = :none
          when DataMapper::Repository
            link(thing.adapter)
          when DataMapper::Model
            link(*thing.repositories)
          when DataMapper::Resource
            link(thing.model)
          when Array
            link(*thing)
          else
            raise "Unknown argument to #{self.class}#link: #{thing.inspect} (#{thing.class})"
        end
      end

      if block_given?
        commit { |*block_args| yield(*block_args) }
      else
        self
      end
    end
Create a new Transaction

 @see Transaction#link

 In fact, it just calls #link with the given arguments at the end of the
 constructor.

 @api public
 Associate this Transaction with some things.

 @param [Object] things
   the things you want this Transaction associated with:

   Adapters::AbstractAdapter subclasses will be added as
     adapters as is.
   Arrays will have their elements added.
   Repository will have it's own @adapters added.
   Resource subclasses will have all the repositories of all
     their properties added.
   Resource instances will have all repositories of all their
     properties added.

 @param [Proc] block
   a block (taking one argument, the Transaction) to execute within
   this transaction. The transaction will begin and commit around
   the block, and rollback if an exception is raised.

 @api private