Class: GitHubRecordsArchiver::Repository

Inherits:
GitRepository show all
Includes:
DataHelper
Defined in:
lib/github_records_archiver/repository.rb

Constant Summary collapse

KEYS =
i[
  name full_name description private fork homepage
  forks_count stargazers_count watchers_count size
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DataHelper

#method_missing, #respond_to_missing?, #to_h, #to_json

Methods inherited from GitRepository

#clone

Constructor Details

#initialize(name_or_hash) ⇒ Repository

Returns a new instance of Repository.



11
12
13
14
15
16
17
18
# File 'lib/github_records_archiver/repository.rb', line 11

def initialize(name_or_hash)
  if name_or_hash.is_a?(String)
    @name = name_or_hash
  else
    @data = name_or_hash.to_h
    @name = @data[:full_name]
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GitHubRecordsArchiver::DataHelper

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/github_records_archiver/repository.rb', line 3

def name
  @name
end

Instance Method Details

#clone_urlObject



43
44
45
46
# File 'lib/github_records_archiver/repository.rb', line 43

def clone_url
  replacement = "https://#{GitHubRecordsArchiver.token}:x-oauth-basic@"
  data[:clone_url].gsub(%r{https?://}, replacement)
end

#dataObject



20
21
22
# File 'lib/github_records_archiver/repository.rb', line 20

def data
  @data ||= GitHubRecordsArchiver.client.repository(name)
end

#issuesObject



28
29
30
31
32
33
# File 'lib/github_records_archiver/repository.rb', line 28

def issues
  @issues ||= begin
    issues = GitHubRecordsArchiver.client.list_issues name, state: 'all'
    issues.map { |i| Issue.from_hash(self, i) }
  end
end

#issues_dirObject



35
36
37
38
39
40
41
# File 'lib/github_records_archiver/repository.rb', line 35

def issues_dir
  @issues_dir ||= begin
    dir = File.expand_path 'issues', repo_dir
    FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
    dir
  end
end

#repo_dirObject



48
49
50
# File 'lib/github_records_archiver/repository.rb', line 48

def repo_dir
  @repo_dir ||= File.expand_path full_name, GitHubRecordsArchiver.dest_dir
end

#wikiObject



24
25
26
# File 'lib/github_records_archiver/repository.rb', line 24

def wiki
  @wiki ||= Wiki.new(self) if has_wiki?
end