Class: RemoteRun::Host::LockFile::RemoteFile

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_run/host.rb

Instance Method Summary collapse

Constructor Details

#initialize(hostname, configuration) ⇒ RemoteFile

Returns a new instance of RemoteFile.



96
97
98
99
# File 'lib/remote_run/host.rb', line 96

def initialize(hostname, configuration)
  @hostname = hostname
  @configuration = configuration
end

Instance Method Details

#delete(file_path) ⇒ Object



113
114
115
# File 'lib/remote_run/host.rb', line 113

def delete(file_path)
  run_and_test("rm -f #{file_path}")
end

#exist?(file_path) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/remote_run/host.rb', line 101

def exist?(file_path)
  run_and_test("test -f #{file_path}")
end

#read(file_path) ⇒ Object



105
106
107
# File 'lib/remote_run/host.rb', line 105

def read(file_path)
  run("test -e #{file_path} && cat #{file_path}")
end

#run(command) ⇒ Object



117
118
119
# File 'lib/remote_run/host.rb', line 117

def run(command)
  `ssh #{@configuration.ssh_options} #{$runner.}@#{@hostname} '#{command};'`.strip
end

#run_and_test(command) ⇒ Object



121
122
123
# File 'lib/remote_run/host.rb', line 121

def run_and_test(command)
  system("ssh #{@configuration.ssh_options} #{$runner.}@#{@hostname} '#{command}' 2>/dev/null")
end

#write(file_path, text) ⇒ Object



109
110
111
# File 'lib/remote_run/host.rb', line 109

def write(file_path, text)
  run_and_test("test -e #{file_path} || echo #{text} > #{file_path}")
end