Method: Executioner::ClassMethods#executable

Defined in:
lib/executioner.rb

#executable(executable, options = {}) ⇒ Object

Register an executable with the class.

executable :ppane

You can configure the environment to use for each call to the executable.

executable :rails, :env => { 'RAILS_ENV' => 'production' }

In case the executable is outside regular paths, you can specify a particular path.

executable :heap, :path => '/Developer/usr/bin/heap'

The method you use to call the binary returns it’s output in a a string sometimes the useful information is in stderr instead of stdout. This happens sometimes in application which show progress. You can switch the output streams to capture stderr instead of stdout.

executable :lame, :switch_stdout_and_stderr => true

If you have some particular need to select a specific path over another you can select it using a proc.

executable :gcc, :select_if => { |e| File.ftype(e) != 'link' }
executable :gcc, :select_if => { |e| e.start_with?('/Developer') }

Both symbols and strings are allowed for names.

executable 'aclocal-1.10'


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/executioner.rb', line 93

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