Class: Confer::Connection
- Inherits:
-
Object
- Object
- Confer::Connection
- Defined in:
- lib/confer/connection.rb
Overview
Public: Encapsulates a connection to a remote host.
Instance Attribute Summary collapse
-
#config ⇒ Object
Public: A Hash containing the SSH configuration options.
-
#host ⇒ Object
Public: A String containing the remote hostname.
-
#user ⇒ Object
Public: A String containing the remote username.
Class Method Summary collapse
-
.start(opts = {}, &block) ⇒ Object
Public: Creates a new instance and immediately connects to the remote host, yielding the instance to the given block.
Instance Method Summary collapse
-
#exec!(command, opts = {}) ⇒ Object
Public: Execute a command on the remote host.
-
#initialize(opts = {}) ⇒ Connection
constructor
Public: Initialies a Connection instance.
-
#start(&block) ⇒ Object
Public: Opens a connection to the remote host and yields self to the given block for further interaction.
Constructor Details
#initialize(opts = {}) ⇒ Connection
Public: Initialies a Connection instance.
host - The host to connect to.
41 42 43 44 |
# File 'lib/confer/connection.rb', line 41 def initialize(opts = {}) @config ||= {} opts.apply_to self end |
Instance Attribute Details
#config ⇒ Object
Public: A Hash containing the SSH configuration options.
34 35 36 |
# File 'lib/confer/connection.rb', line 34 def config @config end |
#host ⇒ Object
Public: A String containing the remote hostname.
24 25 26 |
# File 'lib/confer/connection.rb', line 24 def host @host end |
#user ⇒ Object
Public: A String containing the remote username.
29 30 31 |
# File 'lib/confer/connection.rb', line 29 def user @user end |
Class Method Details
.start(opts = {}, &block) ⇒ Object
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.
17 18 19 |
# File 'lib/confer/connection.rb', line 17 def self.start(opts = {}, &block) Connection.new(opts).start(&block) end |
Instance Method Details
#exec!(command, opts = {}) ⇒ Object
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.
69 70 71 |
# File 'lib/confer/connection.rb', line 69 def exec!(command, opts = {}) @ssh.exec! command end |
#start(&block) ⇒ Object
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.
53 54 55 56 57 58 |
# 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 |