Class: Dizby::SpawnCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/dizby/tunnel/spawn_command.rb

Constant Summary collapse

TEMPLATE =
"require'dizby/tunnel/spawned';Dizby::Spawned.%s('%s',%s){%s}"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, config = {}) ⇒ SpawnCommand

Returns a new instance of SpawnCommand.


8
9
10
11
12
13
14
# File 'lib/dizby/tunnel/spawn_command.rb', line 8

def initialize(data, config = {})
  @data = data
  @ruby_cmd = 'ruby'
  @uri = 'drb://'
  @config = config
  @mode = :static
end

Instance Attribute Details

#config

Returns the value of attribute config


24
25
26
# File 'lib/dizby/tunnel/spawn_command.rb', line 24

def config
  @config
end

#ruby_cmd

Returns the value of attribute ruby_cmd


24
25
26
# File 'lib/dizby/tunnel/spawn_command.rb', line 24

def ruby_cmd
  @ruby_cmd
end

#uri

Returns the value of attribute uri


24
25
26
# File 'lib/dizby/tunnel/spawn_command.rb', line 24

def uri
  @uri
end

Class Method Details

.local_file(file)


38
39
40
# File 'lib/dizby/tunnel/spawn_command.rb', line 38

def local_file(file)
  new(File.read(file))
end

.remote_file(file, obj_name)

WARNING: Dangerous operation. This loads an object from a file on the remote machine. That file may be insecure or modified without notice.


44
45
46
# File 'lib/dizby/tunnel/spawn_command.rb', line 44

def remote_file(file, obj_name)
  new("load '#{file}'; #{obj_name}")
end

.text(script)


34
35
36
# File 'lib/dizby/tunnel/spawn_command.rb', line 34

def text(script)
  new(script)
end

Instance Method Details

#dynamic?Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/dizby/tunnel/spawn_command.rb', line 20

def dynamic?
  @mode == :dynamic
end

#set_dynamic_mode


16
17
18
# File 'lib/dizby/tunnel/spawn_command.rb', line 16

def set_dynamic_mode
  @mode = :dynamic
end

#to_cmd Also known as: to_s


26
27
28
29
30
# File 'lib/dizby/tunnel/spawn_command.rb', line 26

def to_cmd
  # TODO: needs a lot of work...
  args = [@mode, @uri.shellescape, @config.inspect, @data.shellescape]
  [@ruby_cmd, '-e', %("#{TEMPLATE % args}")].join ' '
end