Class: Chrysalis::Repository

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

Overview

Represents a repository from which dependencies can be retrieved.

This class is intended to be subclassed in order to implement support for concrete types of repositories.

Constant Summary collapse

@@repositories =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, params = {}) ⇒ Repository

Returns a new instance of Repository.



57
58
# File 'lib/chrysalis/repository.rb', line 57

def initialize(url, params = {})
end

Class Method Details

.inherited(repository) ⇒ Object

:nodoc:



14
15
16
# File 'lib/chrysalis/repository.rb', line 14

def self.inherited(repository)  # :nodoc:
  @@repositories << repository
end

.retrieve(url, to = '.', params = {}) ⇒ Object

Retrieves a WorkingCopy from the repository located at url. The working copy is placed at the path to, which defaults to the current directory. An optional set of parameters can be specified in params.

Returns a WorkingCopy.

Using the factory design pattern, this method locates a subclass of Repository that implements support for the given URL. That subclass will be instructed to retrieve a working copy from the repository.

If the working copy has already been retrieved, it will be found in the cache and returned directly.

If support for the given URL is not implemented, a RepositoryError will be raised.

Raises:



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/chrysalis/repository.rb', line 33

def self.retrieve(url, to = '.', params = {})
  cached = WorkingCopy.create(Chrysalis::Cache.instance[url])
  return cached if cached
  
  @@repositories.reverse.each { |repository|
    if repository.retrieves?(url, params)
      working_copy = repository.new(url, params).retrieve(to)
      Chrysalis::Cache.instance[url] = working_copy
      return working_copy
    end
  }
  raise RepositoryError, "Unknown version control system. (URL: #{url})"
end

.retrieves?(url, params = {}) ⇒ Boolean

Returns true if this class implements support for url. Otherwise, returns false.

Because this class is abstract, false is returned unconditionally. Subclasses are expected to provide an implementation.

Returns:

  • (Boolean)


53
54
55
# File 'lib/chrysalis/repository.rb', line 53

def self.retrieves?(url, params = {})
  false
end

Instance Method Details

#retrieve(to = '.') ⇒ Object

Retrieves a working copy from the repository.

Because this class is abstract, always raises an UnimplementedError. Subclasses are expected to provide an implementation.

Raises:



64
65
66
# File 'lib/chrysalis/repository.rb', line 64

def retrieve(to = '.')
  raise UnimplementedError, "Repository#retrieve not implemented"
end