Class: Stockboy::Providers::FTP::SFTPAdapter
- Inherits:
-
Object
- Object
- Stockboy::Providers::FTP::SFTPAdapter
- Defined in:
- lib/stockboy/providers/ftp/sftp_adapter.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #chdir(directory) ⇒ Object
- #delete(file_name) ⇒ Object
- #download(file_name) ⇒ Object
-
#initialize(provider) ⇒ SFTPAdapter
constructor
A new instance of SFTPAdapter.
- #list_files ⇒ Object
- #modification_time(file_name) ⇒ Object
- #open ⇒ Object
- #size(file_name) ⇒ Object
Constructor Details
#initialize(provider) ⇒ SFTPAdapter
Returns a new instance of SFTPAdapter.
7 8 9 10 |
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 7 def initialize(provider) @provider = provider @file_dir = "." end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 5 def client @client end |
Instance Method Details
#chdir(directory) ⇒ Object
21 22 23 |
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 21 def chdir(directory) @file_dir = ::File.join(directory, '') end |
#delete(file_name) ⇒ Object
29 30 31 |
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 29 def delete(file_name) client.remove!(full_path(file_name)) end |
#download(file_name) ⇒ Object
33 34 35 |
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 33 def download(file_name) client.download!(full_path(file_name)) end |
#list_files ⇒ Object
25 26 27 |
# 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) ⇒ Object
37 38 39 |
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 37 def modification_time(file_name) stat(file_name).mtime end |
#open ⇒ Object
12 13 14 15 16 17 18 19 |
# 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) ⇒ Object
41 42 43 |
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 41 def size(file_name) stat(file_name).size end |