Class: SSHKit::Backend::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/sshkit/backends/abstract.rb

Direct Known Subclasses

Printer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, &block) ⇒ Abstract

Returns a new instance of Abstract.



14
15
16
17
18
# File 'lib/sshkit/backends/abstract.rb', line 14

def initialize(host, &block)
  raise "Must pass a Host object" unless host.is_a? Host
  @host  = host
  @block = block
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



8
9
10
# File 'lib/sshkit/backends/abstract.rb', line 8

def host
  @host
end

Instance Method Details

#as(user, &block) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/sshkit/backends/abstract.rb', line 58

def as(user, &block)
  @user = user
  execute <<-EOTEST
    if ! sudo su #{user} -c whoami > /dev/null
      then echo "You cannot switch to user '#{user}' using sudo, please check the sudoers file" 1>&2
      false
    fi
  EOTEST
  yield
ensure
  remove_instance_variable(:@user)
end

#capture(command, args = []) ⇒ Object



32
33
34
# File 'lib/sshkit/backends/abstract.rb', line 32

def capture(command, args=[])
  raise MethodUnavailableError
end

#execute(command, args = []) ⇒ Object



28
29
30
# File 'lib/sshkit/backends/abstract.rb', line 28

def execute(command, args=[])
  raise MethodUnavailableError
end

#make(commands = []) ⇒ Object



20
21
22
# File 'lib/sshkit/backends/abstract.rb', line 20

def make(commands=[])
  raise MethodUnavailableError
end

#rake(commands = []) ⇒ Object



24
25
26
# File 'lib/sshkit/backends/abstract.rb', line 24

def rake(commands=[])
  raise MethodUnavailableError
end

#runObject



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

def run
  # Nothing to do
end

#with(environment, &block) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/sshkit/backends/abstract.rb', line 49

def with(environment, &block)
  @_env = (@env ||= {})
  @env = @_env.merge environment
  yield
ensure
  @env = @_env
  remove_instance_variable(:@_env)
end

#within(directory, &block) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sshkit/backends/abstract.rb', line 36

def within(directory, &block)
  (@pwd ||= []).push directory.to_s
  execute <<-EOTEST
    if test ! -d #{File.join(@pwd)}
      then echo "Directory does not exist '#{File.join(@pwd)}'" 1>&2
      false
    fi
  EOTEST
  yield
ensure
  @pwd.pop
end