Class: GithubBackup::GithubRepositoryCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/github-backup/github_repository_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ GithubRepositoryCollection

Returns a new instance of GithubRepositoryCollection.



5
6
7
# File 'lib/github-backup/github_repository_collection.rb', line 5

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/github-backup/github_repository_collection.rb', line 3

def client
  @client
end

Instance Method Details

#gists(username) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/github-backup/github_repository_collection.rb', line 22

def gists(username)
  first_page =
    if username_is_authenticated_user?(username)
      client.gists
    else
      client.gists(username)
    end

  all(first_page).map { |r| GithubBackup::Gist.new(r) }
end

#repos(username) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/github-backup/github_repository_collection.rb', line 9

def repos(username)
  first_page =
    if username_is_authenticated_user?(username)
      client.repos
    elsif username_is_organisation?(username)
      client.org_repos(username)
    else
      client.repos(username)
    end

  all(first_page).map { |r| GithubBackup::Repository.new(r) }
end

#starred_gists(username) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/github-backup/github_repository_collection.rb', line 33

def starred_gists(username)
  first_page =
    if username_is_authenticated_user?(username)
      client.starred_gists
    else
      [] # Can only list authenticated user's gists at the moment
    end

  return first_page if first_page.empty?
  all(first_page).map { |r| GithubBackup::Gist.new(r) }
end

#wikis(username) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/github-backup/github_repository_collection.rb', line 45

def wikis(username)
  first_page =
    if username_is_authenticated_user?(username)
      client.repos
    elsif username_is_organisation?(username)
      client.org_repos(username)
    else
      client.repos(username)
    end

  all(first_page).
    select(&:has_wiki?).
      map { |r| GithubBackup::Wiki.new(r) }
end