Class: Redwood::MBox::SSHLoader
- Defined in:
- lib/sup/mbox/ssh-loader.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Attributes inherited from Source
Class Method Summary collapse
Instance Method Summary collapse
- #connect ⇒ Object
- #cur_offset=(o) ⇒ Object
- #end_offset ⇒ Object
- #filename ⇒ Object
- #host ⇒ Object
- #id ⇒ Object
- #id=(o) ⇒ Object
-
#initialize(uri, username = nil, password = nil, start_offset = nil, usual = true, archived = false, id = nil, labels = []) ⇒ SSHLoader
constructor
A new instance of SSHLoader.
- #next ⇒ Object
- #safely ⇒ Object
-
#to_s ⇒ Object
def cur_offset; @loader.cur_offset; end # think we’ll be ok without this.
Methods inherited from Source
#==, #check, #done?, #each, #file_path, #is_source_for?, #reset!, #seek_to!, #usual
Constructor Details
#initialize(uri, username = nil, password = nil, start_offset = nil, usual = true, archived = false, id = nil, labels = []) ⇒ SSHLoader
Returns a new instance of SSHLoader.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sup/mbox/ssh-loader.rb', line 12 def initialize uri, username=nil, password=nil, start_offset=nil, usual=true, archived=false, id=nil, labels=[] raise ArgumentError, "not an mbox+ssh uri: #{uri.inspect}" unless uri =~ %r!^mbox\+ssh://! super uri, start_offset, usual, archived, id @parsed_uri = URI(uri) @username = username @password = password @uri = uri @cur_offset = start_offset @labels = (labels || []).freeze opts = {} opts[:username] = @username if @username opts[:password] = @password if @password @f = SSHFile.new host, filename, opts @loader = Loader.new @f, start_offset, usual, archived, id ## heuristic: use the filename as a label, unless the file ## has a path that probably represents an inbox. end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/sup/mbox/ssh-loader.rb', line 7 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/sup/mbox/ssh-loader.rb', line 7 def username @username end |
Class Method Details
.suggest_labels_for(path) ⇒ Object
35 |
# File 'lib/sup/mbox/ssh-loader.rb', line 35 def self.suggest_labels_for path; Loader.suggest_labels_for(path) end |
Instance Method Details
#connect ⇒ Object
37 |
# File 'lib/sup/mbox/ssh-loader.rb', line 37 def connect; safely { @f.connect }; end |
#cur_offset=(o) ⇒ Object
53 |
# File 'lib/sup/mbox/ssh-loader.rb', line 53 def cur_offset= o; @cur_offset = @loader.cur_offset = o; @dirty = true; end |
#end_offset ⇒ Object
49 50 51 |
# File 'lib/sup/mbox/ssh-loader.rb', line 49 def end_offset safely { @f.size } end |
#filename ⇒ Object
39 |
# File 'lib/sup/mbox/ssh-loader.rb', line 39 def filename; @parsed_uri.path[1..-1] end |
#host ⇒ Object
38 |
# File 'lib/sup/mbox/ssh-loader.rb', line 38 def host; @parsed_uri.host; end |
#id ⇒ Object
54 |
# File 'lib/sup/mbox/ssh-loader.rb', line 54 def id; @loader.id; end |
#id=(o) ⇒ Object
55 |
# File 'lib/sup/mbox/ssh-loader.rb', line 55 def id= o; @id = @loader.id = o; end |
#next ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/sup/mbox/ssh-loader.rb', line 41 def next safely do offset, labels = @loader.next self.cur_offset = @loader.cur_offset # superclass keeps @cur_offset which is used by yaml [offset, (labels + @labels).uniq] # add our labels end end |
#safely ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/sup/mbox/ssh-loader.rb', line 59 def safely begin yield rescue Net::SSH::Exception, SocketError, SSHFileError, SystemCallError, IOError => e m = "error communicating with SSH server #{host} (#{e.class.name}): #{e.}" raise FatalSourceError, m end end |
#to_s ⇒ Object
def cur_offset; @loader.cur_offset; end # think we’ll be ok without this
57 |
# File 'lib/sup/mbox/ssh-loader.rb', line 57 def to_s; @parsed_uri.to_s; end |