Module: Executioner::ClassMethods
- Defined in:
- lib/executioner.rb
Class Method Summary collapse
-
.find_executable(executable, advance_from = nil) ⇒ Object
Finds the first occurence of the specified executable in Executioner::SEARCH_PATHS.
Instance Method Summary collapse
-
#executable(executable, options = {}) ⇒ Object
Register an executable with the class.
Class Method Details
.find_executable(executable, advance_from = nil) ⇒ Object
Finds the first occurence of the specified executable in Executioner::SEARCH_PATHS
124 125 126 127 128 129 130 131 |
# File 'lib/executioner.rb', line 124 def find_executable(executable, advance_from = nil) search_paths = Executioner::SEARCH_PATHS search_paths = search_paths[(search_paths.index(advance_from) + 1)..-1] if advance_from if executable_in_path = search_paths.find { |path| File.exist?(File.join(path, executable)) } File.join(executable_in_path, executable) end end |
Instance Method Details
#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, ={}) [:switch_stdout_and_stderr] ||= false [:use_queue] ||= false executable = executable.to_s if executable.is_a? Symbol use_queue = .delete(:use_queue) if selection_proc = .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 = [:path] || find_executable(executable) end if executable_path if use_queue body = "queue(\"#{executable_path} \#{args}\")" else body = "execute(\"#{executable_path} \#{args}\", #{.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 |