class Stockboy::Providers::FTP::SFTPAdapter

Attributes

client[R]

Public Class Methods

new(provider) click to toggle source
# File lib/stockboy/providers/ftp/sftp_adapter.rb, line 7
def initialize(provider)
  @provider = provider
  @file_dir = "."
end

Private Class Methods

exception_class() click to toggle source
# File lib/stockboy/providers/ftp/sftp_adapter.rb, line 55
def self.exception_class
  Net::SFTP::Exception
end

Public Instance Methods

chdir(directory) click to toggle source
# File lib/stockboy/providers/ftp/sftp_adapter.rb, line 21
def chdir(directory)
  @file_dir = ::File.join(directory, '')
end
delete(file_name) click to toggle source
# File lib/stockboy/providers/ftp/sftp_adapter.rb, line 29
def delete(file_name)
  client.remove!(full_path(file_name))
end
download(file_name) click to toggle source
# File lib/stockboy/providers/ftp/sftp_adapter.rb, line 33
def download(file_name)
  client.download!(full_path(file_name))
end
list_files() click to toggle source
# File lib/stockboy/providers/ftp/sftp_adapter.rb, line 25
def list_files
  client.dir.entries(@file_dir).map(&:name).sort
end
modification_time(file_name) click to toggle source
# File lib/stockboy/providers/ftp/sftp_adapter.rb, line 37
def modification_time(file_name)
  (mtime = stat(file_name).mtime) && Time.at(mtime)
end
open() { |self| ... } click to toggle source
# File lib/stockboy/providers/ftp/sftp_adapter.rb, line 12
def open
  result = nil
  Net::SFTP.start(@provider.host, @provider.username, password: @provider.password) do |sftp|
    @client = sftp
    result = yield self
  end
  result
end
size(file_name) click to toggle source
# File lib/stockboy/providers/ftp/sftp_adapter.rb, line 41
def size(file_name)
  stat(file_name).size
end

Private Instance Methods

full_path(file_name) click to toggle source
# File lib/stockboy/providers/ftp/sftp_adapter.rb, line 47
def full_path(file_name)
  ::File.join(@file_dir, file_name)
end
stat(file_name) click to toggle source
# File lib/stockboy/providers/ftp/sftp_adapter.rb, line 51
def stat(file_name)
  client.file.open(full_path(file_name)).stat
end