<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>File: defaultclient.rb</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="fileHeader"> <h1>defaultclient.rb</h1> <table class="header-table"> <tr class="top-aligned-row"> <td><strong>Path:</strong></td> <td>defaultclient.rb </td> </tr> <tr class="top-aligned-row"> <td><strong>Last Update:</strong></td> <td>Fri Nov 19 17:20:25 GMT 2004</td> </tr> </table> </div> <!-- banner header --> <div id="bodyContent"> <div id="contextContent"> <div id="description"> <h2>Introduction</h2> <pre> This script ensures that the default client view offered to users for new client workspaces is based on a template client specified in the trigger definition. </pre> <h2>Synopsis</h2> <pre> defaultclient.rb <templatename> <clientname> <formfile> </pre> <h2>Sample Trigger Definition</h2> <pre> Using a trigger spec like this: defaultclient out client "defaultclient.rb baseclient %formname% %formfile%" would make the default client view offered to any user based on the view defined in the client called 'baseclient'. Changing that client spec would change the default view. </pre> </div> <div id="requires-list"> <h2 class="section-bar">Required files</h2> <div class="name-list"> <a href="../classes/P4.html">P4</a> </div> </div> <div id="method-list"> <h2 class="section-bar">Methods</h2> <div class="name-list"> <a href="#M000002">client_exists?</a> <a href="#M000001">croakusage</a> <a href="#M000003">load_spec</a> <a href="#M000004">write_spec</a> </div> </div> </div> <!-- if includes --> <!-- if method_list --> <div id="methods"> <h2 class="section-bar">Public Instance methods</h2> <div id="method-M000002" class="method-detail"> <a name="M000002"></a> <div class="method-heading"> <a href="#M000002" class="method-signature"> <span class="method-name">client_exists?</span><span class="method-args">( p4, name )</span> </a> </div> <div class="method-description"> <p> Check whether or not a client already exists. </p> <p><a class="source-toggle" href="#" onclick="toggleCode('M000002-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000002-source"> <pre> <span class="ruby-comment cmt"># File defaultclient.rb, line 59</span> 59: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">client_exists?</span>( <span class="ruby-identifier">p4</span>, <span class="ruby-identifier">name</span> ) 60: <span class="ruby-identifier">p4</span>.<span class="ruby-identifier">run_clients</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> 61: <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> 62: <span class="ruby-keyword kw">if</span>( <span class="ruby-identifier">c</span>[ <span class="ruby-value str">"client"</span> ] <span class="ruby-operator">==</span> <span class="ruby-identifier">name</span> ) 63: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span> 64: <span class="ruby-keyword kw">end</span> 65: <span class="ruby-keyword kw">end</span> 66: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> 67: <span class="ruby-keyword kw">end</span> </pre> </div> </div> </div> <div id="method-M000001" class="method-detail"> <a name="M000001"></a> <div class="method-heading"> <a href="#M000001" class="method-signature"> <span class="method-name">croakusage</span><span class="method-args">()</span> </a> </div> <div class="method-description"> <p> Show a message explaining correct usage of this script and exit. </p> <p><a class="source-toggle" href="#" onclick="toggleCode('M000001-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000001-source"> <pre> <span class="ruby-comment cmt"># File defaultclient.rb, line 34</span> 34: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">croakusage</span>() 35: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"\nUsage: defaultclient.rb <templatename> <clientname> <formfile>\n\nWhere:\n <templatename> - the name of an existing client workspace \n on which all future client workspaces \n should be based (by default).\n\n <clientname> - The name of the client spec the user's \n asking for\n\n <formfile> - The name of the temporary file in which the\n current client spec is stored\n\n"</span> 36: <span class="ruby-identifier">exit</span>( <span class="ruby-value">1</span> ) 37: <span class="ruby-keyword kw">end</span> </pre> </div> </div> </div> <div id="method-M000003" class="method-detail"> <a name="M000003"></a> <div class="method-heading"> <a href="#M000003" class="method-signature"> <span class="method-name">load_spec</span><span class="method-args">( formfile )</span> </a> </div> <div class="method-description"> <p> Load the skeleton spec from the formfile </p> <p><a class="source-toggle" href="#" onclick="toggleCode('M000003-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000003-source"> <pre> <span class="ruby-comment cmt"># File defaultclient.rb, line 72</span> 72: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_spec</span>( <span class="ruby-identifier">formfile</span> ) 73: <span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>( <span class="ruby-identifier">formfile</span>, <span class="ruby-value str">"r"</span> ) 74: <span class="ruby-identifier">buf</span> = <span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span> 75: <span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span> 76: <span class="ruby-identifier">buf</span> 77: <span class="ruby-keyword kw">end</span> </pre> </div> </div> </div> <div id="method-M000004" class="method-detail"> <a name="M000004"></a> <div class="method-heading"> <a href="#M000004" class="method-signature"> <span class="method-name">write_spec</span><span class="method-args">( spec, formfile )</span> </a> </div> <div class="method-description"> <p> Update the existing formfile with a new spec. Since the comments that appear at the top of a spec file are quite useful to the users, we preserve them and only update the end of the file with the new spec. </p> <p><a class="source-toggle" href="#" onclick="toggleCode('M000004-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000004-source"> <pre> <span class="ruby-comment cmt"># File defaultclient.rb, line 85</span> 85: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">write_spec</span>( <span class="ruby-identifier">spec</span>, <span class="ruby-identifier">formfile</span> ) 86: <span class="ruby-identifier">comments</span> = <span class="ruby-value str">""</span> 87: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>( <span class="ruby-identifier">formfile</span>, <span class="ruby-value str">"r"</span> ) <span class="ruby-keyword kw">do</span> 88: <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> 89: <span class="ruby-identifier">f</span>.<span class="ruby-identifier">each_line</span> <span class="ruby-keyword kw">do</span> 90: <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> 91: <span class="ruby-keyword kw">if</span>( <span class="ruby-identifier">line</span>[<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-value">1</span>] <span class="ruby-operator">!=</span> <span class="ruby-value str">'#'</span> ) 92: <span class="ruby-keyword kw">break</span> 93: <span class="ruby-keyword kw">end</span> 94: <span class="ruby-identifier">comments</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">line</span> 95: <span class="ruby-keyword kw">end</span> 96: <span class="ruby-keyword kw">end</span> 97: <span class="ruby-identifier">comments</span> <span class="ruby-operator">+=</span> <span class="ruby-value str">"\n"</span> 98: 99: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>( <span class="ruby-identifier">formfile</span>, <span class="ruby-value str">"w"</span> ) <span class="ruby-keyword kw">do</span> 100: <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> 101: <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>( <span class="ruby-identifier">comments</span> ) 102: <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>( <span class="ruby-identifier">spec</span> ) 103: <span class="ruby-keyword kw">end</span> 104: <span class="ruby-keyword kw">end</span> </pre> </div> </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>
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 4654 | Tony Smith |
Add an example spec trigger to show how you might restrict the default view for all new clients to a pre-defined set of mappings. |