aboutsummaryrefslogtreecommitdiffstats
path: root/lib/alaveteli_external_command.rb
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2015-01-13 10:41:44 +0000
committerGareth Rees <gareth@mysociety.org>2015-01-27 16:12:42 +0000
commita47554c9b4509f2842d609d11191c9e5655ec765 (patch)
treed39926b5ed28b8fc320fa87e6ce48925fbdcc254 /lib/alaveteli_external_command.rb
parent21ef93f10d45a854fcb84ab5f69c3dad89b6d197 (diff)
Factor out find_program method.
Diffstat (limited to 'lib/alaveteli_external_command.rb')
-rw-r--r--lib/alaveteli_external_command.rb27
1 files changed, 14 insertions, 13 deletions
diff --git a/lib/alaveteli_external_command.rb b/lib/alaveteli_external_command.rb
index 086a461c8..79711328c 100644
--- a/lib/alaveteli_external_command.rb
+++ b/lib/alaveteli_external_command.rb
@@ -18,19 +18,7 @@ module AlaveteliExternalCommand
opts = args.pop
end
- if program_name =~ %r(^/)
- program_path = program_name
- else
- found = false
- AlaveteliConfiguration::utility_search_path.each do |d|
- program_path = File.join(d, program_name)
- if File.file? program_path and File.executable? program_path
- found = true
- break
- end
- end
- raise "Could not find #{program_name} in any of #{AlaveteliConfiguration::utility_search_path.join(', ')}" if !found
- end
+ program_path = find_program(program_name)
xc = ExternalCommand.new(program_path, *args)
if opts.has_key? :append_to
@@ -61,5 +49,18 @@ module AlaveteliExternalCommand
end
end
end
+
+ def find_program(program_name)
+ if program_name =~ %r(^/)
+ return program_name
+ else
+ search_path = AlaveteliConfiguration::utility_search_path
+ search_path.each do |d|
+ program_path = File.join(d, program_name)
+ return program_name if File.file? program_path and File.executable? program_path
+ end
+ raise "Could not find #{program_name} in any of #{search_path.join(', ')}"
+ end
+ end
end
end