6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/robot-army/eval_builder.rb', line 6
def build(command)
proc, procargs, context, dependencies =
command.proc, command.args, command.context, command.dependencies
options = {}
proxies = {context.hash => context}
file, line = eval('[__FILE__, __LINE__]', proc.binding)
local_variables = eval('local_variables', proc.binding)
locals, lproxies = dump_values(local_variables) { |name,| eval(name, proc.binding) }
proxies.merge! lproxies
args, aproxies = dump_values(proc.arguments) { |_, i| procargs[i] }
proxies.merge! aproxies
dep_loading = "Marshal.load(#{Marshal.dump(dependencies).inspect}).load!"
proc = "proc{ #{proc.to_ruby_without_proc_wrapper} }"
messenger = "RobotArmy::Messenger.new($stdin, $stdout)"
context = "RobotArmy::Proxy.new(#{messenger}, #{context.hash.inspect})"
code = %{
#{dep_loading} # load dependencies
#{(locals+args).join("\n")} # all local variables
#{context}.__proxy_instance_eval(&#{proc}) # run the block
}
options[:file] = file
options[:line] = line
options[:code] = code
options[:user] = command.user if command.user
return options, proxies
end
|