Sha256: 63629669e0476e0b4331a8898e452f78c689dbd1aaf58d668bf243d185caffa8
Contents?: true
Size: 837 Bytes
Versions: 19
Compression:
Stored size: 837 Bytes
Contents
# frozen_string_literal: true require 'eac_fs/patches' require 'eac_ruby_utils/fs/temp' module Avm class CachedDownload attr_reader :url, :fs_cache def initialize(url, parent_fs_cache = nil) @url = url @fs_cache = (parent_fs_cache || fs_cache).child(url.parameterize) end def assert download unless fs_cache.cached? end def download ::EacRubyUtils::Fs::Temp.on_file do |temp| download_to(temp) fs_cache.content_path.to_pathname.dirname.mkpath ::FileUtils.mv(temp.to_path, fs_cache.content_path) end end def path fs_cache.content_path.to_pathname end private def download_to(local_file) ::URI.parse(url).open do |remote| local_file.open('wb') { |handle| handle.write(remote.read) } end end end end
Version data entries
19 entries across 19 versions & 3 rubygems