11class Task
2- def initialize ( name , doc , action , dir )
2+ def initialize ( name , doc , block , dir )
33 @name = name
44 @doc = doc
5- @action = action
5+ @block = block
66 @dir = dir
77 end
88
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+
1013 Dir . chdir ( @dir ) do
11- context . instance_exec ( *args , &@action )
14+ context . instance_exec ( *args , &@block )
1215 end
1316 end
1417
@@ -34,7 +37,6 @@ def initialize(name)
3437class TaskManager
3538 def initialize
3639 @tasks = { }
37- @run_context = TaskRunContext . new ( self )
3840 end
3941
4042 def load ( file )
@@ -59,7 +61,7 @@ def run_task(name, *args)
5961 raise TaskNotFoundError . new ( name )
6062 end
6163
62- task . run ( @run_context , *args )
64+ task . run ( self , *args )
6365 end
6466end
6567
@@ -89,13 +91,18 @@ def run(name, &block)
8991end
9092
9193class TaskRunContext
92- def initialize ( manager )
94+ def initialize ( manager , block_self )
9395 @manager = manager
96+ @self = block_self
9497 end
9598
9699 def run ( name , *args )
97100 @manager . run_task ( name , *args )
98101 end
102+
103+ def method_missing ( method , *args , &block )
104+ @self . send ( method , *args , &block )
105+ end
99106end
100107
101108def find_runfile
0 commit comments