<?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">
<head>
<title>Class: TypeTrigger</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> TypeTrigger
</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/checktype_rb.html" class="aqua">
checktype.rb
</a>
<br />
</td>
</tr>
<tr>
<td class="small-title-font">Parent:</td>
<td class="small-title-font">
<a href="P4Trigger.html" class="aqua">
P4Trigger
</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- banner header -->
<div class="description"><p>
The trigger class itself. The main method in here is validate() which is
invoked from the super-class’ <a
href="P4Trigger.html#M000021">parse_change</a>() method.
</p>
</div>
<table summary="Methods" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Methods</td></tr>
</table>
<div class="name-list">
<a href="#M000011">filetype</a>
<a href="#M000010">new</a>
<a href="#M000013">report</a>
<a href="#M000012">validate</a>
</div>
<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="M000010"></a>
<b>new</b>( max_errors )
</td></tr>
</table>
<pre class="source">
<span class="cmt"># File checktype.rb, line 78</span>
<span class="kw">def</span> initialize( max_errors )
@max_errors = max_errors
<span class="kw">super</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="M000011"></a>
<b>filetype</b>( depot_file )
</td></tr>
</table>
<div class="description">
<p>
Method to return the expected filetype given a filename. Returns nil if no
specific filetype has been mandated.
</p>
</div>
<pre class="source">
<span class="cmt"># File checktype.rb, line 97</span>
<span class="kw">def</span> filetype( depot_file )
ext = depot_file.sub( <span class="re">/.*\.(.*)/</span>, <span class="str">'\1'</span> )
ext = ext.downcase
TYPEMAP[ ext ]
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000012"></a>
<b>validate</b>()
</td></tr>
</table>
<div class="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>
</div>
<pre class="source">
<span class="cmt"># File checktype.rb, line 106</span>
<span class="kw">def</span> validate()
<span class="cmt"># First gather the list of bad files</span>
badlist = Array.new
change.each_file <span class="kw">do</span>
|file|
<span class="cmt"># Ignore files not open for add</span>
<span class="kw">next</span> <span class="kw">unless</span> ( file.revisions[ 0 ].action == <span class="str">"add"</span> )
type = filetype( file.depot_file )
<span class="kw">next</span> <span class="kw">unless</span> type
basetype = file.revisions[ 0 ].type.sub( <span class="re">/\+.*/</span>, <span class="str">""</span> )
<span class="kw">if</span> ( ! type.match( basetype ) )
badlist.push( file )
<span class="kw">end</span>
<span class="kw">end</span>
<span class="cmt"># Now report any problems to the user</span>
report( badlist ) <span class="kw">if</span> ( ! badlist.empty? )
<span class="kw">return</span> badlist.empty?
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000013"></a>
<b>report</b>( badfiles )
</td></tr>
</table>
<div class="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’ll be grateful for that.
</p>
</div>
<pre class="source">
<span class="cmt"># File checktype.rb, line 132</span>
<span class="kw">def</span> report( badfiles )
errors = 0
msg = @@USER_MESSAGE
badfiles.each <span class="kw">do</span>
|file|
type = filetype( file.depot_file )
msg += sprintf( @@BADFILE_FORMAT,
file.depot_file,
file.revisions[ 0 ].type,
type.msg
)
errors += 1
<span class="kw">break</span> <span class="kw">if</span> ( errors >= @max_errors )
<span class="kw">end</span>
message( msg )
<span class="kw">end</span>
</pre>
</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. |