Class: RobotArmy::TaskMaster

Inherits:
Thor
  • Object
show all
Defined in:
lib/robot-army/task_master.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.host(host = nil) ⇒ Object



3
4
5
6
# File 'lib/robot-army/task_master.rb', line 3

def self.host(host=nil)
  @host = host if host
  @host
end

Instance Method Details

#connectionObject



16
17
18
# File 'lib/robot-army/task_master.rb', line 16

def connection
  RobotArmy::GateKeeper.shared_instance.connect(host)
end

#hostObject



8
9
10
# File 'lib/robot-army/task_master.rb', line 8

def host
  self.class.host
end

#remote(host = self.host, &proc) ⇒ Object



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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/robot-army/task_master.rb', line 20

def remote(host=self.host, &proc)
  ##
  ## build the code to send it
  ##
  
  # fix stack traces
  file, line = eval('[__FILE__, __LINE__]', proc.binding)
  
  # include local variables
  locals = eval('local_variables', proc.binding).map do |name|
    "#{name} = Marshal.load(#{Marshal.dump(eval(name, proc.binding)).inspect})"
  end
  
  code = %{
    #{locals.join("\n")}  # all local variables
    #{proc.to_ruby(true)} # the proc itself
  }
  
  
  ##
  ## send the child a message
  ##
  
  connection.messenger.post(:command => :eval, :data => {
    :code => code, 
    :file => file, 
    :line => line
  })
  
  ##
  ## get and evaluate the response
  ##
  
  response = connection.messenger.get
  
  case response[:status]
  when 'ok'
    return response[:data]
  when 'error'
    raise response[:data]
  else
    raise RuntimeError, "Unknown response status from remote process: #{response[:status]}"
  end
end

#say(something) ⇒ Object



12
13
14
# File 'lib/robot-army/task_master.rb', line 12

def say(something)
  puts "** #{something}"
end