Class: Net::SFTP::Response
- Inherits:
-
Object
- Object
- Net::SFTP::Response
- Includes:
- Constants::StatusCodes
- Defined in:
- lib/net/sftp/response.rb
Overview
Encapsulates a response from the remote server, to a specific client request. Response objects are passed as parameters to callbacks when you are performing asynchronous operations; when you call Net::SFTP::Request#wait, you can get the corresponding response object via Net::SFTP::Request#response.
sftp.open("/path/to/file") do |response|
p response.ok?
p response[:handle]
end
sftp.loop
Constant Summary collapse
- MAP =
–
constants.inject({}) do |memo, name| next memo unless name =~ /^FX_(.*)/ memo[const_get(name)] = $1.downcase.tr("_", " ") memo end
Constants included from Constants::StatusCodes
Constants::StatusCodes::FX_BAD_MESSAGE, Constants::StatusCodes::FX_CONNECTION_LOST, Constants::StatusCodes::FX_DIR_NOT_EMPTY, Constants::StatusCodes::FX_EOF, Constants::StatusCodes::FX_FAILURE, Constants::StatusCodes::FX_FILE_ALREADY_EXISTS, Constants::StatusCodes::FX_INVALID_FILENAME, Constants::StatusCodes::FX_INVALID_HANDLE, Constants::StatusCodes::FX_LINK_LOOP, Constants::StatusCodes::FX_LOCK_CONFlICT, Constants::StatusCodes::FX_NOT_A_DIRECTORY, Constants::StatusCodes::FX_NO_CONNECTION, Constants::StatusCodes::FX_NO_MEDIA, Constants::StatusCodes::FX_NO_SPACE_ON_FILESYSTEM, Constants::StatusCodes::FX_NO_SUCH_FILE, Constants::StatusCodes::FX_NO_SUCH_PATH, Constants::StatusCodes::FX_OK, Constants::StatusCodes::FX_OP_UNSUPPORTED, Constants::StatusCodes::FX_PERMISSION_DENIED, Constants::StatusCodes::FX_QUOTA_EXCEEDED, Constants::StatusCodes::FX_UNKNOWN_PRINCIPLE, Constants::StatusCodes::FX_WRITE_PROTECT
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
The numeric code, one of the FX_* constants.
-
#data ⇒ Object
readonly
A hash of request-specific data, such as a file handle or attribute information.
-
#message ⇒ Object
readonly
The textual message for this response (possibly blank).
-
#request ⇒ Object
readonly
The request object that this object is in response to.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Retrieve the data item with the given
key
. -
#eof? ⇒ Boolean
Returns
true
if the status code is FX_EOF;false
otherwise. -
#initialize(request, data = {}) ⇒ Response
constructor
Create a new Response object for the given Net::SFTP::Request instance, and with the given data.
-
#ok? ⇒ Boolean
Returns
true
if the status code is FX_OK;false
otherwise. -
#to_s ⇒ Object
(also: #to_str)
Returns a textual description of this response, including the status code and name.
Constructor Details
#initialize(request, data = {}) ⇒ Response
Create a new Response object for the given Net::SFTP::Request instance, and with the given data. If there is no :code key in the data, the code is assumed to be FX_OK.
34 35 36 37 |
# File 'lib/net/sftp/response.rb', line 34 def initialize(request, data={}) #:nodoc: @request, @data = request, data @code, @message = data[:code] || FX_OK, data[:message] end |
Instance Attribute Details
#code ⇒ Object (readonly)
The numeric code, one of the FX_* constants
26 27 28 |
# File 'lib/net/sftp/response.rb', line 26 def code @code end |
#data ⇒ Object (readonly)
A hash of request-specific data, such as a file handle or attribute information
23 24 25 |
# File 'lib/net/sftp/response.rb', line 23 def data @data end |
#message ⇒ Object (readonly)
The textual message for this response (possibly blank)
29 30 31 |
# File 'lib/net/sftp/response.rb', line 29 def @message end |
#request ⇒ Object (readonly)
The request object that this object is in response to
20 21 22 |
# File 'lib/net/sftp/response.rb', line 20 def request @request end |
Instance Method Details
#[](key) ⇒ Object
Retrieve the data item with the given key
. The key is converted to a symbol before being used to lookup the value.
41 42 43 |
# File 'lib/net/sftp/response.rb', line 41 def [](key) data[key.to_sym] end |
#eof? ⇒ Boolean
Returns true
if the status code is FX_EOF; false
otherwise.
63 64 65 |
# File 'lib/net/sftp/response.rb', line 63 def eof? code == FX_EOF end |
#ok? ⇒ Boolean
Returns true
if the status code is FX_OK; false
otherwise.
58 59 60 |
# File 'lib/net/sftp/response.rb', line 58 def ok? code == FX_OK end |
#to_s ⇒ Object Also known as: to_str
Returns a textual description of this response, including the status code and name.
47 48 49 50 51 52 53 |
# File 'lib/net/sftp/response.rb', line 47 def to_s if && !.empty? && .downcase != MAP[code] "#{} (#{MAP[code]}, #{code})" else "#{MAP[code]} (#{code})" end end |