Class: LgPodPlugin::LRequest

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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.checkout_options
  if pod.spec
    @lg_spec = pod.spec
  end
  self.preprocess_request
end

Instance Attribute Details

#checkout_optionsObject

Returns the value of attribute checkout_options.



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

def checkout_options
  @checkout_options
end

#configObject

Returns the value of attribute config.



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

def config
  @config
end

#lg_specObject

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

#lockfileObject

Returns the value of attribute lockfile.



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

def lockfile
  @lockfile
end

#nameObject (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_pingObject

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

#paramsObject

Returns the value of attribute params.



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

def params
  @params
end

#released_podObject (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_gitObject

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

#targetObject (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_paramsObject



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
  options = Hash.new.merge!(self.checkout_options)
  hash_map = Hash.new
  http = options[:http]
  if http
    hash_map[:http] = http
    return hash_map
  end
  git = options[:git] ||= self.params[:git]
  tag = options[:tag] ||= self.params[:tag]
  branch = options[:branch] ||= self.params[:branch]
  commit = options[: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_paramsObject



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.checkout_options[:git]
  tag = self.checkout_options[:tag]
  commit = self.checkout_options[:commit]
  branch = self.checkout_options[: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_lockfileObject



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_paramsObject

获取下载参数



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_requestObject



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.checkout_options[:http]
  if http
    self.config = nil
    self.net_ping = nil
    self.single_git = false
    self.params = Hash.new
  else
    tag = self.checkout_options[:tag]
    git = self.checkout_options[:git]
    commit = self.checkout_options[:commit]
    branch = self.checkout_options[: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