Class: Vendor::VendorFile::Library::Git

Inherits:
Base
  • Object
show all
Defined in:
lib/vendor/vendor_file/library/git.rb

Defined Under Namespace

Classes: GitError

Instance Attribute Summary collapse

Attributes inherited from Base

#name, #parent, #require, #targets, #version

Instance Method Summary collapse

Methods inherited from Base

#<=>, #==, #build_settings, #dependencies, #description, #files, #frameworks, #per_file_flag, #resources, #version_matches_any?

Constructor Details

#initialize(attributes = {}) ⇒ Git

Returns a new instance of Git.



18
19
20
21
22
# File 'lib/vendor/vendor_file/library/git.rb', line 18

def initialize(attributes = {})
  attributes[:tag] ||= attributes[:ref] || attributes[:branch] || "master"

  super(attributes)
end

Instance Attribute Details

#tagObject

Returns the value of attribute tag.



12
13
14
# File 'lib/vendor/vendor_file/library/git.rb', line 12

def tag
  @tag
end

#uriObject

Returns the value of attribute uri.



11
12
13
# File 'lib/vendor/vendor_file/library/git.rb', line 11

def uri
  @uri
end

Instance Method Details

#cache_pathObject

If you change the git path, and not the lib name, we want to update the sources correctly. So instead of using the name, use a hash of the URI



46
47
48
# File 'lib/vendor/vendor_file/library/git.rb', line 46

def cache_path
  File.join(Vendor.library_path, "git", Digest::MD5.hexdigest(uri)) if uri
end

#display_nameObject



50
51
52
# File 'lib/vendor/vendor_file/library/git.rb', line 50

def display_name
  [ name, "(#{uri}##{tag})" ].join(' ')
end

#downloadObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vendor/vendor_file/library/git.rb', line 24

def download
  if File.exist?(cache_path)
    Vendor.ui.info "Updating #{uri}"

    Dir.chdir(cache_path) do
      git %|fetch --force --quiet --tags #{uri_escaped}|
    end
  else
    Vendor.ui.info "Fetching #{uri}"

    FileUtils.mkdir_p(cache_path)
    git %|clone #{uri_escaped} "#{cache_path}"|
  end

  Dir.chdir(cache_path) do
    git "reset --hard #{tag}"
  end
end