Sha256: 928c890db13b568f5d094e01d3c8f3f0c3e73f8f5f3163f4c7aff1813ac3e8ea

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

require 'resync'
require 'resync/client/mixins/client_delegator'

module Resync
  class Client
    module Mixins
      # A downloadable resource or link.
      module Downloadable
        prepend ClientDelegator

        # Delegates to {Client#get_and_parse} to get the contents of
        # +:uri+ as a ResourceSync document. The downloaded, parsed
        # document will only be downloaded once; subsequent calls to
        # this method will return the cached document.
        def get_and_parse # rubocop:disable Style/AccessorMethodName
          @parsed_content ||= client.get_and_parse(uri)
        end

        # Delegates to {Client#get} to get the contents of this +:uri+.
        # The downloaded content will only be downloaded once; subsequent
        # calls to this method will return the cached content.
        def get
          @content ||= client.get(uri)
        end

        # Delegates to {Client#download_to_temp_file} to download the
        # contents of +:uri+ to a file. Subsequent calls will download
        # the contents again, each time to a fresh temporary file.
        def download_to_temp_file
          client.download_to_temp_file(uri)
        end

        # Delegates to {Client#download_to_file} to download the
        # contents of +:uri+ to the specified path. Subsequent
        # calls wiill download the contents again, potentially
        # overwriting the file if given the same path.
        # @param path [String] the path to download to
        def download_to_file(path)
          client.download_to_file(uri: uri, path: path)
        end
      end
    end
  end

  class Link
    prepend Client::Mixins::Downloadable
  end

  class Resource
    prepend Client::Mixins::Downloadable
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
resync-client-0.4.7 lib/resync/client/mixins/downloadable.rb
resync-client-0.4.6 lib/resync/client/mixins/downloadable.rb