Class: Amp::Core::Repositories::GenericRepoPicker
- Inherits:
-
Object
- Object
- Amp::Core::Repositories::GenericRepoPicker
- Extended by:
- Enumerable
- Defined in:
- lib/amp-core/repository/generic_repo_picker.rb
Overview
This class is a generic “repo picker”. It will return a Repository object for the given path (if there is one), and is capable of telling you if there is a repository of its type in the given directory.
Amp started off with a MercurialPicker - it knows how to find Mercurial repos.
When amp runs, it iterates over all subclasses of AbstractRepoPicker, in no guaranteed order (so don’t stomp on existing pickers!), calling #repo_in_dir? . If only one picker returns true
, then that picker is used for opening the repository. If more than one returns true
, the user’s configuration is consulted. If nothing is found then, then the user is prompted. When the final picker has been chosen, its #pick method is called to get the repository for the directory/URL.
This is an “abstract” class, in that all the methods will raise a NotImplementedError if you try to call them.
You must subclass this class, or your custom repo code will be ignored by Amp’s dispatch system.
Class Attribute Summary collapse
-
.all_pickers ⇒ Object
Returns the value of attribute all_pickers.
Class Method Summary collapse
-
.each(*args, &block) ⇒ Object
Iterate over every RepoPicker in the system.
Instance Method Summary collapse
-
#pick(config, path = '', create = false) ⇒ AbstractLocalRepository
Returns a repository object for the given path.
-
#repo_in_dir?(path) ⇒ Boolean
(also: #repo_in_url?)
Returns whether or not there is a repository in the given directory.
Class Attribute Details
.all_pickers ⇒ Object
Returns the value of attribute all_pickers.
42 43 44 |
# File 'lib/amp-core/repository/generic_repo_picker.rb', line 42 def all_pickers @all_pickers end |
Class Method Details
.each(*args, &block) ⇒ Object
Iterate over every RepoPicker in the system.
46 47 48 |
# File 'lib/amp-core/repository/generic_repo_picker.rb', line 46 def each(*args, &block) @all_pickers.each(*args, &block) end |
Instance Method Details
#pick(config, path = '', create = false) ⇒ AbstractLocalRepository
Returns a repository object for the given path. Should respond to the standard repository API to the best of its ability, and raise a CapabilityError if asked to do something it cannot do from the API.
88 89 90 |
# File 'lib/amp-core/repository/generic_repo_picker.rb', line 88 def pick(config, path = '', create = false) raise NotImplementedError.new("repo_in_dir? must be implemented in a concrete subclass.") end |
#repo_in_dir?(path) ⇒ Boolean Also known as: repo_in_url?
Returns whether or not there is a repository in the given directory. This picker should only be responsible for one type of repository - git, svn, hg, etc. The given path could be deep inside a repository, and must look in parent directories for the root of the VCS repository.
73 74 75 |
# File 'lib/amp-core/repository/generic_repo_picker.rb', line 73 def repo_in_dir?(path) raise NotImplementedError.new("repo_in_dir? must be implemented in a concrete subclass.") end |