Module: SocialSnippet::Repository::RepositoryFactory

Defined in:
lib/social_snippet/repository/repository_factory.rb

Class Method Summary collapse

Class Method Details

.clone(repo_url) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/social_snippet/repository/repository_factory.rb', line 5

def clone(repo_url)
  uri = URI.parse repo_url
  if is_git_repo(uri)
    path = ::SocialSnippet::Repository::Drivers::GitRepository.download uri
    repo = create_git_repo(path)
    repo.set_url repo_url
    repo.load_snippet_json
    return repo
  else
    raise "unknown repository type"
  end
end

.clone_local(repo_path) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
# File 'lib/social_snippet/repository/repository_factory.rb', line 18

def clone_local(repo_path)
  if has_git_dir?(repo_path)
    cloned_path = ::SocialSnippet::Repository::Drivers::GitRepository.download repo_path
    repo = create_git_repo(cloned_path)
    repo.set_url repo_path
    repo.load_snippet_json
    return repo
  else
    raise "unknown local repository type"
  end
end

.create(path, ref = nil, options = {}) ⇒ Object

Create suitable Repository class instance from path


33
34
35
36
37
38
39
40
41
# File 'lib/social_snippet/repository/repository_factory.rb', line 33

def create(path, ref = nil, options = {})
  if has_git_dir?(path)
    repo = create_git_repo(path, ref)
    repo.load_snippet_json
    return repo
  end

  return nil
end

.create_git_repo(path, ref = nil) ⇒ Object


43
44
45
# File 'lib/social_snippet/repository/repository_factory.rb', line 43

def create_git_repo(path, ref = nil)
  ::SocialSnippet::Repository::Drivers::GitRepository.new(path, ref)
end

.has_git_dir?(dir_path) ⇒ Boolean


47
48
49
# File 'lib/social_snippet/repository/repository_factory.rb', line 47

def has_git_dir?(dir_path)
  Dir.exists?("#{dir_path}/.git")
end

.is_git_repo(uri) ⇒ Object


51
52
53
54
55
# File 'lib/social_snippet/repository/repository_factory.rb', line 51

def is_git_repo(uri)
  return true if uri.scheme === "git"
  return true if uri.host === "github.com"
  return false
end