lib/executioner.rb in Fingertips-executioner-0.1.0 vs lib/executioner.rb in Fingertips-executioner-0.2.0
- old
+ new
@@ -14,11 +14,11 @@
klass.extend ClassMethods
end
end
def execute(command, options={})
- options[:switch_stdout_and_stderr] = false if options[:switch_stdout_and_stderr].nil?
+ command = "#{options[:env].map { |k,v| "#{k}='#{v}'" }.join(' ')} #{command}" if options[:env]
Executioner.logger.debug("Executing: `#{command}'") if Executioner.logger
output = nil
Open3.popen3(command) do |stdin, stdout, stderr|
@@ -54,12 +54,12 @@
@commands = []
end
module ClassMethods
def executable(executable, options={})
- options[:switch_stdout_and_stderr] = false if options[:switch_stdout_and_stderr].nil?
- options[:use_queue] = false if options[:use_queue].nil?
+ 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)
@@ -74,16 +74,16 @@
if executable_path
if use_queue
body = "queue(\"#{executable_path} \#{args}\")"
else
- body = "execute(\"#{executable_path} \#{args}\", #{options.inspect})"
+ 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); #{body}; end", __FILE__, __LINE__
+ class_eval "def #{executable.gsub(/-/, '_')}(args, options = {}); #{body}; end", __FILE__, __LINE__
end
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
\ No newline at end of file