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



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/sshkit/backends/abstract.rb', line 66

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

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



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

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

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



40
41
42
# File 'lib/sshkit/backends/abstract.rb', line 40

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

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



36
37
38
# File 'lib/sshkit/backends/abstract.rb', line 36

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

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



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

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

#with(environment, &block) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/sshkit/backends/abstract.rb', line 57

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

#within(directory, &block) ⇒ Object



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

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