Sha256: b0ca157520dccb354b43360d77b8170a841f2c52b9cb91668cdfa64d4963e08e

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

module Fontist
  module Resources
    class ArchiveResource
      def initialize(resource, options = {})
        @resource = resource
        @options = options
      end

      def files(_source_names, &block)
        excavate.files(recursive_packages: true, &block)
      end

      private

      def excavate
        Excavate::Archive.new(archive.path)
      end

      def archive
        download_file(@resource)
      end

      def download_file(source)
        errors = []
        source.urls.each do |request|
          result = try_download_file(request, source)
          return result unless result.is_a?(Errors::InvalidResourceError)

          errors << result
        end

        raise Errors::InvalidResourceError, errors.join(" ")
      end

      def try_download_file(request, source)
        info_log(request)

        Fontist::Utils::Downloader.download(
          request,
          sha: source.sha256,
          file_size: source.file_size,
          progress_bar: !@options[:no_progress],
        )
      rescue Errors::InvalidResourceError => e
        Fontist.ui.say(e.message)
        e
      end

      def info_log(request)
        url = request.respond_to?(:url) ? request.url : request
        Fontist.ui.say(%(Downloading from #{url}))
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fontist-1.21.2 lib/fontist/resources/archive_resource.rb
fontist-1.21.1 lib/fontist/resources/archive_resource.rb