Class: ElmInstall::Repository
- Extended by:
- Forwardable
- Defined in:
- lib/elm_install/repository.rb
Overview
Handles git repositories.
Instance Attribute Summary collapse
-
#fetched ⇒ Bool
readonly
Whether or not the repository has been fetched (updated).
-
#path ⇒ String
readonly
The path to the directory where the repository lives.
-
#url ⇒ String
readonly
The url of the git repository.
Class Method Summary collapse
-
.of(url, path) ⇒ Repository
Returns the repository for the given url and path.
Instance Method Summary collapse
-
#checkout(ref) ⇒ Dir
Checks out the version and returns it’s directory.
-
#clone ⇒ Git::Base
Clones the repository.
-
#cloned? ⇒ Bool
Returns if the repository has been cloned yet or not.
-
#directory ⇒ Dir
Returns the directory of the repository.
-
#fetch ⇒ Void
Fetches changes from a repository.
-
#initialize(url, path) ⇒ Repository
constructor
Initializes a repository.
-
#repo ⇒ Git::Base
Returns the existing repository or clones it if it does not exists.
-
#versions ⇒ Array<Semverse::Version>
Returns the versions of the repository.
Constructor Details
#initialize(url, path) ⇒ Repository
Initializes a repository.
37 38 39 40 41 42 |
# File 'lib/elm_install/repository.rb', line 37 def initialize(url, path) @fetched = false @path = path @url = url self end |
Instance Attribute Details
#fetched ⇒ Bool (readonly)
Whether or not the repository has been fetched (updated)
16 17 18 |
# File 'lib/elm_install/repository.rb', line 16 def fetched @fetched end |
#path ⇒ String (readonly)
The path to the directory where the repository lives
12 13 14 |
# File 'lib/elm_install/repository.rb', line 12 def path @path end |
#url ⇒ String (readonly)
The url of the git repository
8 9 10 |
# File 'lib/elm_install/repository.rb', line 8 def url @url end |
Class Method Details
.of(url, path) ⇒ Repository
Returns the repository for the given url and path
25 26 27 28 |
# File 'lib/elm_install/repository.rb', line 25 def self.of(url, path) @repositories ||= {} @repositories[url] ||= new url, path end |
Instance Method Details
#checkout(ref) ⇒ Dir
Checks out the version and returns it’s directory
50 51 52 53 |
# File 'lib/elm_install/repository.rb', line 50 def checkout(ref) repo.checkout ref directory end |
#clone ⇒ Git::Base
Clones the repository
109 110 111 112 113 114 |
# File 'lib/elm_install/repository.rb', line 109 def clone Logger.arrow "Package: #{url.bold} not found in cache, cloning..." FileUtils.mkdir_p path @fetched = true @repo = Git.clone(url, path) end |
#cloned? ⇒ Bool
Returns if the repository has been cloned yet or not
92 93 94 |
# File 'lib/elm_install/repository.rb', line 92 def cloned? Dir.exist?(path) end |
#directory ⇒ Dir
Returns the directory of the repository
59 60 61 62 |
# File 'lib/elm_install/repository.rb', line 59 def directory # This removes the .git from filename Dir.new(File.dirname(repo.repo.path)) end |
#fetch ⇒ Void
Fetches changes from a repository
99 100 101 102 103 |
# File 'lib/elm_install/repository.rb', line 99 def fetch return if fetched repo.fetch @fetched = true end |
#repo ⇒ Git::Base
Returns the existing repository or clones it if it does not exists.
82 83 84 85 86 87 |
# File 'lib/elm_install/repository.rb', line 82 def repo clone unless cloned? @repo ||= Git.open path @repo.reset_hard @repo end |
#versions ⇒ Array<Semverse::Version>
Returns the versions of the repository
68 69 70 71 72 73 74 75 76 |
# File 'lib/elm_install/repository.rb', line 68 def versions @versions ||= repo . .map(&:name) .select { |tag| tag =~ /(.*\..*\..*)/ } .map { |tag| Semverse::Version.try_new tag } .compact end |