Skip to content

Commit

Permalink
Merge pull request #720 from kenhys/support-check_is_installed_by_gem
Browse files Browse the repository at this point in the history
Windows: support check_is_installed_by_gem
  • Loading branch information
mizzy authored Aug 24, 2020
2 parents 879c9fc + 42c4f74 commit a1bfdda
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/specinfra/backend/powershell/support/find_installed_gem.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function FindInstalledGem
{
param($gemName, $gemVersion)

$nameVer = $(Invoke-Expression "gem list --local" | Select-String "$gemName").Line
if ($nameVer.StartsWith($gemName)) {
if ($gemVersion) {
if ($nameVer.EndsWith("$gemVersion)")) {
$true
} else {
$false
}
} else {
$true
}
} else {
$false
}
}

8 changes: 8 additions & 0 deletions lib/specinfra/command/windows/base/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@ def check_is_installed(package, version=nil)
exec "(FindInstalledApplication -appName '#{package}' #{version_selection}) -eq $true"
end
end

def check_is_installed_by_gem(name, version=nil, gem_binary="gem")
version_selection = version.nil? ? "" : "-gemVersion '#{version}'"
Backend::PowerShell::Command.new do
using 'find_installed_gem.ps1'
exec "(FindInstalledGem -gemName '#{name}' #{version_selection}) -eq $true"
end
end
end
end

0 comments on commit a1bfdda

Please sign in to comment.