Class: LgPodPlugin::LRequest
- Inherits:
-
Object
- Object
- LgPodPlugin::LRequest
- Defined in:
- lib/lg_pod_plugin/downloader/request.rb
Instance Attribute Summary collapse
-
#checkout_options ⇒ Object
Returns the value of attribute checkout_options.
-
#config ⇒ Object
Returns the value of attribute config.
-
#lg_spec ⇒ Object
Returns the value of attribute lg_spec.
-
#lockfile ⇒ Object
Returns the value of attribute lockfile.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#net_ping ⇒ Object
Returns the value of attribute net_ping.
-
#params ⇒ Object
Returns the value of attribute params.
-
#released_pod ⇒ Object
readonly
Returns the value of attribute released_pod.
-
#single_git ⇒ Object
Returns the value of attribute single_git.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #get_cache_key_params ⇒ Object
- #get_lock_params ⇒ Object
- #get_lockfile ⇒ Object
-
#get_request_params ⇒ Object
获取下载参数.
-
#git_ls_remote_refs(name, git, branch) ⇒ Object
获取最新的一条 commit 信息.
-
#initialize(pod) ⇒ LRequest
constructor
A new instance of LRequest.
- #preprocess_request ⇒ Object
Constructor Details
#initialize(pod) ⇒ LRequest
Returns a new instance of LRequest.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 18 def initialize(pod) @name = pod.name @target = pod.target @released_pod = pod.released_pod @checkout_options = pod. if pod.spec @lg_spec = pod.spec end self.preprocess_request # require 'benchmark' # col_width = 10 # Benchmark.bm(col_width) do |bm| # bm.report("time") do # end # end end |
Instance Attribute Details
#checkout_options ⇒ Object
Returns the value of attribute checkout_options.
17 18 19 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 17 def @checkout_options end |
#config ⇒ Object
Returns the value of attribute config.
13 14 15 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 13 def config @config end |
#lg_spec ⇒ Object
Returns the value of attribute lg_spec.
10 11 12 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 10 def lg_spec @lg_spec end |
#lockfile ⇒ Object
Returns the value of attribute lockfile.
16 17 18 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 16 def lockfile @lockfile end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 9 def name @name end |
#net_ping ⇒ Object
Returns the value of attribute net_ping.
14 15 16 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 14 def net_ping @net_ping end |
#params ⇒ Object
Returns the value of attribute params.
15 16 17 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 15 def params @params end |
#released_pod ⇒ Object (readonly)
Returns the value of attribute released_pod.
11 12 13 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 11 def released_pod @released_pod end |
#single_git ⇒ Object
Returns the value of attribute single_git.
12 13 14 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 12 def single_git @single_git end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
8 9 10 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 8 def target @target end |
Instance Method Details
#get_cache_key_params ⇒ Object
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/lg_pod_plugin/downloader/request.rb', line 65 def get_cache_key_params = Hash.new.merge!(self.) hash_map = Hash.new http = [:http] if http hash_map[:http] = http return hash_map end git = [:git] ||= self.params[:git] tag = [:tag] ||= self.params[:tag] branch = [:branch] ||= self.params[:branch] commit = [:commit] ||= self.params[:commit] return hash_map unless git hash_map[:git] = git if git && commit hash_map[:commit] = commit elsif git && tag hash_map[:tag] = tag elsif git && branch && commit hash_map[:commit] = commit end hash_map end |
#get_lock_params ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 90 def get_lock_params begin _release_pods = self.lockfile.release_pods ||= [] _external_source = (self.lockfile.external_sources_data[self.name]) _external_source = {} unless _external_source = self.lockfile.(self.name) rescue _release_pods = {} _external_source = {} = {} end git = self.[:git] tag = self.[:tag] commit = self.[:commit] branch = self.[:branch] lock_git = _external_source[:git] ||= [:git] lock_tag = _external_source[:tag] ||= _release_pods[self.name] lock_branch = _external_source[:branch] ||= "" lock_commit = [:commit] ||= "" hash_map = Hash.new hash_map[:git] = git if git if git && tag hash_map[:tag] = tag if tag != lock_tag hash_map["is_delete"] = false else hash_map["is_delete"] = true end return hash_map elsif git && branch hash_map[:branch] = branch if lock_commit && !lock_commit.empty? && !LProject.shared.update pod_info = LSqliteDb.shared.query_branch_with_sha(self.name, git, lock_commit) lock_branch = pod_info[:branch] if lock_branch.empty? new_commit = pod_info[:sha] ||= "" if lock_branch == branch && new_commit == lock_commit hash_map[:commit] = lock_commit hash_map["is_delete"] = true return hash_map end end _, new_commit = git_ls_remote_refs(self.name, git, branch) if new_commit && !new_commit.empty? hash_map[:commit] = new_commit elsif lock_commit && !lock_commit.empty? hash_map[:commit] = lock_commit end if !new_commit || !lock_commit || new_commit.empty? || lock_commit.empty? hash_map["is_delete"] = false elsif new_commit != lock_commit hash_map["is_delete"] = false else hash_map["is_delete"] = true end elsif git && commit if commit != lock_commit hash_map["is_delete"] = false else hash_map["is_delete"] = true end hash_map[:commit] = commit return hash_map else if lock_git && !LProject.shared.update id = LPodLatestRefs.get_pod_id(self.name, git) pod_info = LSqliteDb.shared.query_pod_refs(id) if pod_info&.commit if pod_info new_commit = pod_info.commit else new_commit = nil end if pod_info new_branch = pod_info.branch else new_branch = nil end if new_commit hash_map[:commit] = new_commit end if new_branch hash_map[:branch] = new_branch end hash_map["is_delete"] = true return hash_map end end new_branch, new_commit = git_ls_remote_refs(self.name, git, nil) hash_map[:branch] = new_branch if new_branch if new_commit && !new_commit.empty? hash_map[:commit] = new_commit end if !new_commit || new_commit.empty? hash_map["is_delete"] = true else hash_map["is_delete"] = false end end hash_map end |
#get_lockfile ⇒ Object
59 60 61 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 59 def get_lockfile self.lockfile = LgPodPlugin::LockfileModel.from_file end |
#get_request_params ⇒ Object
获取下载参数
197 198 199 200 201 202 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 197 def get_request_params unless self.lockfile self.lockfile = self.get_lockfile end Hash.new.merge!(self.get_lock_params) end |
#git_ls_remote_refs(name, git, branch) ⇒ Object
获取最新的一条 commit 信息
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 205 def git_ls_remote_refs(name, git, branch) ip = self.net_ping.ip network_ok = self.net_ping.network_ok return [nil, nil] unless (ip && network_ok) if branch new_commit, _ = GitLabAPI.request_github_refs_heads git, branch, self.net_ping.uri unless new_commit id = LPodLatestRefs.get_pod_id(name, git) pod_info = LSqliteDb.shared.query_pod_refs(id) new_commit = pod_info ? pod_info.commit : nil return [branch, new_commit] end if new_commit LSqliteDb.shared.insert_pod_refs(name, git, branch, nil, new_commit) end [branch, new_commit] else new_commit, new_branch = GitLabAPI.request_github_refs_heads git, nil, self.net_ping.uri unless new_commit id = LPodLatestRefs.get_pod_id(name, git) pod_info = LSqliteDb.shared.query_pod_refs(id) new_commit = pod_info ? pod_info.commit : nil new_branch = pod_info ? pod_info.branch : nil return [new_branch, new_commit] end if new_commit LSqliteDb.shared.insert_pod_refs(name, git, new_branch, nil, new_commit) end [new_branch, new_commit] end end |
#preprocess_request ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 35 def preprocess_request http = self.[:http] if http self.config = nil self.net_ping = nil self.single_git = false self.params = Hash.new else tag = self.[:tag] git = self.[:git] commit = self.[:commit] branch = self.[:branch] if (git && branch) || (git && commit) || (git && tag) self.single_git = false else self.single_git = true end self.net_ping = Ping.new(git) self.config = LConfig.get_config(git, self.net_ping.uri) self.params = self.get_request_params end end |