Sha256: a3f335d32e9147695dec8f4409b4c00fe91f2ef6c26e031d7944a930e7996ced

Contents?: true

Size: 1.45 KB

Versions: 53

Compression:

Stored size: 1.45 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.
    # @raise [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

53 entries across 53 versions & 1 rubygems

Version Path
vagrant-pe_build-0.19.2 lib/pe_build/transfer.rb
vagrant-pe_build-0.19.1 lib/pe_build/transfer.rb
vagrant-pe_build-0.19.0 lib/pe_build/transfer.rb
vagrant-pe_build-0.18.2 lib/pe_build/transfer.rb
vagrant-pe_build-0.18.1 lib/pe_build/transfer.rb
vagrant-pe_build-0.18.0 lib/pe_build/transfer.rb
vagrant-pe_build-0.17.14 lib/pe_build/transfer.rb
vagrant-pe_build-0.17.13 lib/pe_build/transfer.rb
vagrant-pe_build-0.17.12 lib/pe_build/transfer.rb
vagrant-pe_build-0.17.11 lib/pe_build/transfer.rb
vagrant-pe_build-0.17.10 lib/pe_build/transfer.rb
vagrant-pe_build-0.17.9 lib/pe_build/transfer.rb
vagrant-pe_build-0.17.8 lib/pe_build/transfer.rb
vagrant-pe_build-0.17.7 lib/pe_build/transfer.rb
vagrant-pe_build-0.17.6 lib/pe_build/transfer.rb
vagrant-pe_build-0.17.5 lib/pe_build/transfer.rb
vagrant-pe_build-0.17.4 lib/pe_build/transfer.rb
vagrant-pe_build-0.17.3 lib/pe_build/transfer.rb
vagrant-pe_build-0.17.2 lib/pe_build/transfer.rb
vagrant-pe_build-0.17.1 lib/pe_build/transfer.rb