Class: LgPodPlugin::LRequest

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/lg_pod_plugin/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cacheObject

缓存



18
19
20
# File 'lib/lg_pod_plugin/request.rb', line 18

def cache
  @cache
end

#checkout_optionsObject

传入的请求参数



38
39
40
# File 'lib/lg_pod_plugin/request.rb', line 38

def checkout_options
  @checkout_options
end

#configObject

配置



20
21
22
# File 'lib/lg_pod_plugin/request.rb', line 20

def config
  @config
end

#downloaderObject

下载类



32
33
34
# File 'lib/lg_pod_plugin/request.rb', line 32

def downloader
  @downloader
end

#git_utilObject

git 工具类



28
29
30
# File 'lib/lg_pod_plugin/request.rb', line 28

def git_util
  @git_util
end

#is_updateObject

是否更新



22
23
24
# File 'lib/lg_pod_plugin/request.rb', line 22

def is_update
  @is_update
end

#libsObject

需要更新的 pod 集合



30
31
32
# File 'lib/lg_pod_plugin/request.rb', line 30

def libs
  @libs
end

#lock_infoObject

lock_info



34
35
36
# File 'lib/lg_pod_plugin/request.rb', line 34

def lock_info
  @lock_info
end

#nameObject

pod name



14
15
16
# File 'lib/lg_pod_plugin/request.rb', line 14

def name
  @name
end

#net_pingObject

网络ip 信息



40
41
42
# File 'lib/lg_pod_plugin/request.rb', line 40

def net_ping
  @net_ping
end

#request_paramsObject

实际下载请求参数



36
37
38
# File 'lib/lg_pod_plugin/request.rb', line 36

def request_params
  @request_params
end

#single_gitObject

是否是还有 git 地址参数



26
27
28
# File 'lib/lg_pod_plugin/request.rb', line 26

def single_git
  @single_git
end

#tokenObject

当前token



16
17
18
# File 'lib/lg_pod_plugin/request.rb', line 16

def token
  @token
end

#workspaceObject

工作目录



24
25
26
# File 'lib/lg_pod_plugin/request.rb', line 24

def workspace
  @workspace
end

Class Method Details

.sharedObject



215
216
217
# File 'lib/lg_pod_plugin/request.rb', line 215

def self.shared
  return LRequest.instance
end

Instance Method Details

#get_cache_key_paramsObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/lg_pod_plugin/request.rb', line 75

def get_cache_key_params
  hash_map = Hash.new
  git = self.checkout_options[:git] ||= self.request_params[:git]
  tag = self.checkout_options[:tag] ||= self.request_params[:tag]
  branch = self.checkout_options[:branch] ||= self.request_params[:branch]
  commit = self.checkout_options[:commit] ||= self.request_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_infoObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/lg_pod_plugin/request.rb', line 43

def get_lock_info
  lock_file_path = self.workspace.join("Podfile.lock")
  if lock_file_path.exist?
    lock_file = Pod::Lockfile.from_file(lock_file_path)
    internal_data = lock_file.send(:internal_data)
    release_pods = Hash.new
    pods = internal_data["PODS"] ||= {}
    pods.each do |key, val|
      if LUtils.is_string(key)
        pod_name = key.split(" ").first if key.include?(" ")
        tag = key[/(?<=\().*?(?=\))/]
        release_pods[pod_name] = tag
      elsif key.is_a?(Hash)
        key_name = key.keys.first
        next unless key_name
        pod_name = key_name.split(" ").first if key_name.include?(" ")
        tag = key_name[/(?<=\().*?(?=\))/]
        release_pods[pod_name] = tag
      else
        next
      end
    end
    external_source = internal_data["EXTERNAL SOURCES"] ||= {}
    checkout_options = internal_data["CHECKOUT OPTIONS"] ||= {}
    { "external_source" => external_source, "checkout_options" => checkout_options, "release_pods" => release_pods }
  else
    { "external_source" => {}, "checkout_options" => {}, "release_pods" => {} }
  end
end

#get_lock_paramsObject



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
# File 'lib/lg_pod_plugin/request.rb', line 94

def get_lock_params
  begin
    _release_pods = self.lock_info["release_pods"] ||= {}
    _external_source = self.lock_info["external_source"][self.name] ||= {}
    _checkout_options = self.lock_info["checkout_options"][self.name] ||= {}
  rescue
    _release_pods = {}
    _external_source = {}
    _checkout_options = {}
  end

  git = self.checkout_options[:git]
  tag = self.checkout_options[:tag]
  commit = self.checkout_options[:commit]
  branch = self.checkout_options[:branch]

  lock_git = _external_source[:git] ||= _checkout_options[:git]
  lock_tag = _external_source[:tag] ||= _release_pods[self.name]
  lock_branch = _external_source[:branch] ||= ""
  lock_commit = _checkout_options[: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 branch == lock_branch && !self.is_update
      if lock_commit && !lock_commit.empty?
        hash_map[:commit] = lock_commit
      end
      hash_map["is_delete"] = true
      return hash_map
    else
      _, new_commit = LGitUtil.git_ls_remote_refs(self.name ,git, branch, nil, nil)
      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
    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 && !self.is_update
      id = LPodLatestRefs.get_pod_id(self.name, git)
      pod_info = LSqliteDb.shared.query_pod_refs(id)
      if pod_info && pod_info.commit
        new_commit = pod_info.commit if pod_info
        new_branch = pod_info.branch if pod_info
        hash_map[:commit] = new_commit if new_commit
        hash_map[:branch] = new_branch if new_branch
        hash_map["is_delete"] = true
        return hash_map
      end
    end
    new_branch, new_commit = LGitUtil.git_ls_remote_refs(self.name, git, nil, nil, 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_request_paramsObject

获取下载参数



185
186
187
188
189
190
# File 'lib/lg_pod_plugin/request.rb', line 185

def get_request_params
  if self.lock_info == nil
    self.lock_info = self.get_lock_info
  end
  Hash.new.merge!(self.get_lock_params)
end

#setup_pod_info(name, workspace, options = {}) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/lg_pod_plugin/request.rb', line 193

def setup_pod_info(name, workspace, options = {})
  self.name = name
  tag = options[:tag]
  git = options[:git]
  commit = options[:commit]
  branch = options[:branch]
  self.workspace = workspace
  if (git && branch) || (git && commit) || (git && tag)
    self.single_git = false
  else
    self.single_git = true
  end
  self.net_ping = Ping.new(git)
  self.net_ping.network_ok = self.net_ping.ping
  self.checkout_options = Hash.new.deep_merge(options)
  self.request_params = self.get_request_params
  self.config = LConfig.getConfig(git)
  self.cache = LCache.new(self.workspace)
  self.git_util = LGitUtil.new(name, self.checkout_options)
  self.downloader = LDownloader.new(name, self.checkout_options)
end