Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* Changed find APIs to allow RegEx

* Updated unit tests and documentation
* Bumped npm version
  • Loading branch information...
commit cfe18c4dcaba9351742641c5986c6fde33c7e13b 1 parent b817f39
Blagovest Dachev authored
127  index.html
@@ -336,7 +336,7 @@
336 336
 </tr>
337 337
 <tr class="code">
338 338
 <td class="docs">
339  
-<p>Returns a list of jobs (substring) matching the specified command.</p>
  339
+<p>Returns a list of jobs matching the specified command.</p>
340 340
 
341 341
 <h2>Examples</h2>
342 342
 
@@ -351,16 +351,16 @@
351 351
 
352 352
 <h2></h2>
353 353
 
354  
-<ul><li><p><strong>param</strong>: <em>String</em>  <strong>command</strong></p></li><li><p><strong>return</strong>: <em>Array[CronJob]</em> </p><p> </p></li></ul>
  354
+<ul><li><p><strong>param</strong>: <em>String | RegEx</em>  <strong>pattern</strong></p></li><li><p><strong>return</strong>: <em>Array[CronJob]</em> </p><p> </p></li></ul>
355 355
 </td>
356 356
 <td class="code">
357  
-<pre><code><span class="this">this</span>.<span class="variable">findCommand</span> = <span class="keyword">function</span>(<span class="variable">command</span>) {
  357
+<pre><code><span class="this">this</span>.<span class="variable">findCommand</span> = <span class="keyword">function</span>(<span class="variable">pattern</span>) {
358 358
         <span class="keyword">var</span> <span class="variable">results</span> = [];
359 359
         
360 360
         <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="number integer">0</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">jobs</span>.<span class="variable">length</span>; <span class="variable">i</span>++) {
361 361
             <span class="keyword">var</span> <span class="variable">job</span> = <span class="variable">jobs</span>[<span class="variable">i</span>];
362 362
             
363  
-            <span class="keyword">if</span> (<span class="variable">job</span>.<span class="variable">command</span>().<span class="variable">match</span>(<span class="variable">command</span>)) {
  363
+            <span class="keyword">if</span> (<span class="variable">job</span>.<span class="variable">command</span>().<span class="variable">match</span>(<span class="variable">pattern</span>)) {
364 364
                 <span class="variable">results</span>.<span class="variable">push</span>(<span class="variable">job</span>);
365 365
             }
366 366
         }
@@ -371,7 +371,7 @@
371 371
 </tr>
372 372
 <tr class="code">
373 373
 <td class="docs">
374  
-<p>Returns a list of jobs (substring) matching the specified inline comment.</p>
  374
+<p>Returns a list of jobs matching the specified inline comment.</p>
375 375
 
376 376
 <h2>Examples</h2>
377 377
 
@@ -386,16 +386,16 @@
386 386
 
387 387
 <h2></h2>
388 388
 
389  
-<ul><li><p><strong>param</strong>: <em>String</em>  <strong>comment</strong></p></li><li><p><strong>return</strong>: <em>Array[CronJob]</em> </p><p> </p></li></ul>
  389
+<ul><li><p><strong>param</strong>: <em>String | RegEx</em>  <strong>pattern</strong></p></li><li><p><strong>return</strong>: <em>Array[CronJob]</em> </p><p> </p></li></ul>
390 390
 </td>
391 391
 <td class="code">
392  
-<pre><code><span class="this">this</span>.<span class="variable">findComment</span> = <span class="keyword">function</span>(<span class="variable">comment</span>) {
  392
+<pre><code><span class="this">this</span>.<span class="variable">findComment</span> = <span class="keyword">function</span>(<span class="variable">pattern</span>) {
393 393
         <span class="keyword">var</span> <span class="variable">results</span> = [];
394 394
         
395 395
         <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="number integer">0</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">jobs</span>.<span class="variable">length</span>; <span class="variable">i</span>++) {
396 396
             <span class="keyword">var</span> <span class="variable">job</span> = <span class="variable">jobs</span>[<span class="variable">i</span>];
397 397
             
398  
-            <span class="keyword">if</span> (<span class="variable">job</span>.<span class="variable">comment</span>().<span class="variable">indexOf</span>(<span class="variable">comment</span>) &<span class="variable">gt</span>;= <span class="number integer">0</span>) {
  398
+            <span class="keyword">if</span> (<span class="variable">job</span>.<span class="variable">comment</span>().<span class="variable">match</span>(<span class="variable">pattern</span>)) {
399 399
                 <span class="variable">results</span>.<span class="variable">push</span>(<span class="variable">job</span>);
400 400
             }
401 401
         }
@@ -482,7 +482,7 @@
482 482
 <pre><code><span class="keyword">function</span> <span class="class">CronJob</span>(<span class="variable">line</span>, <span class="variable">c</span>, <span class="variable">m</span>) {
483 483
     <span class="keyword">var</span> <span class="variable">self</span>    = <span class="this">this</span>,
484 484
         <span class="variable">command</span> = <span class="keyword">null</span>,
485  
-        <span class="variable">meta</span>    = <span class="variable">m</span> || <span class="string">''</span>,
  485
+        <span class="variable">comment</span> = <span class="keyword">null</span>,
486 486
         <span class="variable">valid</span>   = <span class="variable">false</span>,
487 487
         <span class="variable">slots</span>   = [],
488 488
         <span class="variable">special</span> = <span class="variable">false</span>;</code></pre>
@@ -558,8 +558,8 @@
558 558
         }
559 559
         
560 560
         <span class="keyword">var</span> <span class="variable">result</span> = <span class="variable">time</span> + <span class="string">' '</span> + <span class="variable">command</span>.<span class="variable">toString</span>()
561  
-        <span class="keyword">if</span> (<span class="variable">meta</span>) {
562  
-            <span class="variable">result</span> += <span class="string">' #'</span> + <span class="variable">meta</span>;
  561
+        <span class="keyword">if</span> (<span class="variable">comment</span>.<span class="variable">toString</span>() != <span class="string">''</span>) {
  562
+            <span class="variable">result</span> += <span class="string">' #'</span> + <span class="variable">comment</span>.<span class="variable">toString</span>();
563 563
         }
564 564
         
565 565
         <span class="keyword">return</span> <span class="variable">result</span>;
@@ -745,7 +745,7 @@
745 745
 </tr>
746 746
 <tr class="code">
747 747
 <td class="docs">
748  
-<p>CronCommand getter/setter.</p>
  748
+<p>Command getter/setter.</p>
749 749
 
750 750
 <h2>Examples</h2>
751 751
 
@@ -774,7 +774,7 @@
774 774
 </tr>
775 775
 <tr class="code">
776 776
 <td class="docs">
777  
-<p>comment getter/setter.</p>
  777
+<p>Comment getter/setter.</p>
778 778
 
779 779
 <h2>Examples</h2>
780 780
 
@@ -792,12 +792,12 @@
792 792
 <ul><li><p><strong>param</strong>: <em>String</em>  <strong>[comment]</strong></p></li><li><p><strong>return</strong>: <em>String</em> </p><p> </p></li></ul>
793 793
 </td>
794 794
 <td class="code">
795  
-<pre><code><span class="this">this</span>.<span class="variable">comment</span> = <span class="keyword">function</span>(<span class="variable">m</span>) {
796  
-        <span class="keyword">if</span> (<span class="variable">m</span>) {
797  
-            <span class="variable">meta</span> = <span class="variable">m</span>;
  795
+<pre><code><span class="this">this</span>.<span class="variable">comment</span> = <span class="keyword">function</span>(<span class="variable">c</span>) {
  796
+        <span class="keyword">if</span> (<span class="variable">c</span>) {
  797
+            <span class="variable">comment</span> = <span class="keyword">new</span> <span class="class">CronComment</span>(<span class="variable">c</span>.<span class="variable">toString</span>());
798 798
         }
799 799
         
800  
-        <span class="keyword">return</span> <span class="variable">meta</span>;
  800
+        <span class="keyword">return</span> <span class="variable">comment</span>.<span class="variable">toString</span>();
801 801
     }</code></pre>
802 802
 </td>
803 803
 </tr>
@@ -1234,7 +1234,7 @@
1234 1234
 </tr>
1235 1235
 <tr class="code">
1236 1236
 <td class="docs">
1237  
-<p>Returns true if the string that was passed occurs somewhere in this command.</p>
  1237
+<p>Returns true if the pattern that was passed matches this command.</p>
1238 1238
 
1239 1239
 <h2>Examples</h2>
1240 1240
 
@@ -1243,20 +1243,23 @@
1243 1243
 
1244 1244
     var jobs = tab.findCommand('ls -l /');
1245 1245
     for (var i = 0; i &lt; jobs.length; i++) {
1246  
-        // false
1247  
-        console.log(jobs[i].command().match('pwd'));
  1246
+        // true
  1247
+        console.log(jobs[i].command().match('ls -l /'));
1248 1248
     }
1249 1249
 });</code></pre>
1250 1250
 
1251 1251
 <h2></h2>
1252 1252
 
1253  
-<ul><li><p><strong>param</strong>: <em>String</em>  <strong>line</strong></p></li><li><p><strong>return</strong>: <em>Boolean</em> </p><p> </p></li></ul>
  1253
+<ul><li><p><strong>param</strong>: <em>String | RegEx</em>  <strong>pattern</strong></p></li><li><p><strong>return</strong>: <em>Boolean</em> </p><p> </p></li></ul>
1254 1254
 </td>
1255 1255
 <td class="code">
1256  
-<pre><code><span class="this">this</span>.<span class="variable">match</span> = <span class="keyword">function</span>(<span class="variable">line</span>) {
1257  
-        <span class="keyword">if</span> (<span class="variable">command</span>.<span class="variable">indexOf</span>(<span class="variable">line</span>) &<span class="variable">gt</span>;= <span class="number integer">0</span>) {
  1256
+<pre><code><span class="this">this</span>.<span class="variable">match</span> = <span class="keyword">function</span>(<span class="variable">pattern</span>) {
  1257
+        <span class="keyword">if</span> ((<span class="variable">pattern</span> <span class="variable">instanceof</span> <span class="class">String</span>) == <span class="variable">true</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">command</span>.<span class="variable">indexOf</span>(<span class="variable">pattern</span>) &<span class="variable">gt</span>;= <span class="number integer">0</span>) {
1258 1258
             <span class="keyword">return</span> <span class="variable">true</span>;
1259 1259
         }
  1260
+        <span class="keyword">if</span> ((<span class="variable">pattern</span> <span class="variable">instanceof</span> <span class="class">RegEx</span>) == <span class="variable">true</span>) {
  1261
+            <span class="keyword">return</span> <span class="variable">pattern</span>.<span class="variable">test</span>(<span class="variable">command</span>);
  1262
+        }
1260 1263
         
1261 1264
         <span class="keyword">return</span> <span class="variable">false</span>;
1262 1265
     }</code></pre>
@@ -1287,5 +1290,83 @@
1287 1290
     }
1288 1291
 }</code></pre>
1289 1292
 </td>
  1293
+</tr>
  1294
+<tr class="code">
  1295
+<td class="docs">
  1296
+<ul><li><strong>class</strong>: <em>CronComment</em></li></ul>
  1297
+
  1298
+<p>A JavaScript representation of the inline comment part of a cron job.</p>
  1299
+
  1300
+<h2>Examples</h2>
  1301
+
  1302
+<pre><code>var comment = new CronComment('run this on the weekend');</code></pre>
  1303
+
  1304
+<h2></h2>
  1305
+
  1306
+<ul><li><p><strong>param</strong>: <em>String</em>  <strong>line</strong></p></li></ul>
  1307
+</td>
  1308
+<td class="code">
  1309
+<pre><code><span class="keyword">function</span> <span class="class">CronComment</span>(<span class="variable">line</span>) {
  1310
+    <span class="keyword">var</span> <span class="variable">comment</span> = <span class="variable">line</span>;</code></pre>
  1311
+</td>
  1312
+</tr>
  1313
+<tr class="code">
  1314
+<td class="docs">
  1315
+<p>Returns true if the pattern that was passed matches this comment.</p>
  1316
+
  1317
+<h2>Examples</h2>
  1318
+
  1319
+<pre><code>new CronTab(function(err, tab) {
  1320
+    if (err) { console.log(err); process.exit(1); }
  1321
+
  1322
+    var jobs = tab.findComment('run this on the weekend');
  1323
+    for (var i = 0; i &lt; jobs.length; i++) {
  1324
+        // true
  1325
+        console.log(jobs[i].comment().match('run this on the weekend'));
  1326
+    }
  1327
+});</code></pre>
  1328
+
  1329
+<h2></h2>
  1330
+
  1331
+<ul><li><p><strong>param</strong>: <em>String | RegEx</em>  <strong>pattern</strong></p></li><li><p><strong>return</strong>: <em>Boolean</em> </p><p> </p></li></ul>
  1332
+</td>
  1333
+<td class="code">
  1334
+<pre><code><span class="this">this</span>.<span class="variable">match</span> = <span class="keyword">function</span>(<span class="variable">pattern</span>) {
  1335
+        <span class="keyword">if</span> ((<span class="variable">pattern</span> <span class="variable">instanceof</span> <span class="class">String</span>) == <span class="variable">true</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">comment</span>.<span class="variable">indexOf</span>(<span class="variable">pattern</span>) &<span class="variable">gt</span>;= <span class="number integer">0</span>) {
  1336
+            <span class="keyword">return</span> <span class="variable">true</span>;
  1337
+        }
  1338
+        <span class="keyword">if</span> ((<span class="variable">pattern</span> <span class="variable">instanceof</span> <span class="class">RegEx</span>) == <span class="variable">true</span>) {
  1339
+            <span class="keyword">return</span> <span class="variable">pattern</span>.<span class="variable">test</span>(<span class="variable">comment</span>);
  1340
+        }
  1341
+        
  1342
+        <span class="keyword">return</span> <span class="variable">false</span>;
  1343
+    }</code></pre>
  1344
+</td>
  1345
+</tr>
  1346
+<tr class="code">
  1347
+<td class="docs">
  1348
+<p>Renders the object to a string as it would be written to the system.</p>
  1349
+
  1350
+<h2>Examples</h2>
  1351
+
  1352
+<pre><code>new CronTab(function(err, tab) {
  1353
+    if (err) { console.log(err); process.exit(1); }
  1354
+
  1355
+    var jobs = tab.findComment('run this on the weekend');
  1356
+    for (var i = 0; i &lt; jobs.length; i++) {
  1357
+        console.log(jobs[i].comment().toString());
  1358
+    }
  1359
+});</code></pre>
  1360
+
  1361
+<h2></h2>
  1362
+
  1363
+<ul><li><p><strong>return</strong>: <em>String</em> </p><p> </p></li></ul>
  1364
+</td>
  1365
+<td class="code">
  1366
+<pre><code><span class="this">this</span>.<span class="variable">toString</span> = <span class="keyword">function</span>() {
  1367
+        <span class="keyword">return</span> <span class="variable">comment</span>;
  1368
+    }
  1369
+}</code></pre>
  1370
+</td>
1290 1371
 </tr>	</body>
1291 1372
 </html></tbody></table>
115  lib/index.js
@@ -196,7 +196,7 @@ function CronTab(u, cb) {
196 196
         return job;
197 197
     }
198 198
     /**
199  
-     * Returns a list of jobs (substring) matching the specified command.
  199
+     * Returns a list of jobs matching the specified command.
200 200
      * 
201 201
      * Examples:
202 202
      *     new CronTab(function(err, tab) {
@@ -208,16 +208,16 @@ function CronTab(u, cb) {
208 208
      *         }
209 209
      *     });
210 210
      *
211  
-     * @param {String} __command__
  211
+     * @param {String|RegEx} __pattern__
212 212
      * @return {Array[CronJob]}
213 213
      */
214  
-    this.findCommand = function(command) {
  214
+    this.findCommand = function(pattern) {
215 215
         var results = [];
216 216
         
217 217
         for (var i = 0; i < jobs.length; i++) {
218 218
             var job = jobs[i];
219 219
             
220  
-            if (job.command().match(command)) {
  220
+            if (job.command().match(pattern)) {
221 221
                 results.push(job);
222 222
             }
223 223
         }
@@ -225,7 +225,7 @@ function CronTab(u, cb) {
225 225
         return results;
226 226
     }
227 227
     /**
228  
-     * Returns a list of jobs (substring) matching the specified inline comment.
  228
+     * Returns a list of jobs matching the specified inline comment.
229 229
      * 
230 230
      * Examples:
231 231
      *     new CronTab(function(err, tab) {
@@ -237,16 +237,16 @@ function CronTab(u, cb) {
237 237
      *         }
238 238
      *     });
239 239
      *
240  
-     * @param {String} __comment__
  240
+     * @param {String|RegEx} __pattern__
241 241
      * @return {Array[CronJob]}
242 242
      */
243  
-    this.findComment = function(comment) {
  243
+    this.findComment = function(pattern) {
244 244
         var results = [];
245 245
         
246 246
         for (var i = 0; i < jobs.length; i++) {
247 247
             var job = jobs[i];
248 248
             
249  
-            if (job.comment().indexOf(comment) >= 0) {
  249
+            if (job.comment().match(pattern)) {
250 250
                 results.push(job);
251 251
             }
252 252
         }
@@ -459,7 +459,7 @@ function CronTab(u, cb) {
459 459
 function CronJob(line, c, m) {
460 460
     var self    = this,
461 461
         command = null,
462  
-        meta    = m || '',
  462
+        comment = null,
463 463
         valid   = false,
464 464
         slots   = [],
465 465
         special = false;
@@ -523,8 +523,8 @@ function CronJob(line, c, m) {
523 523
         }
524 524
         
525 525
         var result = time + ' ' + command.toString()
526  
-        if (meta) {
527  
-            result += ' #' + meta;
  526
+        if (comment.toString() != '') {
  527
+            result += ' #' + comment.toString();
528 528
         }
529 529
         
530 530
         return result;
@@ -660,7 +660,7 @@ function CronJob(line, c, m) {
660 660
         return slots[4];
661 661
     }
662 662
     /**
663  
-     * CronCommand getter/setter.
  663
+     * Command getter/setter.
664 664
      * 
665 665
      * Examples:
666 666
      *     new CronTab(function(err, tab) {
@@ -683,7 +683,7 @@ function CronJob(line, c, m) {
683 683
         return command.toString();
684 684
     }
685 685
     /**
686  
-     * comment getter/setter.
  686
+     * Comment getter/setter.
687 687
      * 
688 688
      * Examples:
689 689
      *     new CronTab(function(err, tab) {
@@ -698,12 +698,12 @@ function CronJob(line, c, m) {
698 698
      * @param {String} __[comment]__
699 699
      * @return {String}
700 700
      */
701  
-    this.comment = function(m) {
702  
-        if (m) {
703  
-            meta = m;
  701
+    this.comment = function(c) {
  702
+        if (c) {
  703
+            comment = new CronComment(c.toString());
704 704
         }
705 705
         
706  
-        return meta;
  706
+        return comment.toString();
707 707
     }
708 708
     /**
709 709
      * Renders the object to a string as it would be written to the system. See __render__.
@@ -760,7 +760,7 @@ function CronJob(line, c, m) {
760 760
             
761 761
             if (result && result.length > 0) {
762 762
                 command = new CronCommand(result[6]);
763  
-                meta    = result[8] || '';
  763
+                comment = new CronComment(result[8] || '');
764 764
                 valid   = true;
765 765
                 
766 766
                 setSlots(result.slice(1,6));
@@ -770,7 +770,7 @@ function CronJob(line, c, m) {
770 770
                 
771 771
                 if (result && result.length > 0 && SPECIALS[result[1]]) {
772 772
                     command = new CronCommand(result[2]);
773  
-                    meta    = result[4] || '';
  773
+                    comment = new CronComment(result[4] || '');
774 774
                     
775 775
                     var value = SPECIALS[result[1]];
776 776
                     if (value.indexOf('@') >= 0) {
@@ -786,6 +786,7 @@ function CronJob(line, c, m) {
786 786
         else if (c) {
787 787
             valid   = true;
788 788
             command = new CronCommand(c.toString());
  789
+            command = new CronCommand(m && m.toString() || '');
789 790
         }
790 791
     }
791 792
     
@@ -1219,7 +1220,7 @@ function CronCommand(line) {
1219 1220
     
1220 1221
     
1221 1222
     /**
1222  
-     * Returns true if the string that was passed occurs somewhere in this command.
  1223
+     * Returns true if the pattern that was passed matches this command.
1223 1224
      * 
1224 1225
      * Examples:
1225 1226
      *     new CronTab(function(err, tab) {
@@ -1227,18 +1228,21 @@ function CronCommand(line) {
1227 1228
      *         
1228 1229
      *         var jobs = tab.findCommand('ls -l /');
1229 1230
      *         for (var i = 0; i < jobs.length; i++) {
1230  
-     *             // false
1231  
-     *             console.log(jobs[i].command().match('pwd'));
  1231
+     *             // true
  1232
+     *             console.log(jobs[i].command().match('ls -l /'));
1232 1233
      *         }
1233 1234
      *     });
1234 1235
      *
1235  
-     * @param {String} __line__
  1236
+     * @param {String|RegEx} __pattern__
1236 1237
      * @return {Boolean}
1237 1238
      */
1238  
-    this.match = function(line) {
1239  
-        if (command.indexOf(line) >= 0) {
  1239
+    this.match = function(pattern) {
  1240
+        if ((pattern instanceof String) == true && command.indexOf(pattern) >= 0) {
1240 1241
             return true;
1241 1242
         }
  1243
+        if ((pattern instanceof RegEx) == true) {
  1244
+            return pattern.test(command);
  1245
+        }
1242 1246
         
1243 1247
         return false;
1244 1248
     }
@@ -1263,6 +1267,67 @@ function CronCommand(line) {
1263 1267
 }
1264 1268
 
1265 1269
 
  1270
+/**
  1271
+ * @class CronComment
  1272
+ * A JavaScript representation of the inline comment part of a cron job.
  1273
+ * 
  1274
+ * Examples:
  1275
+ *     var comment = new CronComment('run this on the weekend');
  1276
+ *
  1277
+ * @param {String} __line__
  1278
+ */
  1279
+function CronComment(line) {
  1280
+    var comment = line;
  1281
+    
  1282
+    
  1283
+    /**
  1284
+     * Returns true if the pattern that was passed matches this comment.
  1285
+     * 
  1286
+     * Examples:
  1287
+     *     new CronTab(function(err, tab) {
  1288
+     *         if (err) { console.log(err); process.exit(1); }
  1289
+     *         
  1290
+     *         var jobs = tab.findComment('run this on the weekend');
  1291
+     *         for (var i = 0; i < jobs.length; i++) {
  1292
+     *             // true
  1293
+     *             console.log(jobs[i].comment().match('run this on the weekend'));
  1294
+     *         }
  1295
+     *     });
  1296
+     *
  1297
+     * @param {String|RegEx} __pattern__
  1298
+     * @return {Boolean}
  1299
+     */
  1300
+    this.match = function(pattern) {
  1301
+        if ((pattern instanceof String) == true && comment.indexOf(pattern) >= 0) {
  1302
+            return true;
  1303
+        }
  1304
+        if ((pattern instanceof RegEx) == true) {
  1305
+            return pattern.test(comment);
  1306
+        }
  1307
+        
  1308
+        return false;
  1309
+    }
  1310
+    /**
  1311
+     * Renders the object to a string as it would be written to the system.
  1312
+     * 
  1313
+     * Examples:
  1314
+     *     new CronTab(function(err, tab) {
  1315
+     *         if (err) { console.log(err); process.exit(1); }
  1316
+     *         
  1317
+     *         var jobs = tab.findComment('run this on the weekend');
  1318
+     *         for (var i = 0; i < jobs.length; i++) {
  1319
+     *             console.log(jobs[i].comment().toString());
  1320
+     *         }
  1321
+     *     });
  1322
+     *
  1323
+     * @return {String}
  1324
+     */
  1325
+    this.toString = function() {
  1326
+        return comment;
  1327
+    }
  1328
+}
  1329
+
  1330
+
1266 1331
 /* @api private */
1267 1332
 function getKeys() {
1268 1333
     return Object.keys(this);
2  package.json
... ...
@@ -1,7 +1,7 @@
1 1
 {
2 2
   'name': 'crontab',
3 3
   'description': 'A module for reading, manipulating, and writing user crontabs with node.js',
4  
-  'version': '0.2.5',
  4
+  'version': '0.2.6',
5 5
   'author': 'Blagovest Dachev <blago@dachev.com>',
6 6
   'keywords': ['cron', 'crontab', 'schedule', 'system', 'run', 'process'],
7 7
   'main': './lib/index',
68  test/runner.js
@@ -344,6 +344,24 @@ var canParseSpecialSyntax = {
344 344
         }
345 345
     }
346 346
 };
  347
+var canParseCommands = {
  348
+    'can parse commands' : {
  349
+        topic: function() {
  350
+            mockChild.user = 'commands';
  351
+            return loadTabs('');
  352
+        },
  353
+        'should succeed loading':function(err, tab) {
  354
+            Assert.isNull(err);
  355
+            Assert.isObject(tab);
  356
+            Assert.isArray(tab.getJobs());
  357
+            Assert.equal(tab.getJobs().length, 1);
  358
+        },
  359
+        'command should match':function(err, tab) {
  360
+            var job = tab.getJobs()[0];
  361
+            Assert.equal(job.command(), '/usr/bin/env echo "check email"');
  362
+        }
  363
+    }
  364
+}
347 365
 var canParseInlineComments = {
348 366
     'can parse inline comments' : {
349 367
         topic: function() {
@@ -361,9 +379,9 @@ var canParseInlineComments = {
361 379
             Assert.equal(job.comment(), 'every business hour');
362 380
         }
363 381
     }
364  
-}
365  
-var canParseCommands = {
366  
-    'can parse commands' : {
  382
+};
  383
+var canFindJobsByCommand = {
  384
+    'can find jobs by command' : {
367 385
         topic: function() {
368 386
             mockChild.user = 'commands';
369 387
             return loadTabs('');
@@ -374,12 +392,46 @@ var canParseCommands = {
374 392
             Assert.isArray(tab.getJobs());
375 393
             Assert.equal(tab.getJobs().length, 1);
376 394
         },
377  
-        'command should match':function(err, tab) {
378  
-            var job = tab.getJobs()[0];
379  
-            Assert.equal(job.command(), '/usr/bin/env echo "check email"');
  395
+        'should find jobs by substring':function(err, tab) {
  396
+            var jobs = tab.findCommand('/usr/bin/env echo');
  397
+            
  398
+            Assert.isArray(jobs);
  399
+            Assert.equal(jobs.length, 1);
  400
+        },
  401
+        'should find jobs by regular expression':function(err, tab) {
  402
+            var jobs = tab.findCommand(/echo/);
  403
+            
  404
+            Assert.isArray(jobs);
  405
+            Assert.equal(jobs.length, 1);
380 406
         }
381 407
     }
382  
-}
  408
+};
  409
+var canFindJobsByComment = {
  410
+    'can find jobs by comment' : {
  411
+        topic: function() {
  412
+            mockChild.user = 'comments';
  413
+            return loadTabs('');
  414
+        },
  415
+        'should succeed loading':function(err, tab) {
  416
+            Assert.isNull(err);
  417
+            Assert.isObject(tab);
  418
+            Assert.isArray(tab.getJobs());
  419
+            Assert.equal(tab.getJobs().length, 1);
  420
+        },
  421
+        'should find jobs by substring':function(err, tab) {
  422
+            var jobs = tab.findComment('every business hour');
  423
+            
  424
+            Assert.isArray(jobs);
  425
+            Assert.equal(jobs.length, 1);
  426
+        },
  427
+        'should find jobs by regular expression':function(err, tab) {
  428
+            var jobs = tab.findComment(/business/);
  429
+            
  430
+            Assert.isArray(jobs);
  431
+            Assert.equal(jobs.length, 1);
  432
+        }
  433
+    }
  434
+};
383 435
 
384 436
 var Vows    = require('vows'),
385 437
     Assert  = require('assert'),
@@ -396,4 +448,6 @@ Vows.describe('crontab').
396 448
     addBatch(canParseSpecialSyntax).
397 449
     addBatch(canParseCommands).
398 450
     addBatch(canParseInlineComments).
  451
+    addBatch(canFindJobsByCommand).
  452
+    addBatch(canFindJobsByComment).
399 453
     export(module);

0 notes on commit cfe18c4

Please sign in to comment.
Something went wrong with that request. Please try again.