Class: Pinoccio::FunctionCommands
Instance Method Summary
collapse
#execute, #get, #initialize, #run
Instance Method Details
#add(name, body = nil) ⇒ Object
327
328
329
330
331
|
# File 'lib/commands.rb', line 327
def add(name, body=nil)
body = name if body.nil?
body = "function #{name} { #{body} }" unless body =~ /^function /
execute(body)
end
|
#list ⇒ Object
301
302
303
304
305
306
307
308
|
# File 'lib/commands.rb', line 301
def list
ls = run('ls')
ls.split(/\r?\n/).reduce({}) do |hsh, fn|
matches = fn.match(/function ([a-z0-9]+) \{/)
hsh[matches[1]] = fn
hsh
end
end
|
#pid_for(fn) ⇒ Object
337
338
339
340
341
|
# File 'lib/commands.rb', line 337
def pid_for(fn)
process = running.find {|p| p[:function].to_s == fn.to_s }
return process[:pid] if process
nil
end
|
#remove(fn) ⇒ Object
310
311
312
|
# File 'lib/commands.rb', line 310
def remove(fn)
execute("rm #{fn}")
end
|
#remove_all ⇒ Object
314
315
316
|
# File 'lib/commands.rb', line 314
def remove_all
execute("rm *")
end
|
#repeat(fn, delay) ⇒ Object
318
319
320
|
# File 'lib/commands.rb', line 318
def repeat(fn, delay)
execute("run #{fn}, #{delay}")
end
|
#running ⇒ Object
343
344
345
346
347
348
349
|
# File 'lib/commands.rb', line 343
def running
ps = run("ps")
ps.split(/\r?\n/).map do |line|
pid, fn = *line.split(": ")
{pid: pid.to_i, function: fn}
end
end
|
#startup(body) ⇒ Object
333
334
335
|
# File 'lib/commands.rb', line 333
def startup(body)
add(:startup, body)
end
|
#stop(pid) ⇒ Object
322
323
324
325
|
# File 'lib/commands.rb', line 322
def stop(pid)
pid = pid_for(pid) unless pid.is_a?(Integer)
execute("stop #{pid}") if pid
end
|