Module: Physique::ToolLocator
- Includes:
- Albacore::Logging
- Included in:
- FluentMigrator::Config, SqlCmd::Config, TasksBuilder
- Defined in:
- lib/physique/tool_locator.rb
Defined Under Namespace
Classes: ToolNotFoundError
Constant Summary collapse
- @@registered_tools =
{}
Instance Method Summary collapse
-
#locate_tool(paths, options = {}) ⇒ Object
Allows you to locate a tool on disk given a file specification.
- #lookup_tool(name, project, package_folder) ⇒ Object
- #register_tool(name, executable, nuget_package = nil, nuget_path = nil) ⇒ Object
- #which(exe) ⇒ Object
Instance Method Details
#locate_tool(paths, options = {}) ⇒ Object
Allows you to locate a tool on disk given a file specification. For example…
locate_tool 'C:/Program Files/Microsoft SQL Server/**/Tools/Binn/SQLCMD.EXE'
The tool sorts any matching executables in descending order to that the most recent version is returned. To change this behavior call the method with the reverse option.
locate_tool 'C:/path/to/**/tool.exe', find_latest: false
Throws a ToolNotFoundError if no tool could be found.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/physique/tool_locator.rb', line 26 def locate_tool(paths, = {}) # FileList only correctly handles forward-slashes, even on Windows paths = paths.gsub('\\', '/') debug { "Extracting paths from the following pattern #{paths}" } paths = FileList[paths] unless paths.respond_to?(:each) debug { "Attempting to locate tool in the following paths #{paths}" } opts = Map.() opts = opts.apply :find_latest => true paths = paths.collect { |p| which(p) }.compact.sort paths = paths.reverse if opts[:find_latest] tool = paths.first raise ToolNotFoundError, "Could not find tool in the following paths: \n #{paths}" if tool.nil? tool end |
#lookup_tool(name, project, package_folder) ⇒ Object
13 14 |
# File 'lib/physique/tool_locator.rb', line 13 def lookup_tool(name, project, package_folder) end |
#register_tool(name, executable, nuget_package = nil, nuget_path = nil) ⇒ Object
10 11 |
# File 'lib/physique/tool_locator.rb', line 10 def register_tool(name, executable, nuget_package = nil, nuget_path = nil) end |
#which(exe) ⇒ Object
44 45 46 |
# File 'lib/physique/tool_locator.rb', line 44 def which(exe) Albacore::CrossPlatformCmd.which(exe) ? exe : nil; end |