Sha256: 70432df1880d845cf65160b9afc67cc9ea4ddf7a4ebdafc91bfe32083d445669

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module PEBuild
  module Transfer

    class UnhandledURIScheme < Vagrant::Errors::VagrantError
      error_key('unhandled_uri_scheme', 'pebuild.transfer')
    end

    require 'pe_build/transfer/open_uri'
    require 'pe_build/transfer/file'

    IMPLEMENTATIONS = {
      'http'  => PEBuild::Transfer::OpenURI,
      'https' => PEBuild::Transfer::OpenURI,
      'ftp'   => PEBuild::Transfer::OpenURI,
      'file'  => PEBuild::Transfer::File,
      nil     => PEBuild::Transfer::File, # Assume that URIs without a scheme are files
    }

    # @param src [URI] The local file path path to the file to copy
    # @param dst [String] The path to destination of the copied file
    def self.copy(src, dst)
      scheme = src.scheme

      if (mod = IMPLEMENTATIONS[scheme])
        mod.copy(src, dst)
      else
        raise UnhandledURIScheme, :scheme => scheme,
                                  :supported => IMPLEMENTATIONS.keys
      end
    end

    # Return the contents of a local or remote file.
    #
    # @param src [URI] The URI of the source file.
    # @raises [UnhandledURIScheme] If the URI uses an unsupported scheme.
    # @return [String] The contents of the source file.
    #
    # @since 0.9.0
    def self.read(src)
      scheme = src.scheme

      if (mod = IMPLEMENTATIONS[scheme])
        mod.read(src)
      else
        raise UnhandledURIScheme, :scheme => scheme,
                                  :supported => IMPLEMENTATIONS.keys
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-pe_build-0.9.0 lib/pe_build/transfer.rb