class Confer::Connection
Public: Encapsulates a connection to a remote host.
Attributes
Public: A Hash
containing the SSH configuration options.
Public: A String containing the remote hostname.
Public: A String containing the remote username.
Public Class Methods
Public: Initialies a Connection
instance.
host - The host to connect to.
# File lib/confer/connection.rb, line 41 def initialize(opts = {}) @config ||= {} opts.apply_to self end
Public: Creates a new instance and immediately connects to the remote host, yielding the instance to the given block.
opts - The options to pass to the new Connection
instance. block - The block to receive the new instance.
# File lib/confer/connection.rb, line 17 def self.start(opts = {}, &block) Connection.new(opts).start(&block) end
Public Instance Methods
Public: Execute a command on the remote host.
command - The command to execute. opts - A hash of options:
:shell - True if the command should be run via the remote shell.
Returns the raw response from the command.
# File lib/confer/connection.rb, line 69 def exec!(command, opts = {}) @ssh.exec! command end
Public: Opens a connection to the remote host and yields self to the given block for further interaction. The connection will be closed once the block has executed.
block - The block to yield to.
# File lib/confer/connection.rb, line 53 def start(&block) Net::SSH.start(self.host, self.user, self.config) do |ssh| @ssh = ssh yield(self) end end