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.


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

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


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

def config
  @config
end

#ruby_cmd

Returns the value of attribute ruby_cmd


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

def ruby_cmd
  @ruby_cmd
end

#uri

Returns the value of attribute uri


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

def uri
  @uri
end

Class Method Details

.local_file(file)


40
41
42
# File 'lib/dizby/tunnel/spawn_command.rb', line 40

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.


46
47
48
# File 'lib/dizby/tunnel/spawn_command.rb', line 46

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

.text(script)


36
37
38
# File 'lib/dizby/tunnel/spawn_command.rb', line 36

def text(script)
  new(script)
end

Instance Method Details

#dynamic?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'lib/dizby/tunnel/spawn_command.rb', line 22

def dynamic?
  @mode == :dynamic
end

#set_dynamic_mode


18
19
20
# File 'lib/dizby/tunnel/spawn_command.rb', line 18

def set_dynamic_mode
  @mode = :dynamic
end

#to_cmd Also known as: to_s


28
29
30
31
32
# File 'lib/dizby/tunnel/spawn_command.rb', line 28

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