Class: Pod::Podfile
- Inherits:
-
Object
- Object
- Pod::Podfile
- Defined in:
- lib/YKBIU.rb
Instance Method Summary collapse
-
#handleResponse(url, response) ⇒ Object
处理网络请求返回来的内容.
-
#makeup_pods(url, params, method, ignores = []) ⇒ Object
从url获取依赖并进行依赖安装.
-
#peform_request(url, params, method) ⇒ Object
处理获取依赖的网络请求.
-
#yk_pod(dependencies, ignores) ⇒ Object
安装依赖,在安装依赖的过程中判断是否在ignores中, 如果在ignores中则忽略不进行依赖安装, 如果不在ignores,判断是否有componentVersion,优先是用版本进行安装,否则进行url、tag、commit等配置进行安装依赖.
Instance Method Details
#handleResponse(url, response) ⇒ Object
处理网络请求返回来的内容
{
"result": 0,
"codeMsg": "",
"resultMessage": "响应成功",
"content": [
{
"dependencyName": "AFNetworking",
"componentVersion": "~> 3.2.0"
}
]
}
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/YKBIU.rb', line 125 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 = []) ⇒ Object
从url获取依赖并进行依赖安装
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/YKBIU.rb', line 35 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.安装依赖 yk_pod(dependencies, ignores) else #1.读取本地保存的json json = File.read(file) if File.exist?(file) dependencies = JSON.parse(json) #2.安装依赖 yk_pod(dependencies, ignores) if dependencies end end |
#peform_request(url, params, method) ⇒ Object
处理获取依赖的网络请求
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/YKBIU.rb', line 95 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 |
#yk_pod(dependencies, ignores) ⇒ Object
安装依赖,在安装依赖的过程中判断是否在ignores中, 如果在ignores中则忽略不进行依赖安装, 如果不在ignores,判断是否有componentVersion,优先是用版本进行安装,否则进行url、tag、commit等配置进行安装依赖
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/YKBIU.rb', line 61 def yk_pod(dependencies, ignores) dependencies.each { |value| componentName = value.fetch("dependencyName", nil) # 忽略组件名称不存的依赖 return unless componentName # 跳过在ignores列表中的依赖 next if ignores.include? componentName 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 |