Method: Docker::Util.file_hash_from_paths

Defined in:
lib/docker/util.rb

.file_hash_from_paths(local_paths) ⇒ Object

Convenience method to get the file hash corresponding to an array of local paths.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/docker/util.rb', line 58

def file_hash_from_paths(local_paths)
  local_paths.each_with_object({}) do |local_path, file_hash|
    unless File.exist?(local_path)
      raise ArgumentError, "#{local_path} does not exist."
    end

    basename = File.basename(local_path)
    if File.directory?(local_path)
      tar = create_dir_tar(local_path)
      file_hash[basename] = tar.read
      tar.close
      FileUtils.rm(tar.path)
    else
      file_hash[basename] = File.read(local_path)
    end
  end
end