Module: FileDependencies

Defined in:
lib/file-dependencies.rb,
lib/file-dependencies/gem.rb,
lib/file-dependencies/file.rb,
lib/file-dependencies/archive.rb,
lib/file-dependencies/version.rb

Overview

Note to authors: this should not include dashes because 'gem' barfs if you include a dash in the version string.

Defined Under Namespace

Modules: Archive, File, Gem

Constant Summary collapse

VERSION =
'0.1.4'

Class Method Summary collapse

Class Method Details

.process_downloads(files, target, tmpdir) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/file-dependencies.rb', line 20

def process_downloads(files, target, tmpdir)
  FileUtils.mkdir_p(target) unless ::File.directory?(target)
  files.each do |file|
    full_target = file['target'] ? ::File.join(target, file['target']) : target
    download = FileDependencies::File.fetch_file(file['url'], file['sha1'], tmpdir)
    if (res = download.match(/(\S+?)(\.tar\.gz|\.tgz)$/))
      FileDependencies::Archive.untar(download) do |entry|
        prefix = file['include_tar_prefix'] ? '' : ::File.join(entry.full_name.split(::File::SEPARATOR).first, '')
        next unless FileDependencies::Archive.extract_file?(entry.full_name, file['extract'], file['exclude'], prefix)
        if file['flatten'] == true
          ::File.join(full_target, ::File.basename(entry.full_name))
        else
          ::File.join(full_target, entry.full_name.gsub(prefix, ''))
        end
      end
    elsif download =~ /.gz$/
      FileDependencies::Archive.ungzip(download, full_target)
    else
      FileUtils.mv(download, ::File.join(full_target, ::File.basename(download)))
    end
  end
end

.process_vendor(dir, target = 'vendor', tmpdir = Dir.tmpdir) ⇒ Object


8
9
10
11
12
13
14
15
16
17
# File 'lib/file-dependencies.rb', line 8

def process_vendor(dir, target = 'vendor', tmpdir = Dir.tmpdir)
  vendor_file = ::File.join(dir, 'vendor.json')
  if ::File.exist?(vendor_file)
    vendor_file_content = IO.read(vendor_file)
    file_list = JSON.load(vendor_file_content)
    FileDependencies.process_downloads(file_list, ::File.join(dir, target), tmpdir)
  else
    puts "vendor.json not found, looked for the file at #{vendor_file}" if $DEBUG
  end
end