Thibault Jouan f45d0b5a20 Modify Remote::FS interface:
* Accept SFTP session in FS constructor;
* Modify Remote to build the session required by FS;
* Change TestEnvHelpers#build_remote in order to provided a test double
  as the remote FS.
2014-03-05 00:07:59 +00:00

42 lines
793 B
Ruby

module Producer
module Core
class Remote
class FS
attr_reader :sftp
def initialize(sftp)
@sftp = sftp
end
def dir?(path)
sftp.stat!(path).directory?
rescue Net::SFTP::StatusException
false
end
def file?(path)
sftp.stat!(path).file?
rescue Net::SFTP::StatusException
false
end
def mkdir(path)
sftp.mkdir! path
end
def file_read(path)
sftp.file.open(path) { |f| content = f.read }
rescue Net::SFTP::StatusException
nil
end
def file_write(path, content)
sftp.file.open path, 'w' do |f|
f.write content
end
end
end
end
end
end