Class: Raykit::Git::Files

Inherits:
Object
  • Object
show all
Defined in:
lib/raykit/git/files.rb

Overview

Functionality to manage a local clone of a git repository

Instance Method Summary collapse

Constructor Details

#initialize(url, commit_id) ⇒ Files

Returns a new instance of Files.



10
11
12
13
# File 'lib/raykit/git/files.rb', line 10

def initialize(url, commit_id)
  @url = url
  @commit_id = commit_id
end

Instance Method Details

#cleanObject



15
16
17
# File 'lib/raykit/git/files.rb', line 15

def clean
  FileUtils.rm_rf(commit_path) if Dir.exist?(commit_path)
end

#commit_pathObject



36
37
38
39
# File 'lib/raykit/git/files.rb', line 36

def commit_path
  Dir.tmpdir + File::SEPARATOR + "Raykit.Git.Files" + File::SEPARATOR + @url.gsub("://",
                                                                                  ".") + File::SEPARATOR + @commit_id
end

#filename(name) ⇒ Object



41
42
43
# File 'lib/raykit/git/files.rb', line 41

def filename(name)
  commit_path + File::SEPARATOR + name
end

#get(name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/raykit/git/files.rb', line 19

def get(name)
  puts "commit_path(): #{commit_path}"
  unless Dir.exist?(commit_path)
    puts "cloning commit path..."
    clone = Raykit::Command.new("git clone #{@url} #{commit_path}")
    puts clone.output
    puts clone.error
    Dir.chdir(commit_path) do
      checkout = Raykit::Command.new("git checkout #{@commit_id}")
    end
  end

  return filename(name) if File.exist?(filename(name))

  ""
end