Class: DRbQS::Manage::SSHShell::RubyEnvironment

Inherits:
Object
  • Object
show all
Defined in:
lib/drbqs/manage/ssh_shell.rb

Constant Summary collapse

DEFAULT_RVM_SCRIPT =
'$HOME/.rvm/scripts/rvm'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ RubyEnvironment

Returns a new instance of RubyEnvironment.

Parameters:

  • opts (Hash) (defaults to: {})

    The options of ruby environment.

Options Hash (opts):

  • :directory (String)

    Directory when we execute commands.

  • :rvm (String)

    Set ruby implementation on rvm.

  • :rvm_init (String)

    Set the path of init script of rvm.

  • :env (Hash)

    Set pair of environmental variables and their values.



20
21
22
23
24
25
26
27
28
# File 'lib/drbqs/manage/ssh_shell.rb', line 20

def initialize(opts = {})
  @directory = opts[:directory]
  @rvm = opts[:rvm]
  @rvm_init = opts[:rvm_init]
  if (@rvm || @rvm_init) && !(String === @rvm_init)
    @rvm_init = DEFAULT_RVM_SCRIPT
  end
  @env = opts[:env]
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



13
14
15
# File 'lib/drbqs/manage/ssh_shell.rb', line 13

def directory
  @directory
end

#envObject (readonly)

Returns the value of attribute env.



13
14
15
# File 'lib/drbqs/manage/ssh_shell.rb', line 13

def env
  @env
end

#rvmObject (readonly)

Returns the value of attribute rvm.



13
14
15
# File 'lib/drbqs/manage/ssh_shell.rb', line 13

def rvm
  @rvm
end

#rvm_initObject (readonly)

Returns the value of attribute rvm_init.



13
14
15
# File 'lib/drbqs/manage/ssh_shell.rb', line 13

def rvm_init
  @rvm_init
end

Instance Method Details

#get_environment_commandsObject



49
50
51
52
53
54
# File 'lib/drbqs/manage/ssh_shell.rb', line 49

def get_environment_commands
  ['echo "directory: " `pwd`',
   'echo "files:"',
   'ls',
   'if which rvm > /dev/null; then rvm info; else ruby -v; fi']
end

#setup_commandsObject



41
42
43
44
45
46
47
# File 'lib/drbqs/manage/ssh_shell.rb', line 41

def setup_commands
  cmds = commands_to_set_env_on_bash
  cmds << "cd #{@directory}" if @directory
  cmds << "source #{@rvm_init}" if @rvm_init
  cmds << "rvm use #{@rvm}" if @rvm
  cmds
end