class Pod::Podfile
Public Instance Methods
handleResponse(url, response)
click to toggle source
处理网络请求返回来的内容
@param response 应返回json数据结构,如下:
{
"result": 0, "codeMsg": "", "resultMessage": "响应成功", "content": [ { "dependencyName": "AFNetworking", "componentVersion": "~> 3.2.0" } ] }
# File lib/ppdbiu.rb, line 131 def handleResponse(url, response) if response.ok? body = JSON.parse(response.body) result = body["result"] if result == 0 content = body["content"] UI.title content content else resultMessage = body["resultMessage"] CoreUI.warn "Request to #{url} has error - #{resultMessage}" nil end else CoreUI.warn "Request to #{url} failed - #{response.status_code}" nil end end
makeup_pods(url, params, method, ignores = [])
click to toggle source
从url获取依赖并进行依赖安装
@param url 获取依赖配置的请求url @param params 获取依赖配置的请求参数 @param method 获取依赖配置的请求方式 @param ignores 依赖安装忽略列表,默认为空
# File lib/ppdbiu.rb, line 28 def makeup_pods(url, params, method, ignores = []) UI.title "makeup pods dependency from #{url}" file = "dependency.json" dependencies = peform_request(url, params, method) if dependencies #1.保存json File.delete(file) if File.exist?(file) File.open(file, "w") { |io| io.syswrite(JSON.generate(dependencies))} #2.安装依赖 ppd_pod(dependencies, ignores) else #1.读取本地保存的json json = File.read(file) if File.exist?(file) dependencies = JSON.parse(json) #2.安装依赖 ppd_pod(dependencies, ignores) if dependencies end end
peform_request(url, params, method)
click to toggle source
处理获取依赖的网络请求
@param url 请求的url @param paras 请求的参数 @param method 请求的方式
# File lib/ppdbiu.rb, line 101 def peform_request(url, params, method) require 'rest' require 'json' headers = {'Accept' => 'application/json, */*', 'Content-Type' => 'application/json; charset=utf-8'} if 'GET' == method || 'get' == method response = REST.get(url, headers, params) handleResponse(url, response) elsif 'POST' == method || 'post' == method response = REST.post(url, params.to_json, headers) handleResponse(url, response) end end
ppd_pod(dependencies, ignores)
click to toggle source
安装依赖,在安装依赖的过程中判断是否在ignores中, 如果在ignores中则忽略不进行依赖安装, 如果不在ignores,判断是否有componentVersion,优先是用版本进行安装,否则进行url、tag、commit等配置进行安装依赖
@param dependencies 依赖列表 @param ignores 忽略列表
# File lib/ppdbiu.rb, line 54 def ppd_pod(dependencies, ignores) dependencies.each { |value| componentName = value.fetch("dependencyName", nil) unless componentName return end # 判断依赖是否在ignores中,如果在则略过 if ignores isIgnore = false; ignores.each { |ignore| if ignore == componentName isIgnore = true break end } if isIgnore next end end version = value.fetch("componentVersion", nil) if version pod(componentName, version) else hash = {} value.each{ |rKey, rValue| hash[:git] = rValue if rKey == "gitUrl" hash[:branch] = rValue if rKey == "componentBranch" hash[:tag] = rValue if rKey == "tag" hash[:commit] = rValue if rKey == "commit" hash[:configuration] = rValue if rKey == "configuration" hash[:path] = rValue if rKey == "path" hash[:podspec] = rValue if rKey == "podspec" hash[:subspecs] = rValue if rKey == "subspecs" } pod(componentName, hash) end } end