Class: LgPodPlugin::LRequest

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sharedObject



134
135
136
# File 'lib/lg_pod_plugin/request.rb', line 134

def self.shared
  return LRequest.instance
end

Instance Method Details

#get_lock_infoObject



29
30
31
32
33
34
35
36
37
# File 'lib/lg_pod_plugin/request.rb', line 29

def get_lock_info
  lock_file = self.workspace.join("Podfile.lock")
  if lock_file.exist?
    json = YAML.load_file(lock_file.to_path)
    json["EXTERNAL SOURCES"]
  else
    nil
  end
end

#get_lock_params(git, branch, tag, commit) ⇒ Object



39
40
41
42
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
# File 'lib/lg_pod_plugin/request.rb', line 39

def get_lock_params(git, branch, tag, commit)
  unless self.lock_info
    return nil
  end
  current_pod_info = self.lock_info[name]
  unless current_pod_info
    return nil
  end
  lock_commit = current_pod_info[:commit]
  if git && tag
    lock_tag = current_pod_info[:tag]
    if lock_tag == tag
      return { :git => git, :commit => lock_commit, :tag => lock_tag }
    else
      return nil
    end
  elsif git && branch
    lock_branch = current_pod_info[:branch]
    if branch == lock_branch
      return { :git => git, :commit => lock_commit, :branch => lock_branch}
    else
      return nil
    end
  elsif commit == lock_commit
    return { :git => git, :commit => lock_commit }
  else
    nil
  end
end

#is_update_podObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lg_pod_plugin/request.rb', line 13

def is_update_pod
  cgi = CGI.new
  command_keys = cgi.keys
  unless command_keys.count > 0
    return false
  end
  first_key = command_keys[0].to_s ||= ""
  if first_key.include?("install")
    false
  elsif first_key.include?("update")
    true
  else
    false
  end
end

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



69
70
71
72
73
74
75
76
77
78
79
80
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
132
# File 'lib/lg_pod_plugin/request.rb', line 69

def setup_pod_info(name, workspace, options = {})
  self.name = name
  hash_map = options
  tag = hash_map[:tag]
  git = hash_map[:git]
  path = hash_map[:path]
  commit = hash_map[:commit]
  branch = hash_map[:branch]
  self.workspace = workspace
  self.is_update = self.is_update_pod
  if self.lock_info == nil
    self.lock_info = self.get_lock_info
  end
  self.lock_params = self.get_lock_params(git, branch, tag, commit)
  if git && tag
    if self.lock_params && !self.is_update
      lock_tag = self.lock_params[:tag]
      lock_commit = self.lock_params[:commit]
      if lock_tag == tag && lock_commit
        hash_map[:commit] = lock_commit
      else
        _, new_commit = LGitUtil.git_ls_remote_refs(git, branch, tag, commit)
        hash_map[:commit] = new_commit
      end
    else
      _, new_commit = LGitUtil.git_ls_remote_refs(git, branch, tag,commit)
      hash_map[:commit] = new_commit
    end
  elsif git && commit
    if self.lock_params && !self.is_update
      hash_map[:commit] = commit
    else
      new_branch, new_commit = LGitUtil.git_ls_remote_refs(git, branch, tag, commit)
      if new_commit
        hash_map[:commit] = new_commit
      end
      if new_branch
        hash_map[:branch] = new_branch
      end
    end
  elsif git && branch
    if self.lock_params && !self.is_update
      lock_branch = self.lock_params[:branch]
      lock_commit = self.lock_params[:commit]
      if branch == lock_branch && lock_commit
        hash_map[:commit] = lock_commit
      else
        _, new_commit = LGitUtil.git_ls_remote_refs(git, branch, tag, commit)
        hash_map[:commit] = new_commit
      end
    else
      _, new_commit = LGitUtil.git_ls_remote_refs(git, branch, tag, commit)
      hash_map[:commit] = new_commit
    end
  elsif !path
    new_branch, new_commit = LGitUtil.git_ls_remote_refs(git, branch, tag, commit)
    hash_map[:commit] = new_commit
    hash_map[:branch] = new_branch
  end
  self.options = hash_map
  self.cache = LCache.new(self.workspace)
  self.git_util = LGitUtil.new(name, hash_map)
  self.downloader = LDownloader.new(name, hash_map)
end