Class: Ronin::PostEx::RemoteDir
- Inherits:
-
Object
- Object
- Ronin::PostEx::RemoteDir
- Includes:
- Enumerable
- Defined in:
- lib/ronin/post_ex/remote_dir.rb
Overview
The RemoteDir class represents directories on a remote system.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
The path of the directory.
-
#pos ⇒ Integer
readonly
The current position in the open directory.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the opened directory.
-
#each {|entry| ... } ⇒ Enumerator
Iterates through the entries within the directory.
-
#initialize(path, entries = []) ⇒ RemoteDir
constructor
Creates a new Dir object.
-
#inspect ⇒ String
Inspects the directory.
-
#read ⇒ String?
Reads the next entry from the directory.
-
#rewind ⇒ Dir
Rewinds the opened directory.
-
#seek(new_pos) ⇒ Dir
Sets the position within the open directory.
-
#tell ⇒ Integer
Returns the position in the opened directory.
Constructor Details
#initialize(path, entries = []) ⇒ RemoteDir
Creates a new Dir object.
47 48 49 50 51 52 |
# File 'lib/ronin/post_ex/remote_dir.rb', line 47 def initialize(path,entries=[]) @path = path @entries = entries @pos = 0 @closed = false end |
Instance Attribute Details
#path ⇒ Object (readonly)
The path of the directory
31 32 33 |
# File 'lib/ronin/post_ex/remote_dir.rb', line 31 def path @path end |
#pos ⇒ Integer (readonly)
The current position in the open directory.
36 37 38 |
# File 'lib/ronin/post_ex/remote_dir.rb', line 36 def pos @pos end |
Instance Method Details
#close ⇒ Object
Closes the opened directory.
173 174 175 176 |
# File 'lib/ronin/post_ex/remote_dir.rb', line 173 def close @closed = true return nil end |
#each {|entry| ... } ⇒ Enumerator
Iterates through the entries within the directory.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ronin/post_ex/remote_dir.rb', line 130 def each return enum_for(__method__) unless block_given? if @closed raise(IOError,"closed directory") end @pos = 0 @entries.each do |entry| yield entry @pos += 1 end return self end |
#inspect ⇒ String
Inspects the directory.
184 185 186 |
# File 'lib/ronin/post_ex/remote_dir.rb', line 184 def inspect "<#{self.class}:#{@path}>" end |
#read ⇒ String?
Reads the next entry from the directory.
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/ronin/post_ex/remote_dir.rb', line 157 def read if @closed raise(IOError,"closed directory") end if @pos < @entries.length next_entry = @entries[@pos] @pos += 1 return next_entry end end |
#rewind ⇒ Dir
Rewinds the opened directory.
79 80 81 82 83 84 85 86 |
# File 'lib/ronin/post_ex/remote_dir.rb', line 79 def rewind if @closed raise(IOError,"closed directory") end @pos = 0 return self end |
#seek(new_pos) ⇒ Dir
Sets the position within the open directory.
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ronin/post_ex/remote_dir.rb', line 102 def seek(new_pos) if @closed raise(IOError,"closed directory") end if (new_pos < 0) || (new_pos >= @entries.length) raise(Errno::EINVAL,"invalid seek position") end @pos = new_pos return self end |
#tell ⇒ Integer
Returns the position in the opened directory.
63 64 65 66 67 68 69 |
# File 'lib/ronin/post_ex/remote_dir.rb', line 63 def tell if @closed raise(IOError,"closed directory") end return @pos end |