Class: Regrit::RemoteRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/regrit/remote_repo.rb

Constant Summary collapse

REFS_REGEXP =
/^[0-9a-f]{40}\t\w/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, options = {}) ⇒ RemoteRepo

Returns a new instance of RemoteRepo.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/regrit/remote_repo.rb', line 11

def initialize(uri, options={})
  if uri.nil? || uri.empty?
    raise InvalidURIError
  end

  begin
    @uri = Gitable::URI.parse(uri)
  rescue TypeError, Gitable::URI::InvalidURIError
    raise InvalidURIError
  end

  if @uri.interactive_authenticated?
    raise InvalidURIError
  end

  @options = options
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



9
10
11
# File 'lib/regrit/remote_repo.rb', line 9

def uri
  @uri
end

Instance Method Details

#accessible?Boolean

Attempt to grab refs. If the repository is auth required and a private key is passed, use ssh to attempt access to the repository.

Returns:

  • (Boolean)

    can the repository be accessed?



39
40
41
42
43
# File 'lib/regrit/remote_repo.rb', line 39

def accessible?
  !!refs
rescue Inaccessible
  false
end

#private_key_required?Boolean

Decide if the URI is likely to require authentication

Returns:

  • (Boolean)

    Does the repo require auth?



31
32
33
# File 'lib/regrit/remote_repo.rb', line 31

def private_key_required?
  @uri.ssh?
end

#ref(named) ⇒ Ref?

Use a git ls-remote to find a single ref

Returns:

  • (Ref, nil)

    A Ref object or nil



55
56
57
# File 'lib/regrit/remote_repo.rb', line 55

def ref(named)
  load_refs(named).detect { |ref| ref.match?(named) }
end

#refsArray

Use a git ls-remote to load all repository refs

Returns:

  • (Array)

    An Array of Ref objects



48
49
50
# File 'lib/regrit/remote_repo.rb', line 48

def refs
  @refs ||= load_refs
end