Sha256: 2bfa1ed8e1911265492a052f278cd1c940d515ca7e13b3824f38b3783b7b2c9a

Contents?: true

Size: 1.78 KB

Versions: 9

Compression:

Stored size: 1.78 KB

Contents

require 'resync'
require_relative '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 # rubocop:disable Style/AccessorMethodName
          @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 # rubocop:disable Style/AccessorMethodName
          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

9 entries across 9 versions & 1 rubygems

Version Path
resync-client-0.4.3 lib/resync/client/mixins/downloadable.rb
resync-client-0.4.2 lib/resync/client/mixins/downloadable.rb
resync-client-0.4.1 lib/resync/client/mixins/downloadable.rb
resync-client-0.4.0 lib/resync/client/mixins/downloadable.rb
resync-client-0.3.5 lib/resync/client/mixins/downloadable.rb
resync-client-0.3.4 lib/resync/client/mixins/downloadable.rb
resync-client-0.3.3 lib/resync/client/mixins/downloadable.rb
resync-client-0.3.2 lib/resync/client/mixins/downloadable.rb
resync-client-0.3.1 lib/resync/client/mixins/downloadable.rb