Class: ElmInstall::Repository
- Extended by:
- Forwardable
- Defined in:
- lib/elm_install/repository.rb
Overview
Handles git repositories.
Constant Summary collapse
- @@fetched =
{}
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.
-
#fetch ⇒ Void
Fetches changes from a repository.
-
#fetched? ⇒ Bool
Returns if the repository has been fetched yet or not.
-
#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
100 101 102 103 104 105 |
# File 'lib/elm_install/repository.rb', line 100 def clone Logger.arrow "Package: #{url.bold} not found in cache, cloning..." FileUtils.mkdir_p path @@fetched[url] = true @repo = Git.clone(url, path) end |
#cloned? ⇒ Bool
Returns if the repository has been cloned yet or not
76 77 78 |
# File 'lib/elm_install/repository.rb', line 76 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 |
#fetch ⇒ Void
Fetches changes from a repository
90 91 92 93 94 |
# File 'lib/elm_install/repository.rb', line 90 def fetch return if fetched? repo.fetch @@fetched[url] = true end |
#fetched? ⇒ Bool
Returns if the repository has been fetched yet or not.
83 84 85 |
# File 'lib/elm_install/repository.rb', line 83 def fetched? @@fetched.key?(url) end |
#repo ⇒ Git::Base
Returns the existing repository or clones it if it does not exists.
66 67 68 69 70 71 |
# File 'lib/elm_install/repository.rb', line 66 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 60 |
# File 'lib/elm_install/repository.rb', line 53 def versions repo . .map(&:name) .select { |tag| tag =~ /(.*\..*\..*)/ } .map { |tag| Semverse::Version.try_new tag } .compact end |