<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Class: Transaction::Simple::Group</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" /> <script type="text/javascript"> // <![CDATA[ function popupCode( url ) { window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") } function toggleCode( id ) { if ( document.getElementById ) elem = document.getElementById( id ); else if ( document.all ) elem = eval( "document.all." + id ); else return false; elemStyle = elem.style; if ( elemStyle.display != "block" ) { elemStyle.display = "block" } else { elemStyle.display = "none" } return true; } // Make codeblocks hidden by default document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" ) // ]]> </script> </head> <body> <div id="classHeader"> <table class="header-table"> <tr class="top-aligned-row"> <td><strong>Class</strong></td> <td class="class-name-in-header">Transaction::Simple::Group</td> </tr> <tr class="top-aligned-row"> <td><strong>In:</strong></td> <td> <a href="../../../files/lib/transaction/simple/group_rb.html"> lib/transaction/simple/group.rb </a> <br /> </td> </tr> <tr class="top-aligned-row"> <td><strong>Parent:</strong></td> <td> Object </td> </tr> </table> </div> <!-- banner header --> <div id="bodyContent"> <div id="contextContent"> <div id="description"> <p> A <a href="Group.html#M000023">transaction</a> group is an object wrapper that manages a group of objects as if they were a single object for the purpose of <a href="Group.html#M000023">transaction</a> management. All transactions for this group of objects should be performed against the <a href="Group.html#M000023">transaction</a> group object, not against individual objects in the group. </p> <h2><a href="../../Transaction.html">Transaction</a> <a href="Group.html">Group</a> Usage</h2> <pre> require 'transaction/simple/group' x = "Hello, you." y = "And you, too." g = Transaction::Simple::Group.new(x, y) g.start_transaction(:first) # -> [ x, y ] g.transaction_open?(:first) # -> true x.transaction_open?(:first) # -> true y.transaction_open?(:first) # -> true x.gsub!(/you/, "world") # -> "Hello, world." y.gsub!(/you/, "me") # -> "And me, too." g.start_transaction(:second) # -> [ x, y ] x.gsub!(/world/, "HAL") # -> "Hello, HAL." y.gsub!(/me/, "Dave") # -> "And Dave, too." g.rewind_transaction(:second) # -> [ x, y ] x # -> "Hello, world." y # -> "And me, too." x.gsub!(/world/, "HAL") # -> "Hello, HAL." y.gsub!(/me/, "Dave") # -> "And Dave, too." g.commit_transaction(:second) # -> [ x, y ] x # -> "Hello, HAL." y # -> "And Dave, too." g.abort_transaction(:first) # -> [ x, y ] x = -> "Hello, you." y = -> "And you, too." </pre> </div> </div> <div id="method-list"> <h3 class="section-bar">Methods</h3> <div class="name-list"> <a href="#M000021">abort_transaction</a> <a href="#M000016">clear</a> <a href="#M000022">commit_transaction</a> <a href="#M000015">new</a> <a href="#M000020">rewind_transaction</a> <a href="#M000019">start_transaction</a> <a href="#M000023">transaction</a> <a href="#M000018">transaction_name</a> <a href="#M000017">transaction_open?</a> </div> </div> </div> <!-- if includes --> <div id="section"> <div id="attribute-list"> <h3 class="section-bar">Attributes</h3> <div class="name-list"> <table> <tr class="top-aligned-row context-row"> <td class="context-item-name">objects</td> <td class="context-item-value"> [R] </td> <td class="context-item-desc"> Returns the objects that are covered by this <a href="Group.html#M000023">transaction</a> group. </td> </tr> </table> </div> </div> <!-- if method_list --> <div id="methods"> <h3 class="section-bar">Public Class methods</h3> <div id="method-M000015" class="method-detail"> <a name="M000015"></a> <div class="method-heading"> <a href="Group.src/M000015.html" target="Code" class="method-signature" onclick="popupCode('Group.src/M000015.html');return false;"> <span class="method-name">new</span><span class="method-args">(*objects) {|self| ...}</span> </a> </div> <div class="method-description"> <p> Creates a <a href="Group.html#M000023">transaction</a> group for the provided objects. If a block is provided, the <a href="Group.html#M000023">transaction</a> group object is yielded to the block; when the block is finished, the <a href="Group.html#M000023">transaction</a> group object will be cleared with <a href="Group.html#M000016">clear</a>. </p> </div> </div> <h3 class="section-bar">Public Instance methods</h3> <div id="method-M000021" class="method-detail"> <a name="M000021"></a> <div class="method-heading"> <a href="Group.src/M000021.html" target="Code" class="method-signature" onclick="popupCode('Group.src/M000021.html');return false;"> <span class="method-name">abort_transaction</span><span class="method-args">(name = nil)</span> </a> </div> <div class="method-description"> <p> Aborts the <a href="Group.html#M000023">transaction</a>. Resets the object state to what it was before the <a href="Group.html#M000023">transaction</a> was started and closes the <a href="Group.html#M000023">transaction</a>. If <tt>name</tt> is specified, then the intervening transactions and the named <a href="Group.html#M000023">transaction</a> will be aborted. Otherwise, only the current <a href="Group.html#M000023">transaction</a> is aborted. </p> <p> If the current or named <a href="Group.html#M000023">transaction</a> has been started by a block (<a href="../Simple.html#M000013">Transaction::Simple.start</a>), then the execution of the block will be halted with <tt>break</tt> <tt>self</tt>. </p> </div> </div> <div id="method-M000016" class="method-detail"> <a name="M000016"></a> <div class="method-heading"> <a href="Group.src/M000016.html" target="Code" class="method-signature" onclick="popupCode('Group.src/M000016.html');return false;"> <span class="method-name">clear</span><span class="method-args">()</span> </a> </div> <div class="method-description"> <p> Clears the object group. Removes references to the objects so that they can be garbage collected. </p> </div> </div> <div id="method-M000022" class="method-detail"> <a name="M000022"></a> <div class="method-heading"> <a href="Group.src/M000022.html" target="Code" class="method-signature" onclick="popupCode('Group.src/M000022.html');return false;"> <span class="method-name">commit_transaction</span><span class="method-args">(name = nil)</span> </a> </div> <div class="method-description"> <p> If <tt>name</tt> is <tt>nil</tt> (default), the current <a href="Group.html#M000023">transaction</a> level is closed out and the changes are committed. </p> <p> If <tt>name</tt> is specified and <tt>name</tt> is in the list of named transactions, then all transactions are closed and committed until the named <a href="Group.html#M000023">transaction</a> is reached. </p> </div> </div> <div id="method-M000020" class="method-detail"> <a name="M000020"></a> <div class="method-heading"> <a href="Group.src/M000020.html" target="Code" class="method-signature" onclick="popupCode('Group.src/M000020.html');return false;"> <span class="method-name">rewind_transaction</span><span class="method-args">(name = nil)</span> </a> </div> <div class="method-description"> <p> Rewinds the <a href="Group.html#M000023">transaction</a>. If <tt>name</tt> is specified, then the intervening transactions will be aborted and the named <a href="Group.html#M000023">transaction</a> will be rewound. Otherwise, only the current <a href="Group.html#M000023">transaction</a> is rewound. </p> </div> </div> <div id="method-M000019" class="method-detail"> <a name="M000019"></a> <div class="method-heading"> <a href="Group.src/M000019.html" target="Code" class="method-signature" onclick="popupCode('Group.src/M000019.html');return false;"> <span class="method-name">start_transaction</span><span class="method-args">(name = nil)</span> </a> </div> <div class="method-description"> <p> Starts a <a href="Group.html#M000023">transaction</a> for the group. Stores the current object state. If a <a href="Group.html#M000023">transaction</a> name is specified, the <a href="Group.html#M000023">transaction</a> will be named. <a href="../../Transaction.html">Transaction</a> names must be unique. <a href="../../Transaction.html">Transaction</a> names of <tt>nil</tt> will be treated as unnamed transactions. </p> </div> </div> <div id="method-M000023" class="method-detail"> <a name="M000023"></a> <div class="method-heading"> <a href="Group.src/M000023.html" target="Code" class="method-signature" onclick="popupCode('Group.src/M000023.html');return false;"> <span class="method-name">transaction</span><span class="method-args">(action = nil, name = nil)</span> </a> </div> <div class="method-description"> <p> Alternative method for calling the <a href="Group.html#M000023">transaction</a> methods. An optional name can be specified for named <a href="Group.html#M000023">transaction</a> support. </p> <table> <tr><td valign="top"><a href="Group.html#M000023">transaction</a>(:start):</td><td><a href="Group.html#M000019">start_transaction</a> </td></tr> <tr><td valign="top"><a href="Group.html#M000023">transaction</a>(:rewind):</td><td><a href="Group.html#M000020">rewind_transaction</a> </td></tr> <tr><td valign="top"><a href="Group.html#M000023">transaction</a>(:abort):</td><td><a href="Group.html#M000021">abort_transaction</a> </td></tr> <tr><td valign="top"><a href="Group.html#M000023">transaction</a>(:commit):</td><td><a href="Group.html#M000022">commit_transaction</a> </td></tr> <tr><td valign="top"><a href="Group.html#M000023">transaction</a>(:name):</td><td><a href="Group.html#M000018">transaction_name</a> </td></tr> <tr><td valign="top"><a href="Group.html#M000023">transaction</a>:</td><td>transaction_open? </td></tr> </table> </div> </div> <div id="method-M000018" class="method-detail"> <a name="M000018"></a> <div class="method-heading"> <a href="Group.src/M000018.html" target="Code" class="method-signature" onclick="popupCode('Group.src/M000018.html');return false;"> <span class="method-name">transaction_name</span><span class="method-args">()</span> </a> </div> <div class="method-description"> <p> Returns the current name of the <a href="Group.html#M000023">transaction</a> for the group. Transactions not explicitly named are named <tt>nil</tt>. </p> </div> </div> <div id="method-M000017" class="method-detail"> <a name="M000017"></a> <div class="method-heading"> <a href="Group.src/M000017.html" target="Code" class="method-signature" onclick="popupCode('Group.src/M000017.html');return false;"> <span class="method-name">transaction_open?</span><span class="method-args">(name = nil)</span> </a> </div> <div class="method-description"> <p> Tests to see if all of the objects in the group have an open <a href="Group.html#M000023">transaction</a>. See Transaction::Simple#transaction_open? for more information. </p> </div> </div> </div> </div> <div id="validator-badges"> <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p> </div> </body> </html>