lib/makit/nuget.rb in makit-0.0.26 vs lib/makit/nuget.rb in makit-0.0.27

- old
+ new

@@ -1,57 +1,57 @@ -require "tmpdir" -# This module provides classes for the Makit gem. -module Makit - # This class provide methods for working with the Nuget package cache - # - # Example: - # - # Makit::Directory.cache("Google.Protobuf", "3.27.2") - # - # dotnet nuget locals all --list - # dotnet nuget locals all --clear - # - class NuGet - def self.get_cache_dir(package, version) - File.join(Makit::Directories::NUGET_PACKAGE_CACHE, package, version) - end - - def self.cache(package, version) - # if the package is already cached, there is nothing to do - if (!Dir.exist?(get_cache_dir(package, version))) - Dir.mktmpdir do |dir| - # Use the temp directory here - Dir.chdir(dir) do - system("dotnet new classlib -n ClassLib") - Dir.chdir("ClassLib") do - - # display a list of directories in the current directory - puts Dir.entries(Dir.pwd) - # display a list of files in the current directory - puts Dir.entries(Dir.pwd) - puts "dotnet add ClassLib.csproj package #{package} --version #{version}" - system("dotnet add ClassLib.csproj package #{package} --version #{version}") - end - end - # The directory and its contents will be removed automatically after the block - end - end - end - - def self.clear_cache(package, version) - if (Dir.exist?(get_cache_dir(package, version))) - FileUtils.rm_rf(get_cache_dir(package, version)) - end - end - - # get the latest version of the package - def self.get_latest_version(package) - dir = File.join(Makit::Directories::NUGET_PACKAGE_CACHE, package) - if (Dir.exist?(dir)) - versions = Dir.entries(dir).select { |entry| File.directory?(File.join(dir, entry)) && !(entry == "." || entry == "..") } - highest_version = Makit::Version::get_highest_version(versions) - return highest_version - end - nil - end - end -end +require "tmpdir" +# This module provides classes for the Makit gem. +module Makit + # This class provide methods for working with the Nuget package cache + # + # Example: + # + # Makit::Directory.cache("Google.Protobuf", "3.27.2") + # + # dotnet nuget locals all --list + # dotnet nuget locals all --clear + # + class NuGet + def self.get_cache_dir(package, version) + File.join(Makit::Directories::NUGET_PACKAGE_CACHE, package, version) + end + + def self.cache(package, version) + # if the package is already cached, there is nothing to do + if (!Dir.exist?(get_cache_dir(package, version))) + Dir.mktmpdir do |dir| + # Use the temp directory here + Dir.chdir(dir) do + system("dotnet new classlib -n ClassLib") + Dir.chdir("ClassLib") do + + # display a list of directories in the current directory + puts Dir.entries(Dir.pwd) + # display a list of files in the current directory + puts Dir.entries(Dir.pwd) + puts "dotnet add ClassLib.csproj package #{package} --version #{version}" + system("dotnet add ClassLib.csproj package #{package} --version #{version}") + end + end + # The directory and its contents will be removed automatically after the block + end + end + end + + def self.clear_cache(package, version) + if (Dir.exist?(get_cache_dir(package, version))) + FileUtils.rm_rf(get_cache_dir(package, version)) + end + end + + # get the latest version of the package + def self.get_latest_version(package) + dir = File.join(Makit::Directories::NUGET_PACKAGE_CACHE, package) + if (Dir.exist?(dir)) + versions = Dir.entries(dir).select { |entry| File.directory?(File.join(dir, entry)) && !(entry == "." || entry == "..") } + highest_version = Makit::Version::get_highest_version(versions) + return highest_version + end + nil + end + end +end