Class: ElmInstall::Repository
- Extended by:
- Forwardable
- Defined in:
- lib/elm_install/repository.rb
Overview
Handles git repositories.
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
The path to the directory where the repository lives.
-
#url ⇒ String
readonly
The url of the git repository.
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.
-
#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.
23 24 25 26 27 |
# File 'lib/elm_install/repository.rb', line 23 def initialize(url, path) @path = path @url = url self end |
Instance Attribute Details
#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 |
Instance Method Details
#checkout(ref) ⇒ Dir
Checks out the version and returns it’s directory
35 36 37 38 |
# File 'lib/elm_install/repository.rb', line 35 def checkout(ref) repo.checkout ref directory end |
#clone ⇒ Git::Base
Clones the repository
83 84 85 86 87 |
# File 'lib/elm_install/repository.rb', line 83 def clone Logger.arrow "Package: #{url.bold} not found in cache, cloning..." FileUtils.mkdir_p path @repo = Git.clone(url, path) end |
#cloned? ⇒ Bool
Returns if the repository has been cloned yet or not
75 76 77 |
# File 'lib/elm_install/repository.rb', line 75 def cloned? Dir.exist?(path) end |
#directory ⇒ Dir
Returns the directory of the repository
44 45 46 47 |
# File 'lib/elm_install/repository.rb', line 44 def directory # This removes the .git from filename Dir.new(File.dirname(repo.repo.path)) end |
#repo ⇒ Git::Base
Returns the existing repository or clones it if it does not exists.
65 66 67 68 69 70 |
# File 'lib/elm_install/repository.rb', line 65 def repo clone unless cloned? @repo ||= Git.open path @repo.reset_hard @repo end |
#versions ⇒ Array<Semverse::Version>
Returns the versions of the repository
53 54 55 56 57 58 59 |
# File 'lib/elm_install/repository.rb', line 53 def versions repo . .map(&:name) .map { |tag| Semverse::Version.try_new tag } .compact end |