Class: ElmInstall::Repository

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

Overview

Handles git repositories.

Constant Summary collapse

@@fetched =
{}

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)


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

Returns:

  • (Bool)


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

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

#fetchVoid

Fetches changes from a repository

Returns:

  • (Void)


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.

Returns:

  • (Bool)


83
84
85
# File 'lib/elm_install/repository.rb', line 83

def fetched?
  @@fetched.key?(url)
end

#repoGit::Base

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

Returns:

  • (Git::Base)


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

#versionsArray<Semverse::Version>

Returns the versions of the repository

Returns:



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

def versions
  repo
    .tags
    .map(&:name)
    .select { |tag| tag =~ /(.*\..*\..*)/ }
    .map { |tag| Semverse::Version.try_new tag }
    .compact
end