public
Description: A dsl for cron
Clone URL: git://github.com/scrooloose/crondle.git
implemented Builder#with_options which takes a hash of timing options and 
a block of job definitions to apply them to
scrooloose (author)
Thu Apr 10 01:59:04 -0700 2008
commit  1b699df4eeef93ef99eee3e5fbd3f0d18bff413d
tree    a88176603abc3978b468dfceadaeb00938ff977c
parent  7d3550496a30c3240c3dd7ff384f0239e11c8ccb
...
5
6
7
8
 
9
10
11
...
18
19
20
 
 
 
 
 
 
21
22
23
24
 
 
 
 
 
25
26
...
5
6
7
 
8
9
10
11
...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
0
@@ -5,7 +5,7 @@ module Crondle
0
     end
0
 
0
     def job(cmd, options = {})
0
- j = Job.new(next_desc, cmd, options)
0
+ j = Job.new(next_desc, cmd, carry_over_options.merge(options))
0
       jobs << j
0
       j
0
     end
0
@@ -18,9 +18,20 @@ module Crondle
0
       @jobs ||= []
0
     end
0
 
0
+ def with_options(options, &block)
0
+ @carry_over_options = options
0
+ yield self
0
+ @carry_over_options.clear
0
+ end
0
+
0
     private
0
     def next_desc
0
       @next_desc || ""
0
     end
0
+
0
+ def carry_over_options
0
+ @carry_over_options || {}
0
+ end
0
+
0
   end
0
 end
...
60
61
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
64
...
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
0
@@ -60,5 +60,22 @@ module Crondle
0
       j.hour.should equal(0)
0
       j.minute.should equal(0)
0
     end
0
+
0
+ it "should apply the #with_options options to the Jobs defined in the #with_options block" do
0
+ b = Builder.new
0
+ b.with_options :month => 3 do
0
+ b.job("ls")
0
+ end
0
+ b.jobs.first.month.should eql(3)
0
+ end
0
+
0
+ it "should reset the carry over options once the #with_options block has ended" do
0
+ b = Builder.new
0
+ b.with_options :month => 3 do
0
+ end
0
+ b.job("ls")
0
+ b.jobs.first.month.should_not be
0
+ end
0
+
0
   end
0
 end

Comments

    No one has commented yet.