bin_path(name, exec_name = nil, *requirements)
public
Find the full path to the executable for gem
name. If the exec_name is not given, the gem’s
default_executable is chosen, otherwise the specified executable’s path is returned. requirements
allows you to specify specific gem versions.
Show source
def self.bin_path(name, exec_name = nil, *requirements)
raise ArgumentError, "you must supply exec_name" unless exec_name
requirements = Gem::Requirement.default if
requirements.empty?
dep = Gem::Dependency.new name, requirements
loaded = Gem.loaded_specs[name]
return loaded.bin_file exec_name if loaded && dep.matches_spec?(loaded)
specs = dep.matching_specs(true)
raise Gem::GemNotFoundException,
"can't find gem #{name} (#{requirements})" if specs.empty?
specs = specs.find_all { |spec|
spec.executables.include? exec_name
} if exec_name
unless spec = specs.last
msg = "can't find gem #{name} (#{requirements}) with executable #{exec_name}"
raise Gem::GemNotFoundException, msg
end
spec.bin_file exec_name
end