Class: Producer::Core::Remote::FS

Inherits:
Object
  • Object
show all
Defined in:
lib/producer/core/remote/fs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sftp) ⇒ FS

Returns a new instance of FS.



7
8
9
# File 'lib/producer/core/remote/fs.rb', line 7

def initialize(sftp)
  @sftp = sftp
end

Instance Attribute Details

#sftpObject (readonly)

Returns the value of attribute sftp.



5
6
7
# File 'lib/producer/core/remote/fs.rb', line 5

def sftp
  @sftp
end

Instance Method Details

#chmod(path, mode) ⇒ Object



27
28
29
# File 'lib/producer/core/remote/fs.rb', line 27

def chmod(path, mode)
  setstat path, permissions: mode
end

#dir?(path) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/producer/core/remote/fs.rb', line 11

def dir?(path)
  sftp.stat!(path).directory?
rescue Net::SFTP::StatusException
  false
end

#file?(path) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/producer/core/remote/fs.rb', line 17

def file?(path)
  sftp.stat!(path).file?
rescue Net::SFTP::StatusException
  false
end

#file_read(path) ⇒ Object



35
36
37
38
39
# File 'lib/producer/core/remote/fs.rb', line 35

def file_read(path)
  sftp.file.open(path) { |f| content = f.read }
rescue Net::SFTP::StatusException
  nil
end

#file_write(path, content) ⇒ Object



41
42
43
44
45
# File 'lib/producer/core/remote/fs.rb', line 41

def file_write(path, content)
  sftp.file.open path, 'w' do |f|
    f.write content
  end
end

#mkdir(path, attributes = {}) ⇒ Object



31
32
33
# File 'lib/producer/core/remote/fs.rb', line 31

def mkdir(path, attributes = {})
  ret = sftp.mkdir! path, attributes
end

#setstat(path, attributes) ⇒ Object



23
24
25
# File 'lib/producer/core/remote/fs.rb', line 23

def setstat(path, attributes)
  sftp.setstat! path, attributes
end