class Object
Public Instance Methods
compare_version(version0, version1)
click to toggle source
# File lib/ZYPodWings.rb, line 222 def compare_version(version0, version1) if version0.length == 0 return version1 end if version1.length == 0 return version0 end if version0[0] == '.' return version1 end if version1[0] == '.' return version0 end ver0_arr = version0.split('.') ver1_arr = version1.split('.') if ver0_arr.size == 0 or ver1_arr.size == 0 or ver0_arr.size != ver1_arr.size return version0 end (0..ver0_arr.size-1).each do |idx| num_0 = ver0_arr[idx].to_i() num_1 = ver1_arr[idx].to_i() if num_0 == num_1 next end if num_0 > num_1 return version0 else return version1 end end end
fetch_last_version(versions)
click to toggle source
获取最新版本号
# File lib/ZYPodWings.rb, line 207 def fetch_last_version(versions) if versions.length == 1 return versions[0] end last_version = versions[0] (1..versions.size-1).each do |idx| version = versions[idx] if version[0] == '.' next end last_version = compare_version(last_version, version) end return last_version end
is_avaliable_pod_dict(pod_dict)
click to toggle source
# File lib/ZYPodWings.rb, line 254 def is_avaliable_pod_dict(pod_dict) if not pod_dict return false end all_keys = pod_dict.keys() if not all_keys.include?('enable') return false end if not all_keys.include?('is_github') return false end if not all_keys.include?('pod_name') return false end if not all_keys.include?('version') return false end return true end
last_version_for_pod(pod_name)
click to toggle source
获取 pod_name 的最新版本号
# File lib/ZYPodWings.rb, line 77 def last_version_for_pod(pod_name) user_hub_path = File.join($spec_repo_path, pod_name) versions = Dir::entries(user_hub_path) last_version = fetch_last_version(versions) # puts pod_name + '最新版本是:'+last_version return last_version end
pod_config(params={"file_name" => "podConfig.json", "update_to_last" => true, "local_pod_list" => []})
click to toggle source
pod 对应配置文件内容(供外部调用)
# File lib/ZYPodWings.rb, line 187 def pod_config(params={"file_name" => "podConfig.json", "update_to_last" => true, "local_pod_list" => []}) file_name = params.fetch("file_name", 'podConfig.json') need_update_to_last = params.fetch("update_to_last", true) local_pod_list = params.fetch("local_pod_list", []) json_file_path = File.join($pwd_path, file_name) if not File.exist? json_file_path puts "找不到#{file_name} 文件,pod_config 已提前结束" return end # 更新json文件(若有必要) if need_update_to_last update_pod_list(json_file_path) end # 开始pod start_pod(json_file_path, local_pod_list) end
pod_local(pod_info)
click to toggle source
pod 本地 git 仓库
# File lib/ZYPodWings.rb, line 62 def pod_local(pod_info) pod_name = pod_info["pod_name"] # puts 'pod 本地仓库' + pod_name spec_path = pod_info["path"] if spec_path.length > 0 pod(pod_name, {:path => spec_path}) else puts "pod 本地仓库进行调试时,路径不能为空: " + pod_name end end
pod_remote(pod_info)
click to toggle source
pod 远程 git 仓库
# File lib/ZYPodWings.rb, line 44 def pod_remote(pod_info) pod_name = pod_info["pod_name"] # puts 'pod 远程仓库' + pod_name version = pod_info["version"] git_path = pod_info["git"] if git_path && git_path.length > 0 commit = pod_info["commit"] if commit && commit.length > 0 pod(pod_name, {:git => git_path, :commit => commit}) else pod(pod_name, {:tag => version, :git => git_path}) end else pod(pod_name, version) end end
pull_spec_repo()
click to toggle source
更新podspec仓库
# File lib/ZYPodWings.rb, line 86 def pull_spec_repo() spec_repo_exist = File.exist?($spec_repo_path) unless spec_repo_exist puts '本地 ~/Desktop/ZYWidgets/目录下没有ZYPodSpecs仓库,将不会更新私有pod版本号' return false end Dir.chdir($spec_repo_path) `git pull origin master` Dir.chdir($pwd_path) return true end
start_pod(json_file_path, debug_list=[])
click to toggle source
开始pod
# File lib/ZYPodWings.rb, line 149 def start_pod(json_file_path, debug_list=[]) unless File.exist?(json_file_path) puts "##### pod 配置文件不存在 >>>>>>>> " return end pod_list = JSON.parse(File.read(json_file_path)) pod_list.each do |pod_info| is_valid = is_avaliable_pod_dict(pod_info) unless is_valid next end enable = pod_info["enable"] pod_name = pod_info["pod_name"] unless enable next end version = pod_info["version"] is_github = pod_info["is_github"] is_release = pod_info.fetch('is_release', true) #["is_release"] if debug_list.include? pod_name and not is_github # puts '##### Force debug >>>>>>>> ' + pod_name is_release = false end if is_github pod_remote(pod_info) else if is_release pod_remote(pod_info) else pod_local(pod_info) end end end end
update_pod_list(json_file_path)
click to toggle source
更新json文件
# File lib/ZYPodWings.rb, line 99 def update_pod_list(json_file_path) spec_repo_exist = File.exist?($spec_repo_path) unless spec_repo_exist puts '本地 ~/Desktop/ZYWidgets/目录下没有ZYPodSpecs仓库,将不会更新私有pod版本号' return end pull_result = pull_spec_repo() unless pull_result puts 'pull ZYPodSpecs 失败了' end pod_list = JSON.parse(File.read(json_file_path)) unless pod_list.class == Array && pod_list.size > 0 puts "pod 配置文件格式有误或内容为空,将不会更新私有pod版本号" return end json_changed = false pod_list.each do |pod_dict| is_avaliable = is_avaliable_pod_dict(pod_dict) if not is_avaliable next end enable = pod_dict.fetch("enable", false) is_github = pod_dict.fetch('is_github', true) auto_update_enable = pod_dict.fetch('auto_update_enable', false) pod_name = pod_dict.fetch('pod_name') if not pod_name or pod_name.length == 0 next end if not enable or is_github or not auto_update_enable next end last_version = last_version_for_pod(pod_name) if not last_version or last_version[0] == '.' next end version = pod_dict.fetch('version', '1.0.0') if not version == last_version pod_dict["version"] = last_version puts "#{pod_name} " json_changed = true end end if json_changed File.open(json_file_path, 'w') { |json_file| json_file.puts JSON.pretty_generate(pod_list) } end end