Class: Pindo::VersionCheck
- Inherits:
-
Object
- Object
- Pindo::VersionCheck
- Defined in:
- lib/pindo/version.rb
Class Method Summary collapse
- .check_pindo_force_upgrade ⇒ Object
- .check_pindo_new_version ⇒ Object
- .version_greater_than(version_string1: nil, version_string2: nil) ⇒ Object
Class Method Details
.check_pindo_force_upgrade ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pindo/version.rb', line 49 def self.check_pindo_force_upgrade begin pindo_dir = File.(ENV['PINDO_DIR'] || '~/.pindo') pindo_common_configdir = File.join(pindo_dir, "pindo_common_config") pindo_common_configfile_fullname = File.join(pindo_common_configdir, "pindo_config.json") pindo_common_config_json = JSON.parse(File.read(pindo_common_configfile_fullname)) pindo_latest_version = pindo_common_config_json["pindo_latest_version"] pindo_mini_version = pindo_common_config_json["pindo_mini_version"] pindo_force_upgrade = pindo_common_config_json["pindo_force_upgrade"] pindo_current_version = Pindo::VERSION if pindo_force_upgrade compare_num = Pindo::VersionCheck::version_greater_than(version_string1:pindo_current_version, version_string2:pindo_mini_version) if compare_num < 0 puts "当前pindo版本 #{Pindo::VERSION}" puts "最新版本 #{pindo_latest_version}" puts "要求最低版本 #{pindo_mini_version}" raise Informative, "请使用pindo upgrade 升级!" end end rescue Exception => e raise Informative, "有异常错误,请使用pindo upgrade 升级!" end end |
.check_pindo_new_version ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pindo/version.rb', line 7 def self.check_pindo_new_version # puts # puts "pindo #{Pindo::VERSION}" begin pindo_dir = File.(ENV['PINDO_DIR'] || '~/.pindo') pindo_common_configdir = File.join(pindo_dir, "pindo_common_config") pindo_common_configfile_fullname = File.join(pindo_common_configdir, "pindo_config.json") pindo_common_config_json = JSON.parse(File.read(pindo_common_configfile_fullname)) pindo_latest_version = pindo_common_config_json["pindo_latest_version"] pindo_mini_version = pindo_common_config_json["pindo_mini_version"] pindo_force_upgrade = pindo_common_config_json["pindo_force_upgrade"] pindo_lates_update_info = pindo_common_config_json["pindo_lates_update_info"] pindo_current_version = Pindo::VERSION if pindo_force_upgrade compare_num = Pindo::VersionCheck::version_greater_than(version_string1:pindo_current_version, version_string2:pindo_latest_version) if compare_num < 0 # answer = agree("有可用的新版本,是否升级?(Y/n:") # if answer # Pindo::Command::Env::Upgrade::run([]) # end puts puts "最新版本是#{pindo_latest_version}目前可用, 可使用pindo upgrade 升级" puts puts pindo_lates_update_info puts end end rescue Exception => e puts "有异常错误,请使用pindo upgrade 升级" puts end end |
.version_greater_than(version_string1: nil, version_string2: nil) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/pindo/version.rb', line 78 def self.version_greater_than(version_string1: nil, version_string2: nil) return 0 if version_string1.nil? && version_string2.nil? return -1 if version_string1.nil? return 1 if version_string2.nil? version_string1_array = version_string1.split('.') || [] version_string2_array = version_string2.split('.') || [] array_max_length = [version_string1_array.size, version_string2_array.size].max version_string1_array += ['0'] * (array_max_length - version_string1_array.size) version_string2_array += ['0'] * (array_max_length - version_string2_array.size) compare_num = 0 (0..array_max_length).each do |i| if version_string1_array[i] == version_string2_array[i] compare_num = 0 elsif version_string1_array[i].to_i > version_string2_array[i].to_i compare_num = 1 break else compare_num = -1 break end end compare_num end |