Class: GitMulticast::RepositoryFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/git_multicast/repository_fetcher.rb,
lib/git_multicast/repository_fetcher/github.rb,
lib/git_multicast/repository_fetcher/bitbucket.rb

Direct Known Subclasses

Bitbucket, Github

Defined Under Namespace

Classes: Bitbucket, Github

Constant Summary collapse

FETCHER_ADAPTER_ZIP =
[
  [Bitbucket, Adapter::Bitbucket],
  [Github, Adapter::Github]
]

Class Method Summary collapse

Class Method Details

.adapter_by_url(url) ⇒ Object



47
48
49
# File 'lib/git_multicast/repository_fetcher.rb', line 47

def self.adapter_by_url(url)
  zip_by_url(url).last
end

.fetcher_by_url(url) ⇒ Object



43
44
45
# File 'lib/git_multicast/repository_fetcher.rb', line 43

def self.fetcher_by_url(url)
  zip_by_url(url).first
end

.get_all_repos_from_user(username) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/git_multicast/repository_fetcher.rb', line 16

def self.get_all_repos_from_user(username)
  FETCHER_ADAPTER_ZIP.map do |fetcher, adapter|
    raw_repos = fetcher.get_all_repos_from_user(username)

    raw_repos.map { |raw_repo| adapter.new(raw_repo).adapt }
  end.flatten
end

.get_repo(url) ⇒ Object



24
25
26
27
# File 'lib/git_multicast/repository_fetcher.rb', line 24

def self.get_repo(url)
  raw_repo = fetcher_by_url(url).get_repo(url)
  adapter_by_url(url).new(raw_repo).adapt
end

.get_repo_parent(url) ⇒ Object



29
30
31
# File 'lib/git_multicast/repository_fetcher.rb', line 29

def self.get_repo_parent(url)
  get_repo(url).parent
end

.make_struct(hash) ⇒ Object



51
52
53
# File 'lib/git_multicast/repository_fetcher.rb', line 51

def self.make_struct(hash)
  RecursiveOpenStruct.new(hash, recurse_over_arrays: true)
end

.zip_by_url(url) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/git_multicast/repository_fetcher.rb', line 33

def self.zip_by_url(url)
  fetchers_names = FETCHERS.map do |fetcher|
    match = fetcher.to_s.match(/Fetcher::(.*)$/)
    match[1].downcase if match
  end

  triples = ([url] * FETCHERS.size).zip(fetchers_names, FETCHER_ADAPTER_ZIP)
  triples.find { |u, name, _| u.match name }.last
end