<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html><head> <title>Class: P4RecFile</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel=StyleSheet href=".././rdoc-style.css" type="text/css" media="screen" /> <script type="text/javascript" language="JavaScript"> <!-- function popCode(url) { window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") } //--> </script> </head> <body bgcolor="white"> <table summary="Information on class" width="100%" border="0" cellspacing="0"> <tr class="title-row"> <td class="big-title-font"> <sup><font color="aqua">Class</font></sup> P4RecFile </td> <td align="right"> <table summary="layout" cellspacing="0" cellpadding="2"> <tr valign="top"> <td class="small-title-font">In:</td> <td class="small-title-font"> <a href="../files/P4table_rb.html" class="aqua"> P4table.rb </a> <br /> </td> </tr> <tr> <td class="small-title-font">Parent:</td> <td class="small-title-font"> Object </td> </tr> </table> </td> </tr> </table> <!-- banner header --> <div class="description"><p> Class for representing files that are versioned in the depot. Files can be either (a) the meta file containing the metadata about the record (basically a "p4 job -o <recid>") or they can be other files which are attached to the record. </p> </div> <table summary="Methods" cellpadding="5" width="100%"> <tr><td class="tablesubtitle">Methods</td></tr> </table> <div class="name-list"> <a href="#M000021">add</a> <a href="#M000023">delete</a> <a href="#M000018">depot_path</a> <a href="#M000017">depot_path=</a> <a href="#M000022">edit</a> <a href="#M000020">exists=</a> <a href="#M000019">exists?</a> <a href="#M000026">mkdir</a> <a href="#M000015">new</a> <a href="#M000024">read</a> <a href="#M000027">to_s</a> <a href="#M000025">write</a> <a href="#M000016">ws_path</a> </div> <table summary="Attributes" cellpadding="5" width="100%"> <tr><td class="tablesubtitle">Attributes</td></tr> </table> <table summary="Attribute details" cellspacing="5"> <tr valign="top"> <td class="attr-name">:id</td> <td align="center" class="attr-rw"> [R] </td> <td></td> </tr> <tr valign="top"> <td class="attr-name">:name</td> <td align="center" class="attr-rw"> [R] </td> <td></td> </tr> </table> <table summary="Method list" cellpadding="5" width="100%"> <tr><td class="tablesubtitle">Public Class methods</td></tr> </table> <table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> <tr><td class="methodtitle"> <a name="M000015"></a> <b>new</b>( name, id ) </td></tr> </table> <div class="description"> <p> Construct a new <a href="P4RecFile.html">P4RecFile</a> object based on the supplied filename and RecId. </p> </div> <pre class="source"> <span class="cmt"># File P4table.rb, line 277</span> <span class="kw">def</span> initialize( name, id ) @name = name @id = id @exists = <span class="kw">false</span> @depot_path = <span class="kw">nil</span> @ws_path = <span class="kw">nil</span> <span class="kw">end</span> </pre> <table summary="Method list" cellpadding="5" width="100%"> <tr><td class="tablesubtitle">Public Instance methods</td></tr> </table> <table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> <tr><td class="methodtitle"> <a name="M000016"></a> <b>ws_path</b>() </td></tr> </table> <div class="description"> <p> Convert the depot path into a client path. Obviously this precludes complex client maps as we don't want to reimplement Perforce mappings in Ruby. </p> </div> <pre class="source"> <span class="cmt"># File P4table.rb, line 292</span> <span class="kw">def</span> ws_path <span class="kw">return</span> @ws_path <span class="kw">if</span> ( @ws_path ) root = P4Global.tagged.fetch_client[ <span class="str">"Root"</span> ] path = depot_path.sub( DEPOT_ROOT_PATH, root ) @ws_path = path.gsub!( <span class="str">"/"</span>, SEP ) <span class="kw">end</span> </pre> <table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> <tr><td class="methodtitle"> <a name="M000017"></a> <b>depot_path=</b>( path ) </td></tr> </table> <div class="description"> <p> Explicitly set the depot path for a file. Needed to allow old records to be found in their old locations even if the storage map has since changed. </p> </div> <pre class="source"> <span class="cmt"># File P4table.rb, line 306</span> <span class="kw">def</span> depot_path=( path ) @depot_path = path <span class="kw">end</span> </pre> <table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> <tr><td class="methodtitle"> <a name="M000018"></a> <b>depot_path</b>() </td></tr> </table> <div class="description"> <p> Compute the depot path based on the table storage map and the id </p> </div> <pre class="source"> <span class="cmt"># File P4table.rb, line 313</span> <span class="kw">def</span> depot_path <span class="kw">return</span> @depot_path <span class="kw">if</span> @depot_path table_path = @id.table.storage_map( @id ).join( <span class="str">"/"</span> ) @depot_path = [ DEPOT_ROOT_PATH, table_path, @id.seq_str, @name ].join( <span class="str">"/"</span> ) <span class="kw">end</span> </pre> <table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> <tr><td class="methodtitle"> <a name="M000019"></a> <b>exists?</b>() </td></tr> </table> <div class="description"> <p> Does the file exist? </p> </div> <pre class="source"> <span class="cmt"># File P4table.rb, line 322</span> <span class="kw">def</span> exists? @exists <span class="kw">end</span> </pre> <table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> <tr><td class="methodtitle"> <a name="M000020"></a> <b>exists=</b>( bool ) </td></tr> </table> <div class="description"> <p> Set the existence flag for a file explicitly </p> </div> <pre class="source"> <span class="cmt"># File P4table.rb, line 329</span> <span class="kw">def</span> exists=( bool ) @exists = bool <span class="kw">end</span> </pre> <table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> <tr><td class="methodtitle"> <a name="M000021"></a> <b>add</b>() </td></tr> </table> <div class="description"> <p> Open this file for add </p> </div> <pre class="source"> <span class="cmt"># File P4table.rb, line 336</span> <span class="kw">def</span> add <span class="kw">if</span> ( exists? ) raise( RuntimeError, <span class="str">"Can't open existing file for add"</span>, caller ) <span class="kw">end</span> P4Global.tagged.run_sync P4Global.tagged.run_add( ws_path() ) <span class="kw">end</span> </pre> <table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> <tr><td class="methodtitle"> <a name="M000022"></a> <b>edit</b>() </td></tr> </table> <div class="description"> <p> Open this file for edit </p> </div> <pre class="source"> <span class="cmt"># File P4table.rb, line 347</span> <span class="kw">def</span> edit <span class="kw">if</span> ( ! exists? ) raise( RuntimeError,<span class="str">"Can't open non-existent file for edit"</span>, caller) <span class="kw">end</span> P4Global.tagged.run_sync P4Global.tagged.run_edit( depot_path() ) <span class="kw">end</span> </pre> <table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> <tr><td class="methodtitle"> <a name="M000023"></a> <b>delete</b>() </td></tr> </table> <div class="description"> <p> Open this file for delete </p> </div> <pre class="source"> <span class="cmt"># File P4table.rb, line 359</span> <span class="kw">def</span> delete <span class="kw">if</span> ( ! exists? ) raise( RuntimeError, <span class="str">"Can't delete non-existent file"</span>, caller ) <span class="kw">end</span> P4Global.tagged.run_sync P4Global.tagged.run_delete( depot_path() ) <span class="kw">end</span> </pre> <table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> <tr><td class="methodtitle"> <a name="M000024"></a> <b>read</b>() </td></tr> </table> <div class="description"> <p> Read the contents of the file (returns a String) </p> </div> <pre class="source"> <span class="cmt"># File P4table.rb, line 371</span> <span class="kw">def</span> read P4Global.tagged.run_sync f = File.open( ws_path, <span class="str">"r"</span> ) buf = f.read f.close <span class="kw">return</span> buf <span class="kw">end</span> </pre> <table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> <tr><td class="methodtitle"> <a name="M000025"></a> <b>write</b>( string ) </td></tr> </table> <div class="description"> <p> Write the contents of the file </p> </div> <pre class="source"> <span class="cmt"># File P4table.rb, line 382</span> <span class="kw">def</span> write( string ) P4Global.tagged.run_sync mkdir File.open( ws_path, <span class="str">"w"</span> ) { |f| f.write( string ) } <span class="kw">end</span> </pre> <table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> <tr><td class="methodtitle"> <a name="M000026"></a> <b>mkdir</b>() </td></tr> </table> <div class="description"> <p> Create the directory for the workspace file </p> </div> <pre class="source"> <span class="cmt"># File P4table.rb, line 391</span> <span class="kw">def</span> mkdir P4Global.tagged.run_sync dirs = ws_path.split( SEP ) dirs.pop dir = <span class="str">""</span> dirs.each <span class="kw">do</span> |d| dir += d + SEP Dir.mkdir( dir ) <span class="kw">unless</span> File.directory?( dir ) <span class="kw">end</span> <span class="kw">end</span> </pre> <table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> <tr><td class="methodtitle"> <a name="M000027"></a> <b>to_s</b>() </td></tr> </table> <div class="description"> <p> Render the filename as a string (we use depot syntax) </p> </div> <pre class="source"> <span class="cmt"># File P4table.rb, line 406</span> <span class="kw">def</span> to_s depot_file <span class="kw">end</span> </pre> </body>
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 3093 | Tony Smith |
Move docs for P4Table in preparation for upcoming docs for specsaver.rb |
||
#1 | 2396 | Tony Smith |
Add RDoc documentation for P4Table.rb. Very pretty. |