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.


33
34
35
36
37
38
39
40
41
42
# File 'lib/lsync/shell.rb', line 33

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

Instance Method Details

#connect(server) ⇒ Object


53
54
55
56
57
58
59
60
# File 'lib/lsync/shell.rb', line 53

def connect(server)
	options = {:passthrough => []}
	if server.local?
		return RExec::start_server(CLIENT_CODE, ruby_command, options)
	else
		return RExec::start_server(CLIENT_CODE, connection_command(server) + ruby_command, options)
	end
end

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

The command required to connect to the remote machine.


49
50
51
# File 'lib/lsync/shell.rb', line 49

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

#ruby_commandObject


44
45
46
# File 'lib/lsync/shell.rb', line 44

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