Class: SSHKit::Backend::Local

Inherits:
Printer show all
Defined in:
lib/sshkit/backends/local.rb

Instance Attribute Summary

Attributes inherited from Abstract

#host

Instance Method Summary collapse

Methods included from CommandHelper

#make, #rake

Methods inherited from Abstract

#as, config, configure, #debug, #error, #fatal, #info, #log, #make, #rake, #trace, #warn, #with, #within

Constructor Details

#initialize(_ = nil, &block) ⇒ Local

Returns a new instance of Local.



9
10
11
12
# File 'lib/sshkit/backends/local.rb', line 9

def initialize(_ = nil, &block)
  @host = Host.new(:local) # just for logging
  @block = block
end

Instance Method Details

#capture(*args) ⇒ Object



30
31
32
33
# File 'lib/sshkit/backends/local.rb', line 30

def capture(*args)
  options = { verbosity: Logger::DEBUG }.merge(args.extract_options!)
  _execute(*[*args, options]).full_stdout
end

#download!(remote, local = nil, options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/sshkit/backends/local.rb', line 45

def download!(remote, local=nil, options = {})
  if local.nil?
    FileUtils.cp(remote, File.basename(remote))
  else
    File.open(remote, "rb") do |f|
      IO.copy_stream(f, local)
    end
  end
end

#execute(*args) ⇒ Object



26
27
28
# File 'lib/sshkit/backends/local.rb', line 26

def execute(*args)
  _execute(*args).success?
end

#runObject



14
15
16
# File 'lib/sshkit/backends/local.rb', line 14

def run
  instance_exec(@host, &@block)
end

#test(*args) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/sshkit/backends/local.rb', line 18

def test(*args)
  options = args.extract_options!.merge(
    raise_on_non_zero_exit: false,
    verbosity: Logger::DEBUG
  )
  _execute(*[*args, options]).success?
end

#upload!(local, remote, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/sshkit/backends/local.rb', line 35

def upload!(local, remote, options = {})
  if local.is_a?(String)
    FileUtils.cp(local, remote)
  else
    File.open(remote, "wb") do |f|
      IO.copy_stream(local, f)
    end
  end
end