Class: GitGo::Connection::Remote
- Defined in:
- lib/git_go/connection/remote.rb
Instance Attribute Summary collapse
-
#ssh ⇒ Net::SSH::Connection::Session
readonly
Instance.
Attributes inherited from Base
Instance Method Summary collapse
-
#bash(command) ⇒ Hash
Executes the provided COMMAND over the #ssh connection.
-
#close ⇒ Object
Closes the #ssh connection and clears the ‘@connection` instance variable of this objects parent `Core` instance so new connections can be established.
-
#initialize(core) ⇒ GitGo::Connection::Remote
constructor
Creates a new instance of GitGo::Connection::Remote.
Methods inherited from Base
#cd, #close_and_exit, #directory?, #file?, #mkdir, #mv, #rm
Constructor Details
#initialize(core) ⇒ GitGo::Connection::Remote
Creates a new instance of GitGo::Connection::Remote. Establishes a session with the host and stores that session in #ssh.
13 14 15 16 |
# File 'lib/git_go/connection/remote.rb', line 13 def initialize(core) super(core) @ssh = Net::SSH.start(core.host, core.user) end |
Instance Attribute Details
#ssh ⇒ Net::SSH::Connection::Session (readonly)
Returns instance.
6 7 8 |
# File 'lib/git_go/connection/remote.rb', line 6 def ssh @ssh end |
Instance Method Details
#bash(command) ⇒ Hash
Executes the provided COMMAND over the #ssh connection. This is a blocking (non-asynchronous) operation.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/git_go/connection/remote.rb', line 31 def bash(command) response = { :stdout => "", :stderr => "" } ssh.open_channel do |channel| channel.exec(%Q(#{source} cd "#{current_path}"; #{command})) do |ch, success| abort "Failed: Couldn't execute command (ssh.channel.exec)." unless success channel.on_data { |_, data| response[:stdout] += data } channel.on_extended_data { |_, __, data| response[:stderr] += data } channel.on_request("exit-status") { |_, data| response[:exit_code] = data.read_long } end end ssh.loop response end |
#close ⇒ Object
Closes the #ssh connection and clears the ‘@connection` instance variable of this objects parent `Core` instance so new connections can be established.
21 22 23 24 |
# File 'lib/git_go/connection/remote.rb', line 21 def close ssh.close core.clear_connection end |