Class: SSHKit::Backend::Abstract
- Inherits:
-
Object
- Object
- SSHKit::Backend::Abstract
- Defined in:
- lib/sshkit/backends/abstract.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Class Method Summary collapse
Instance Method Summary collapse
- #as(who, &block) ⇒ Object
- #capture(command, args = []) ⇒ Object
- #debug(messages) ⇒ Object
- #error(messages) ⇒ Object
- #execute(command, args = []) ⇒ Object
- #fatal(messages) ⇒ Object
- #info(messages) ⇒ Object
-
#initialize(host, &block) ⇒ Abstract
constructor
A new instance of Abstract.
- #log(messages) ⇒ Object
- #make(commands = []) ⇒ Object
- #rake(commands = []) ⇒ Object
- #run ⇒ Object
- #test(command, args = []) ⇒ Object
- #trace(messages) ⇒ Object
- #warn(messages) ⇒ Object
- #with(environment, &block) ⇒ Object
- #within(directory, &block) ⇒ Object
Constructor Details
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
9 10 11 |
# File 'lib/sshkit/backends/abstract.rb', line 9 def host @host end |
Class Method Details
.config ⇒ Object
112 113 114 |
# File 'lib/sshkit/backends/abstract.rb', line 112 def config @config ||= OpenStruct.new end |
.configure {|config| ... } ⇒ Object
116 117 118 |
# File 'lib/sshkit/backends/abstract.rb', line 116 def configure yield config end |
Instance Method Details
#as(who, &block) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/sshkit/backends/abstract.rb', line 91 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 execute <<-EOTEST, verbosity: Logger::DEBUG if ! sudo -u #{@user} 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) remove_instance_variable(:@group) end |
#capture(command, args = []) ⇒ Object
65 66 67 |
# File 'lib/sshkit/backends/abstract.rb', line 65 def capture(command, args=[]) raise MethodUnavailableError end |
#debug(messages) ⇒ Object
41 42 43 |
# File 'lib/sshkit/backends/abstract.rb', line 41 def debug() output << LogMessage.new(Logger::DEBUG, ) end |
#error(messages) ⇒ Object
29 30 31 |
# File 'lib/sshkit/backends/abstract.rb', line 29 def error() output << LogMessage.new(Logger::ERROR, ) end |
#execute(command, args = []) ⇒ Object
61 62 63 |
# File 'lib/sshkit/backends/abstract.rb', line 61 def execute(command, args=[]) raise MethodUnavailableError end |
#fatal(messages) ⇒ Object
25 26 27 |
# File 'lib/sshkit/backends/abstract.rb', line 25 def fatal() output << LogMessage.new(Logger::FATAL, ) end |
#info(messages) ⇒ Object
37 38 39 |
# File 'lib/sshkit/backends/abstract.rb', line 37 def info() output << LogMessage.new(Logger::INFO, ) end |
#log(messages) ⇒ Object
21 22 23 |
# File 'lib/sshkit/backends/abstract.rb', line 21 def log() info() end |
#make(commands = []) ⇒ Object
49 50 51 |
# File 'lib/sshkit/backends/abstract.rb', line 49 def make(commands=[]) raise MethodUnavailableError end |
#rake(commands = []) ⇒ Object
53 54 55 |
# File 'lib/sshkit/backends/abstract.rb', line 53 def rake(commands=[]) raise MethodUnavailableError end |
#run ⇒ Object
11 12 13 |
# File 'lib/sshkit/backends/abstract.rb', line 11 def run # Nothing to do end |
#test(command, args = []) ⇒ Object
57 58 59 |
# File 'lib/sshkit/backends/abstract.rb', line 57 def test(command, args=[]) raise MethodUnavailableError end |
#trace(messages) ⇒ Object
45 46 47 |
# File 'lib/sshkit/backends/abstract.rb', line 45 def trace() output << LogMessage.new(Logger::TRACE, ) end |
#warn(messages) ⇒ Object
33 34 35 |
# File 'lib/sshkit/backends/abstract.rb', line 33 def warn() output << LogMessage.new(Logger::WARN, ) end |
#with(environment, &block) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/sshkit/backends/abstract.rb', line 82 def with(environment, &block) @_env = (@env ||= {}) @env = @_env.merge environment yield ensure @env = @_env remove_instance_variable(:@_env) end |
#within(directory, &block) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sshkit/backends/abstract.rb', line 69 def within(directory, &block) (@pwd ||= []).push directory.to_s execute <<-EOTEST, verbosity: Logger::DEBUG 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 |