Class: Buildr::Transports::Transport

Inherits:
Object
  • Object
show all
Defined in:
lib/core/transports.rb

Direct Known Subclasses

HTTP, SFTP

Defined Under Namespace

Classes: Digester

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options) ⇒ Transport

Returns a new instance of Transport.



74
75
76
77
78
79
# File 'lib/core/transports.rb', line 74

def initialize(url, options)
  @uri = URI.parse(url.to_s)
  @base_path = @uri.path || "/"
  @base_path += "/" unless @base_path[-1] == ?/
  @options = options || {}
end

Instance Attribute Details

#base_pathObject (readonly)

The base path on the server, always ending with a slash.



70
71
72
# File 'lib/core/transports.rb', line 70

def base_path
  @base_path
end

#optionsObject (readonly)

Options passed during construction.



72
73
74
# File 'lib/core/transports.rb', line 72

def options
  @options
end

#uriObject (readonly)

The server URI.



68
69
70
# File 'lib/core/transports.rb', line 68

def uri
  @uri
end

Class Method Details

.perform(url, options = nil) ⇒ Object

Perform one or more operations using an open connection to the specified URL. For examples, see #download and #upload.



57
58
59
60
61
62
63
64
# File 'lib/core/transports.rb', line 57

def perform(url, options = nil)
  instance = new(url, options)
  begin
    yield instance
  ensure
    instance.close
  end
end

Instance Method Details

#download(path, target, &block) ⇒ Object

Downloads a file from the specified path, relative to the server URI. Downloads to either the target file, or by calling the block with each chunk of the file.

For example:

Transports.perform("http://server/libs") do |http|
  http.download("my_project/test.jar", "test.jar")
  http.download("my_project/readme") { |text| $stdout.write text }
end


90
91
92
# File 'lib/core/transports.rb', line 90

def download(path, target, &block)
  fail "Upload not implemented for this transport"
end

#mkpath(path) ⇒ Object

Creates a path on the server relative to the server URI. See #upload for example.



108
109
110
# File 'lib/core/transports.rb', line 108

def mkpath(path)
  fail "Upload not implemented for this transport"
end

#upload(source, path) ⇒ Object

Uploads a file (source) to the server at the specified path, relative to the server URI.

For example:

Transports.perform("sftp://server/libs") do |sftp|
  sftp.mkpath "my_project"
  sftp.upload("target/test.jar", "my_project/test.jar")
end


102
103
104
# File 'lib/core/transports.rb', line 102

def upload(source, path)
  fail "Upload not implemented for this transport"
end