Class: DRbQS::Setting::SSH

Inherits:
Base
  • Object
show all
Includes:
Command::Argument
Defined in:
lib/drbqs/setting/ssh.rb

Constant Summary

Constants included from Misc

Misc::STRINGS_FOR_KEY

Instance Attribute Summary collapse

Attributes inherited from Base

#source

Instance Method Summary collapse

Methods included from Command::Argument

check_argument_size, split_arguments

Methods inherited from Base

#clone, #string_for_shell, #value

Methods included from Misc

create_logger, create_uri, output_error, process_running_normally?, random_key, time_to_history_string, time_to_history_string2, uri_drbunix

Constructor Details

#initializeSSH

Returns a new instance of SSH.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/drbqs/setting/ssh.rb', line 8

def initialize
  super(:all_keys_defined => true) do
    [:directory, :shell, :rvm, :rvm_init, :output, :connect].each do |key|
      register_key(key, :check => 1)
    end
    register_key(:bundler, :bool => true)
    register_key(:nice, :check => 1, :default => [10])
    set_argument_condition(:>=, 0)
  end
  @mode_setting = nil
end

Instance Attribute Details

#mode_settingObject

Returns the value of attribute mode_setting.



6
7
8
# File 'lib/drbqs/setting/ssh.rb', line 6

def mode_setting
  @mode_setting
end

Instance Method Details

#command_line_argument(escape = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/drbqs/setting/ssh.rb', line 38

def command_line_argument(escape = nil)
  ary = super(escape)
  ssh_args = @mode_setting.command_line_argument(escape)
  if ssh_args.size > 0
    ary << '--'
    ary.concat(ssh_args)
  end
  ary
end

#configure_mode_setting(type = nil, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/drbqs/setting/ssh.rb', line 20

def configure_mode_setting(type = nil, &block)
  if type ||= get_argument[0]
    unless @mode_setting
      case type.intern
      when :server
        @mode_setting = DRbQS::Setting::Server.new
      when :node
        @mode_setting = DRbQS::Setting::Node.new
      else
        @mode_setting = DRbQS::Setting::Base.new
      end
    end
    yield(@mode_setting.value)
  else
    raise DRbQS::Setting::InvalidArgument, "Command mode is not determined."
  end
end

#exec(io = nil) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/drbqs/setting/ssh.rb', line 146

def exec(io = nil)
  case @command
  when 'list'
    command_list(io)
  when 'show'
    command_show(io)
  when 'environment'
    command_environment(io)
  when 'execute'
    command_execute(io)
  when 'server'
    command_server(io)
  when 'node'
    command_node(io)
  else
    raise DRbQS::Setting::InvalidArgument, "Invalid command '#{@command}'."
  end
end

#parse!Object

If there are invalid arguments, this method raises an error.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/drbqs/setting/ssh.rb', line 68

def parse!
  super
  [:directory, :shell, :rvm, :rvm_init, :nice, :bundler].each do |key|
    if val = get_first(key)
      @options[key] = val
    end
  end
  @output = get_first(:output)
  ary = get_argument
  @command = ary[0]
  @argv = ary[1..-1]
  @mode_setting.parse!
  @mode_argument_array = @mode_setting.command_line_argument
end