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 |
# 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 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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 59 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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 84 def get_lock_params git = self.[:git] tag = self.[:tag] commit = self.[:commit] branch = self.[:branch] hash_map = Hash.new hash_map[:git] = git if git if git && tag hash_map[:tag] = tag return hash_map elsif git && branch hash_map[:branch] = branch _, new_commit = git_ls_remote_refs(self.name, git, branch) hash_map[:commit] = new_commit if new_commit elsif git && commit hash_map[:commit] = commit return hash_map else new_branch, new_commit = git_ls_remote_refs(self.name, git, nil) hash_map[:branch] = new_branch if new_branch hash_map[:commit] = new_commit if new_commit end hash_map end |
#get_lockfile ⇒ Object
53 54 55 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 53 def get_lockfile self.lockfile = LgPodPlugin::LockfileModel.from_file end |
#get_request_params ⇒ Object
获取下载参数
113 114 115 116 117 118 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 113 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 信息
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 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 121 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, branch) 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, "HEAD") 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, "HEAD", nil, new_commit) end [new_branch, new_commit] end end |
#preprocess_request ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lg_pod_plugin/downloader/request.rb', line 29 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 |