TypeTrigger.html #2

  • //
  • guest/
  • tony_smith/
  • perforce/
  • P4Rubylib/
  • triggers/
  • doc/
  • classes/
  • TypeTrigger.html
  • View
  • Commits
  • Open Download .zip Download (11 KB)
<?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>Class: TypeTrigger</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">
        <h1>TypeTrigger <sup class="type-note">(Class)</sup></h1>
        <table class="header-table">
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/checktype_rb.html">
                checktype.rb
                </a>
				<br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="P4Trigger.html">
                P4Trigger
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

	<div id="bodyContent">


	<div id="contextContent">

		<div id="description">
			<p>
The trigger class itself. The main method in here is validate() which is
invoked from the super-class&#8217; parse_change() method.
</p>

		</div>


		<div id="method-list">
			<h2 class="section-bar">Methods</h2>

			<div class="name-list">
			<a href="#M000016">filetype</a>&nbsp;&nbsp;
			<a href="#M000015">new</a>&nbsp;&nbsp;
			<a href="#M000018">report</a>&nbsp;&nbsp;
			<a href="#M000017">validate</a>&nbsp;&nbsp;
			</div>
		</div>




			

	</div>



		<!-- if includes -->


		<!-- if method_list -->
		<div id="methods">
			<h2 class="section-bar">Public Class methods</h2>

			<div id="method-M000015" class="method-detail">
				<a name="M000015"></a>

				<div class="method-heading">
					<a href="#M000015" class="method-signature">
					<span class="method-name">new</span><span class="method-args">( max_errors )</span>
					</a>
				</div>
			
				<div class="method-description">
					<p><a class="source-toggle" href="#"
					  onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
					<div class="method-source-code" id="M000015-source">
<pre>
    <span class="ruby-comment cmt"># File checktype.rb, line 78</span>
78:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>( <span class="ruby-identifier">max_errors</span> )
79:         <span class="ruby-ivar">@max_errors</span> = <span class="ruby-identifier">max_errors</span>
80:         <span class="ruby-keyword kw">super</span>()
81:     <span class="ruby-keyword kw">end</span>
</pre>
					</div>
				</div>
			</div>

			<h2 class="section-bar">Public Instance methods</h2>

			<div id="method-M000016" class="method-detail">
				<a name="M000016"></a>

				<div class="method-heading">
					<a href="#M000016" class="method-signature">
					<span class="method-name">filetype</span><span class="method-args">( depot_file )</span>
					</a>
				</div>
			
				<div class="method-description">
					<p>
Method to return the expected filetype given a filename. Returns nil if no
specific filetype has been mandated.
</p>
					<p><a class="source-toggle" href="#"
					  onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
					<div class="method-source-code" id="M000016-source">
<pre>
     <span class="ruby-comment cmt"># File checktype.rb, line 97</span>
 97:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">filetype</span>( <span class="ruby-identifier">depot_file</span> )
 98:         <span class="ruby-identifier">ext</span> = <span class="ruby-identifier">depot_file</span>.<span class="ruby-identifier">sub</span>( <span class="ruby-regexp re">/.*\.(.*)/</span>, <span class="ruby-value str">'\1'</span> )
 99:         <span class="ruby-identifier">ext</span> = <span class="ruby-identifier">ext</span>.<span class="ruby-identifier">downcase</span>
100:         <span class="ruby-constant">TYPEMAP</span>[ <span class="ruby-identifier">ext</span> ]
101:     <span class="ruby-keyword kw">end</span>
</pre>
					</div>
				</div>
			</div>

			<div id="method-M000018" class="method-detail">
				<a name="M000018"></a>

				<div class="method-heading">
					<a href="#M000018" class="method-signature">
					<span class="method-name">report</span><span class="method-args">( badfiles )</span>
					</a>
				</div>
			
				<div class="method-description">
					<p>
Method to report the error to the user. Just formats the error message and
sends it. We only report the first @max_errors bad files. On a large
changelist they&#8217;ll be grateful for that.
</p>
					<p><a class="source-toggle" href="#"
					  onclick="toggleCode('M000018-source');return false;">[Source]</a></p>
					<div class="method-source-code" id="M000018-source">
<pre>
     <span class="ruby-comment cmt"># File checktype.rb, line 132</span>
132:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">report</span>( <span class="ruby-identifier">badfiles</span> )
133:         <span class="ruby-identifier">errors</span> = <span class="ruby-value">0</span>
134:         <span class="ruby-identifier">msg</span> = @<span class="ruby-ivar">@USER_MESSAGE</span>
135:         <span class="ruby-identifier">badfiles</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span>
136:             <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
137:             <span class="ruby-identifier">type</span> = <span class="ruby-identifier">filetype</span>( <span class="ruby-identifier">file</span>.<span class="ruby-identifier">depot_file</span> )
138:             <span class="ruby-identifier">msg</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">sprintf</span>( @<span class="ruby-ivar">@BADFILE_FORMAT</span>, 
139:                            <span class="ruby-identifier">file</span>.<span class="ruby-identifier">depot_file</span>, 
140:                             <span class="ruby-identifier">file</span>.<span class="ruby-identifier">revisions</span>[ <span class="ruby-value">0</span> ].<span class="ruby-identifier">type</span>,
141:                             <span class="ruby-identifier">type</span>.<span class="ruby-identifier">msg</span>
142:                           )
143:             <span class="ruby-identifier">errors</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
144:             <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> ( <span class="ruby-identifier">errors</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-ivar">@max_errors</span> )
145: 
146:         <span class="ruby-keyword kw">end</span>
147:         <span class="ruby-identifier">message</span>( <span class="ruby-identifier">msg</span> )
148:     <span class="ruby-keyword kw">end</span>
</pre>
					</div>
				</div>
			</div>

			<div id="method-M000017" class="method-detail">
				<a name="M000017"></a>

				<div class="method-heading">
					<a href="#M000017" class="method-signature">
					<span class="method-name">validate</span><span class="method-args">()</span>
					</a>
				</div>
			
				<div class="method-description">
					<p>
Enforce type checking. Basic algorithm is that we iterate over the typemap
and match each extension against the depot file. If they match, we check
the type.
</p>
					<p><a class="source-toggle" href="#"
					  onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
					<div class="method-source-code" id="M000017-source">
<pre>
     <span class="ruby-comment cmt"># File checktype.rb, line 106</span>
106:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">validate</span>()
107: 
108:         <span class="ruby-comment cmt"># First gather the list of bad files</span>
109:         <span class="ruby-identifier">badlist</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
110:         <span class="ruby-identifier">change</span>.<span class="ruby-identifier">each_file</span> <span class="ruby-keyword kw">do</span>
111:             <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
112:             <span class="ruby-comment cmt"># Ignore files not open for add</span>
113:             <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">unless</span> ( <span class="ruby-identifier">file</span>.<span class="ruby-identifier">revisions</span>[ <span class="ruby-value">0</span> ].<span class="ruby-identifier">action</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;add&quot;</span> )
114:             
115:             <span class="ruby-identifier">type</span> = <span class="ruby-identifier">filetype</span>( <span class="ruby-identifier">file</span>.<span class="ruby-identifier">depot_file</span> )
116:             <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">type</span>
117: 
118:             <span class="ruby-identifier">basetype</span> = <span class="ruby-identifier">file</span>.<span class="ruby-identifier">revisions</span>[ <span class="ruby-value">0</span> ].<span class="ruby-identifier">type</span>.<span class="ruby-identifier">sub</span>( <span class="ruby-regexp re">/\+.*/</span>, <span class="ruby-value str">&quot;&quot;</span> )
119:             <span class="ruby-keyword kw">if</span> ( <span class="ruby-operator">!</span> <span class="ruby-identifier">type</span>.<span class="ruby-identifier">match</span>( <span class="ruby-identifier">basetype</span> ) )
120:                 <span class="ruby-identifier">badlist</span>.<span class="ruby-identifier">push</span>( <span class="ruby-identifier">file</span> )
121:             <span class="ruby-keyword kw">end</span>
122:         <span class="ruby-keyword kw">end</span>
123: 
124:         <span class="ruby-comment cmt"># Now report any problems to the user</span>
125:         <span class="ruby-identifier">report</span>( <span class="ruby-identifier">badlist</span> ) <span class="ruby-keyword kw">if</span> ( <span class="ruby-operator">!</span> <span class="ruby-identifier">badlist</span>.<span class="ruby-identifier">empty?</span> )
126:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">badlist</span>.<span class="ruby-identifier">empty?</span>
127:     <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
#3 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.
#2 4640 Tony Smith Add a sample post-commit trigger that can be used to keep a master
and slave branch in sync.
#1 3637 Tony Smith Add RDoc documentation to the sample triggers.