Class: ElmInstall::Repository

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/elm_install/repository.rb

Overview

Handles git repositories.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, path) ⇒ Repository

Initializes a repository.

Parameters:

  • url (String)

    The url

  • path (String)

    The path



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

#pathString (readonly)

The path to the directory where the repository lives

Returns:

  • (String)


12
13
14
# File 'lib/elm_install/repository.rb', line 12

def path
  @path
end

#urlString (readonly)

The url of the git repository

Returns:

  • (String)


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

Parameters:

  • ref (String)

    The reference to checkout

Returns:

  • (Dir)

    The directory



35
36
37
38
# File 'lib/elm_install/repository.rb', line 35

def checkout(ref)
  repo.checkout ref
  directory
end

#cloneGit::Base

Clones the repository

Returns:

  • (Git::Base)


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

Returns:

  • (Bool)


75
76
77
# File 'lib/elm_install/repository.rb', line 75

def cloned?
  Dir.exist?(path)
end

#directoryDir

Returns the directory of the repository

Returns:

  • (Dir)

    The directory



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

#repoGit::Base

Returns the existing repository or clones it if it does not exists.

Returns:

  • (Git::Base)


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

#versionsArray<Semverse::Version>

Returns the versions of the repository

Returns:



53
54
55
56
57
58
59
# File 'lib/elm_install/repository.rb', line 53

def versions
  repo
    .tags
    .map(&:name)
    .map { |tag| Semverse::Version.try_new tag }
    .compact
end