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

缓存



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

def cache
  @cache
end

#checkout_optionsObject

传入的请求参数



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

def checkout_options
  @checkout_options
end

#configObject

配置



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

def config
  @config
end

#downloaderObject

下载类



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

def downloader
  @downloader
end

#git_utilObject

git 工具类



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

def git_util
  @git_util
end

#is_updateObject

是否更新



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

def is_update
  @is_update
end

#libsObject

需要更新的 pod 集合



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

def libs
  @libs
end

#lock_infoObject

lock_info



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

def lock_info
  @lock_info
end

#nameObject

pod name



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

def name
  @name
end

#net_pingObject

网络ip 信息



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

def net_ping
  @net_ping
end

#request_paramsObject

实际下载请求参数



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

def request_params
  @request_params
end

#single_gitObject

是否是还有 git 地址参数



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

def single_git
  @single_git
end

#tokenObject

当前token



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

def token
  @token
end

#workspaceObject

工作目录



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

def workspace
  @workspace
end

Class Method Details

.sharedObject



166
167
168
# File 'lib/lg_pod_plugin/request.rb', line 166

def self.shared
  return LRequest.instance
end

Instance Method Details

#get_cache_key_paramsObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/lg_pod_plugin/request.rb', line 62

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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lg_pod_plugin/request.rb', line 44

def get_lock_info
  lock_file = self.workspace.join("Podfile.lock")
  if lock_file.exist?
    begin
      json = YAML.load_file(lock_file.to_path)
    rescue
      json = {}
    end
    external_source = json["EXTERNAL SOURCES"] ||= {}
    checkout_options = json["CHECKOUT OPTIONS"] ||= {}
    { "external_source" => external_source, "checkout_options" => checkout_options }
  else
    { "external_source" => {}, "checkout_options" => {} }
  end
end

#get_lock_paramsObject



81
82
83
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/lg_pod_plugin/request.rb', line 81

def get_lock_params
  begin
    _external_source = self.lock_info["external_source"][self.name] ||= {}
    _checkout_options = self.lock_info["checkout_options"][self.name] ||= {}
  rescue
    _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_commit = _checkout_options[:commit] ||= ""
  lock_branch = _external_source[:branch] ||= ""
  hash_map = Hash.new
  hash_map[:git] = git if git
  if git && tag
    hash_map[:tag] = tag
    return hash_map
  elsif git && branch
    if branch == lock_branch && !self.is_update
      hash_map[:branch] = branch if branch
      hash_map[:commit] = lock_commit if lock_commit
      return hash_map
    else
      hash_map[:branch] = branch if branch
      _, new_commit = LGitUtil.git_ls_remote_refs(self.name ,git, branch, tag, commit)
      if new_commit && (new_commit != lock_commit)
        hash_map[:commit] = new_commit
        hash_map["is_delete"] = false
      else
        hash_map["is_delete"] = true
      end
    end
  elsif git && commit
    hash_map[:commit] = commit if commit
    return hash_map
  else
    _, new_commit = LGitUtil.git_ls_remote_refs(self.name ,git, branch, tag, commit)
    if (new_commit != lock_commit)
      hash_map[:commit] = new_commit
      hash_map["is_delete"] = false
    else
      hash_map[:commit] = new_commit if new_commit
      hash_map["is_delete"] = true
    end
  end
  hash_map
end

#get_request_paramsObject

获取下载参数



136
137
138
139
140
141
# File 'lib/lg_pod_plugin/request.rb', line 136

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



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/lg_pod_plugin/request.rb', line 144

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