lib/pbmenv.rb in pbmenv-0.1.6 vs lib/pbmenv.rb in pbmenv-0.1.7
- old
+ new
@@ -1,8 +1,9 @@
# frozen_string_literal: true
require "securerandom"
+require "pathname"
require_relative "pbmenv/version"
require_relative "pbmenv/cli"
require_relative "pbmenv/pbm"
@@ -12,11 +13,11 @@
def self.available_versions
Pbmenv::PBM.new.available_versions.map { |x| x["name"] =~ /^v([\d.]+)/ && $1 }.compact
end
def self.versions
- Pbmenv::PBM.new.versions.map { |name| Pathname.new(name).basename.to_s =~ /^v([\d.]+)/ && $1 }.compact
+ Pbmenv::PBM.new.versions.map { |name| Pathname.new(name).basename.to_s =~ /^v([\d.]+)/ && $1 }.compact.sort_by {|x| Gem::Version.new(x) }.compact
end
def self.install(version)
raise "Need a version" if version.nil?
if version == 'latest'
@@ -43,10 +44,15 @@
end
system_and_puts <<~SHELL
ln -s #{PBM_DIR}/shared/device_id #{PBM_DIR}/v#{version}/device_id
SHELL
+
+ # 初回だけinstall時にcurrentを作成する
+ if not File.exists?("#{PBM_DIR}/current")
+ use(version)
+ end
rescue => e
system_and_puts "rm -rf #{PBM_DIR}/v#{version}"
raise
ensure
if Dir.exists?("./procon_bypass_man-#{version}")
@@ -64,11 +70,12 @@
system_and_puts "rm -rf #{PBM_DIR}/v#{version}"
end
def self.use(version)
raise "Need a version" if version.nil?
+ version = versions.last if version == "latest"
- unless File.exists?("/usr/share/pbm/v#{version}")
+ if !File.exists?("/usr/share/pbm/#{version}") && !File.exists?("/usr/share/pbm/v#{version}")
return false
end
if File.exists?("#{PBM_DIR}/current")
system_and_puts "unlink #{PBM_DIR}/current"