Sha256: 06e909f8c668a457510045bb6206a25ea73f7dd53b275954fad42ca534eecc8a
Contents?: true
Size: 1.41 KB
Versions: 5
Compression:
Stored size: 1.41 KB
Contents
require "open-uri" module Lambdagem::Extract autoload :ClassMethods, 'lambdagem/extract/class_methods' class Base < Lambdagem::Base extend ClassMethods def clean_downloads(folder) path = "#{@build_root}/downloads/#{folder}" puts "Removing cache: #{path}" FileUtils.rm_rf(path) end def unpack_tarball(tarball_path) dest = project_root puts "Unpacking into #{dest}" FileUtils.mkdir_p(dest) untar(tarball_path, dest) end def untar(tarball_path, parent_folder_dest) sh("tar -xzf #{tarball_path} -C #{parent_folder_dest}") end def sh(command) puts "=> #{command}".colorize(:green) success = system(command) abort("Command Failed") unless success success end def url_exists?(url) self.class.url_exists?(url) end # Returns the dest path def download_file(source_url, dest) puts "Url #{source_url}" return unless url_exists?(source_url) if File.exist?(dest) puts "File already downloaded #{dest}" return dest end puts "Downloading..." FileUtils.mkdir_p(File.dirname(dest)) # ensure parent folder exists File.open(dest, 'wb') do |saved_file| open(source_url, 'rb') do |read_file| saved_file.write(read_file.read) end end dest end def project_root @options[:project_root] || "." end end end
Version data entries
5 entries across 5 versions & 1 rubygems