Class: Amp::Repositories::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/amp/repository/repository.rb

Overview

Repository

This is an abstract class that represents a repository. All repositories must inherit from this class.

Direct Known Subclasses

HTTPRepository, LocalRepository

Instance Method Summary collapse

Instance Method Details

#add_path(path) ⇒ String

Joins the given path with our URL. Necessary due to the difference between local and remote repos.

Parameters:

  • path (String)

    the path we are appending

Returns:

  • (String)

    our URL joined with the requested path



84
85
86
87
88
89
90
91
# File 'lib/amp/repository/repository.rb', line 84

def add_path(path)
  myurl = self.url
  if myurl.end_with? '/'
    myurl + path
  else
    myurl + '/' + path
  end
end

#can_copy?Boolean

can we copy files? Only for local repos.

Returns:

  • (Boolean)

    whether we are able to copy files



74
75
76
# File 'lib/amp/repository/repository.rb', line 74

def can_copy?
  local?
end

#capable?(capability) ⇒ Boolean, String

Is this repository capable of the given action/format? Or, if the capability has a value assigned to it (like “revlog” = “version2”), what is it?

Parameters:

  • capability (String)

    the name of the action/format/what have you that we need to test

Returns:

  • (Boolean, String)

    whether or not we support the given capability; or, for capabilities that have a value, the string value.



39
40
41
42
# File 'lib/amp/repository/repository.rb', line 39

def capable?(capability)
  get_capabilities
  @capabilities[capability]
end

#get_capabilitiesObject

No-op, to be implemented by remote repo classes.



46
# File 'lib/amp/repository/repository.rb', line 46

def get_capabilities; end

#local?Boolean

is the repository a local repo?

Returns:

  • (Boolean)

    is the repository local?



66
67
68
# File 'lib/amp/repository/repository.rb', line 66

def local?
  false
end

#require_capability(capability, purpose) ⇒ Object

Raises an exception if we don’t have a given capability.

Parameters:

  • capability (String)

    what capability we are requiring

  • purpose (String)

    why we need it - enhances the output

Raises:



54
55
56
57
58
59
60
# File 'lib/amp/repository/repository.rb', line 54

def require_capability(capability, purpose)
  get_capabilities
  raise RepositoryCapabilityError.new(<<-EOF
  Can't #{purpose}; remote repository doesn't support the #{capability} capability.
  EOF
  ) unless @capabilities[capability]
end