Class: LgPodPlugin::GitDownloader

Inherits:
Object
  • Object
show all
Defined in:
lib/lg_pod_plugin/git/git_download.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(checkout_options = {}) ⇒ GitDownloader

Returns a new instance of GitDownloader.



13
14
15
16
17
# File 'lib/lg_pod_plugin/git/git_download.rb', line 13

def initialize(checkout_options = {})
  self.git = checkout_options[:git]
  self.config = checkout_options[:config]
  self.checkout_options = checkout_options
end

Instance Attribute Details

#checkout_optionsObject

Returns the value of attribute checkout_options.



12
13
14
# File 'lib/lg_pod_plugin/git/git_download.rb', line 12

def checkout_options
  @checkout_options
end

#configObject

Returns the value of attribute config.



11
12
13
# File 'lib/lg_pod_plugin/git/git_download.rb', line 11

def config
  @config
end

#gitObject

Returns the value of attribute git.



10
11
12
# File 'lib/lg_pod_plugin/git/git_download.rb', line 10

def git
  @git
end

Instance Method Details

#downloadObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lg_pod_plugin/git/git_download.rb', line 21

def download
  begin
    if self.is_use_gitlab_archive_file(self.git)
      git_archive = GitLabArchive.new(self.checkout_options)
      return git_archive.download
    elsif self.git.include?("https://github.com")
      github_archive = GitHubArchive.new(self.checkout_options)
      return github_archive.download
    else
      git_clone = GitRepository.new(checkout_options)
      return git_clone.download
    end
  rescue
    LgPodPlugin.log_red "异常信息: #{$!}"
    LgPodPlugin.log_yellow " 异常位置: #{$@}"
    git_clone = GitRepository.new(checkout_options)
    return  git_clone.download
  end
end

#is_use_gitlab_archive_file(git) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/lg_pod_plugin/git/git_download.rb', line 43

def is_use_gitlab_archive_file(git)
  return false unless self.config&.access_token
  return true if self.config.project
  project_name = LUtils.get_git_project_name(git)
  self.config.project = GitLabAPI.request_project_info(config.host, project_name, config.access_token, git)
  (self.config.project != nil)
end