1
1
class Task
2
- def initialize ( name , doc , action , dir )
2
+ def initialize ( name , doc , block , dir )
3
3
@name = name
4
4
@doc = doc
5
- @action = action
5
+ @block = block
6
6
@dir = dir
7
7
end
8
8
9
- def run ( context , *args )
9
+ def run ( manager , *args )
10
+ block_self = eval ( 'self' , @block . binding )
11
+ context = TaskRunContext . new ( manager , block_self )
12
+
10
13
Dir . chdir ( @dir ) do
11
- context . instance_exec ( *args , &@action )
14
+ context . instance_exec ( *args , &@block )
12
15
end
13
16
end
14
17
@@ -34,7 +37,6 @@ def initialize(name)
34
37
class TaskManager
35
38
def initialize
36
39
@tasks = { }
37
- @run_context = TaskRunContext . new ( self )
38
40
end
39
41
40
42
def load ( file )
@@ -59,7 +61,7 @@ def run_task(name, *args)
59
61
raise TaskNotFoundError . new ( name )
60
62
end
61
63
62
- task . run ( @run_context , *args )
64
+ task . run ( self , *args )
63
65
end
64
66
end
65
67
@@ -89,13 +91,18 @@ def run(name, &block)
89
91
end
90
92
91
93
class TaskRunContext
92
- def initialize ( manager )
94
+ def initialize ( manager , block_self )
93
95
@manager = manager
96
+ @self = block_self
94
97
end
95
98
96
99
def run ( name , *args )
97
100
@manager . run_task ( name , *args )
98
101
end
102
+
103
+ def method_missing ( method , *args , &block )
104
+ @self . send ( method , *args , &block )
105
+ end
99
106
end
100
107
101
108
def find_runfile
0 commit comments