58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/executioner.rb', line 58
def executable(executable, options={})
options[:switch_stdout_and_stderr] ||= false
options[:use_queue] ||= false
executable = executable.to_s if executable.is_a? Symbol
use_queue = options.delete(:use_queue)
if selection_proc = options.delete(:select_if)
advance_from = nil
while executable_path = find_executable(executable, advance_from)
break if selection_proc.call(executable_path)
advance_from = File.dirname(executable_path)
end
else
executable_path = options[:path] || find_executable(executable)
end
if executable_path
if use_queue
body = "queue(\"#{executable_path} \#{args}\")"
else
body = "execute(\"#{executable_path} \#{args}\", #{options.inspect}.merge(options))"
end
else
body = "raise Executioner::ExecutableNotFoundError, \"Unable to find the executable '#{executable}' in: #{Executioner::SEARCH_PATHS.join(', ')}\""
end
class_eval "def #{executable.gsub(/-/, '_')}(args, options = {}); #{body}; end", __FILE__, __LINE__
end
|