Class: Buildr::Transports::Transport
- Inherits:
-
Object
- Object
- Buildr::Transports::Transport
- Defined in:
- lib/core/transports.rb
Defined Under Namespace
Classes: Digester
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
The base path on the server, always ending with a slash.
-
#options ⇒ Object
readonly
Options passed during construction.
-
#uri ⇒ Object
readonly
The server URI.
Class Method Summary collapse
-
.perform(url, options = nil) ⇒ Object
Perform one or more operations using an open connection to the specified URL.
Instance Method Summary collapse
-
#download(path, target, &block) ⇒ Object
Downloads a file from the specified path, relative to the server URI.
-
#initialize(url, options) ⇒ Transport
constructor
A new instance of Transport.
-
#mkpath(path) ⇒ Object
Creates a path on the server relative to the server URI.
-
#upload(source, path) ⇒ Object
Uploads a file (source) to the server at the specified path, relative to the server URI.
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, ) @uri = URI.parse(url.to_s) @base_path = @uri.path || "/" @base_path += "/" unless @base_path[-1] == ?/ @options = || {} end |
Instance Attribute Details
#base_path ⇒ Object (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 |
#options ⇒ Object (readonly)
Options passed during construction.
72 73 74 |
# File 'lib/core/transports.rb', line 72 def @options end |
#uri ⇒ Object (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, = nil) instance = new(url, ) 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 |