Class: Imagen::Clone

Inherits:
Object
  • Object
show all
Defined in:
lib/imagen/clone.rb

Overview

Responsible for cloning a Git repository into a given tempdir

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_url, dirname) ⇒ Clone

Returns a new instance of Clone.



17
18
19
20
21
22
23
24
# File 'lib/imagen/clone.rb', line 17

def initialize(repo_url, dirname)
  unless repo_url.match?(/^https:\/\//)
    raise ArgumentError, 'repo_url must start with https://'
  end

  @repo_url = repo_url
  @dir = dirname
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



15
16
17
# File 'lib/imagen/clone.rb', line 15

def dir
  @dir
end

#repo_urlObject (readonly)

Returns the value of attribute repo_url.



15
16
17
# File 'lib/imagen/clone.rb', line 15

def repo_url
  @repo_url
end

Class Method Details

.perform(repo_url, dir) ⇒ Object



11
12
13
# File 'lib/imagen/clone.rb', line 11

def self.perform(repo_url, dir)
  new(repo_url, dir).perform
end

Instance Method Details

#performObject



26
27
28
29
30
31
32
# File 'lib/imagen/clone.rb', line 26

def perform
  cmd = "GIT_TERMINAL_PROMPT=0 git clone #{repo_url} #{dir}"
  Open3.popen3(cmd) do |_s_in, _s_out, s_err, wait_thr|
    err_msg = s_err.read
    raise GitError, err_msg unless wait_thr.value.exitstatus.zero?
  end
end