Skip to content

Commit 73a60c0

Browse files
committed
Fix bug where Runfile tasks could not access local scope.
1 parent cfb003a commit 73a60c0

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

runx.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
class 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)
3437
class 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
6466
end
6567

@@ -89,13 +91,18 @@ def run(name, &block)
8991
end
9092

9193
class 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
99106
end
100107

101108
def find_runfile

0 commit comments

Comments
 (0)