Class: SSHKit::Interactive::Backend

Inherits:
Backend::Printer
  • Object
show all
Defined in:
lib/sshkit/interactive/backend.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, options = {}, &block) ⇒ Backend

Returns a new instance of Backend.



4
5
6
7
8
# File 'lib/sshkit/interactive/backend.rb', line 4

def initialize(host, options = {}, &block)
  super(host, &block)

  @options = options
end

Instance Method Details

#_unsupported_operation(*args) ⇒ Object Also known as: upload!, download!, test, capture

Raises:

  • (SSHKit::Backend::MethodUnavailableError)


50
51
52
# File 'lib/sshkit/interactive/backend.rb', line 50

def _unsupported_operation(*args)
  raise SSHKit::Backend::MethodUnavailableError, 'SSHKit::Interactive does not support this operation.'
end

#as(who, &_block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sshkit/interactive/backend.rb', line 22

def as(who, &_block)
  if who.is_a?(Hash)
    @user  = who[:user]  || who['user']
    @group = who[:group] || who['group']
  else
    @user  = who
    @group = nil
  end

  raise SSHKit::Interactive::Unsupported, 'Setting group (through `as`) is currently not supported' unless @group.nil?

  yield
ensure
  remove_instance_variable(:@user)
  remove_instance_variable(:@group)
end

#execute(*args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/sshkit/interactive/backend.rb', line 39

def execute(*args)
  super

  options = args.extract_options!
  cmd     = Command.new(host, command(args, options), @options)

  debug(cmd.to_s)

  cmd.execute
end

#runObject



10
11
12
# File 'lib/sshkit/interactive/backend.rb', line 10

def run
  instance_exec(host, &@block)
end

#within(directory, &_block) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/sshkit/interactive/backend.rb', line 14

def within(directory, &_block)
  (@pwd ||= []).push(directory.to_s)

  yield
ensure
  @pwd.pop
end