Class: LSync::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/lsync/shell.rb

Overview

A shell provides access to a server, typically to run an instance of ‘ruby`.

Direct Known Subclasses

LSync::Shells::SSH

Instance Method Summary collapse

Constructor Details

#initialize(command, options = {}) ⇒ Shell

Returns a new instance of Shell.



14
15
16
17
18
19
20
21
22
23
# File 'lib/lsync/shell.rb', line 14

def initialize(command, options = {})
  case command
  when Array
    @command = command
  else
    @command = [command]
  end
  
  @options = options
end

Instance Method Details

#connect(server) ⇒ Object

Establish a connection to the server using this shell configuration.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lsync/shell.rb', line 36

def connect(server)
  begin
    connection, pid = open_connection(server)
    message = connection.receive_object
  ensure
    connection.dump_errors if connection
  end
  
  if message != :ready
    raise ConnectionError.new("Remote shell connection was not successful: #{message}")
  end
  
  return connection, pid
end

#connection_command(server, arguments = []) ⇒ Object

The command required to connect to the remote machine.



31
32
33
# File 'lib/lsync/shell.rb', line 31

def connection_command(server, arguments = [])
  @command + (@options[:arguments] || []) + arguments + [server.host]
end

#ruby_commandObject

The command required to start an instance of Ruby.



26
27
28
# File 'lib/lsync/shell.rb', line 26

def ruby_command
  @options[:ruby] || ["ruby"]
end