18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/asciidoctor-diagram/util/which.rb', line 18
def which(parent_block, cmd, options = {})
attr_names = options[:attr_names] || [cmd]
cmd_var = '@' + attr_names[0]
already_defined = instance_variable_defined?(cmd_var)
if already_defined
cmd_path = instance_variable_get(cmd_var)
else
cmd_path = attr_names.map { |attr_name| parent_block.document.attributes[attr_name] }.find { |attr| !attr.nil? }
cmd_path = ::Asciidoctor::Diagram::Which.which(cmd, :path => options[:path]) unless cmd_path && File.executable?(cmd_path)
instance_variable_set(cmd_var, cmd_path)
if cmd_path.nil? && options.fetch(:raise_on_error, true)
raise "Could not find the '#{cmd}' executable in PATH; add it to the PATH or specify its location using the '#{attr_names[0]}' document attribute"
end
end
cmd_path
end
|