module Figs::GitHandler

Constants

TMP_GIT_DIR

Public Instance Methods

clear_temp_files() click to toggle source
# File lib/figs/git_handler.rb, line 19
def clear_temp_files
  return unless !@temp_files.nil?
  @temp_files.each do |temp_file|
    temp_file.close
    temp_file.unlink
  end
end
location(gitpath, filenames) click to toggle source
# File lib/figs/git_handler.rb, line 9
def location(gitpath, filenames)
  @temp_files = []
  git_clone gitpath
  temp_filenames(([]<< Figs::DirectoryFlattener.flattened_filenames(filenames.collect {|filename| "#{TMP_GIT_DIR}#{filename}"})).flatten)
rescue Exception => e
  puts e
  clear_tmp_dir
  clear_temp_files
end

Private Instance Methods

clear_tmp_dir() click to toggle source
# File lib/figs/git_handler.rb, line 50
def clear_tmp_dir
  FileUtils.rm_rf TMP_GIT_DIR
end
copy_to_temp_files(filename) click to toggle source
# File lib/figs/git_handler.rb, line 36
def copy_to_temp_files(filename)
  temp_file = Tempfile.new("#{filename.gsub('/','-')}")
  temp_file.open
  temp_file.write(File.open("#{filename}").read)
  temp_file.flush
  @temp_files << temp_file
  temp_file.path
end
git_clone(gitpath) click to toggle source
# File lib/figs/git_handler.rb, line 45
def git_clone(gitpath)
  clear_tmp_dir
  ::Git.clone gitpath, TMP_GIT_DIR
end
temp_filenames(filenames) click to toggle source
# File lib/figs/git_handler.rb, line 29
def temp_filenames(filenames)
  temp_files = []
  filenames.each { |filename| temp_files << copy_to_temp_files(filename) }
  clear_tmp_dir
  temp_files
end