Class: Net::SFTP::Protocol::V04::Name
- Inherits:
-
Object
- Object
- Net::SFTP::Protocol::V04::Name
- Defined in:
- lib/net/sftp/protocol/04/name.rb
Overview
Represents a single named item on the remote server. This includes the name, and attributes about the item, and the “longname”.
For backwards compatibility with the format and interface of the Name structure from previous protocol versions, this also exposes a #longname method, which returns a string that can be used to display this item in a directory listing.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Attributes instance describing this item.
-
#name ⇒ Object
readonly
The name of the item on the remote server.
Instance Method Summary collapse
-
#directory? ⇒ Boolean
Returns
true
if the item is a directory. -
#file? ⇒ Boolean
Returns
true
if the item is a regular file. -
#initialize(name, attributes) ⇒ Name
constructor
Create a new Name object with the given name and attributes.
-
#longname ⇒ Object
Returns a string representing this file, in a format similar to that used by the unix “ls” utility.
-
#symlink? ⇒ Boolean
Returns
true
if the item is a symlink.
Constructor Details
#initialize(name, attributes) ⇒ Name
Create a new Name object with the given name and attributes.
18 19 20 |
# File 'lib/net/sftp/protocol/04/name.rb', line 18 def initialize(name, attributes) @name, @attributes = name, attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Attributes instance describing this item.
15 16 17 |
# File 'lib/net/sftp/protocol/04/name.rb', line 15 def attributes @attributes end |
#name ⇒ Object (readonly)
The name of the item on the remote server.
12 13 14 |
# File 'lib/net/sftp/protocol/04/name.rb', line 12 def name @name end |
Instance Method Details
#directory? ⇒ Boolean
Returns true
if the item is a directory.
23 24 25 |
# File 'lib/net/sftp/protocol/04/name.rb', line 23 def directory? attributes.directory? end |
#file? ⇒ Boolean
Returns true
if the item is a regular file.
33 34 35 |
# File 'lib/net/sftp/protocol/04/name.rb', line 33 def file? attributes.file? end |
#longname ⇒ Object
Returns a string representing this file, in a format similar to that used by the unix “ls” utility.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/net/sftp/protocol/04/name.rb', line 39 def longname @longname ||= begin longname = if directory? "d" elsif symlink? "l" else "-" end longname << (attributes. & 0400 != 0 ? "r" : "-") longname << (attributes. & 0200 != 0 ? "w" : "-") longname << (attributes. & 0100 != 0 ? "x" : "-") longname << (attributes. & 0040 != 0 ? "r" : "-") longname << (attributes. & 0020 != 0 ? "w" : "-") longname << (attributes. & 0010 != 0 ? "x" : "-") longname << (attributes. & 0004 != 0 ? "r" : "-") longname << (attributes. & 0002 != 0 ? "w" : "-") longname << (attributes. & 0001 != 0 ? "x" : "-") longname << (" %-8s %-8s %8d " % [attributes.owner, attributes.group, attributes.size]) longname << Time.at(attributes.mtime).strftime("%b %e %H:%M ") longname << name end end |
#symlink? ⇒ Boolean
Returns true
if the item is a symlink.
28 29 30 |
# File 'lib/net/sftp/protocol/04/name.rb', line 28 def symlink? attributes.symlink? end |