class DRbQS::Setting::SSH

Attributes

mode_setting[RW]

Public Class Methods

new() click to toggle source
Calls superclass method DRbQS::Setting::Base::new
# 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

Public Instance Methods

command_line_argument(escape = nil) click to toggle source
Calls superclass method
# 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) { |value| ... } click to toggle source
# 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) click to toggle source
# 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!() click to toggle source

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

Calls superclass method DRbQS::Setting::Base#parse!
# 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

Private Instance Methods

command_environment(io) click to toggle source
# File lib/drbqs/setting/ssh.rb, line 120
def command_environment(io)
  dest = only_first_argument
  manage_ssh(dest, io).get_environment
end
command_execute(io) click to toggle source
# File lib/drbqs/setting/ssh.rb, line 126
def command_execute(io)
  mng_ssh = manage_ssh(connecting_ssh_server, io)
  if @mode_argument_array.size > 0
    mng_ssh.command(@mode_argument_array)
  else
    raise "There is no command for ssh."
  end
end
command_list(io) click to toggle source
# File lib/drbqs/setting/ssh.rb, line 83
def command_list(io)
  if io
    ssh_host = DRbQS::Config.new.ssh_host
    io.puts ssh_host.config_names.join("\n")
  end
end
command_node(io) click to toggle source
# File lib/drbqs/setting/ssh.rb, line 141
def command_node(io)
  manage_ssh(connecting_ssh_server, io).node(@mode_argument_array, :nice => @nice, :daemon => @output)
end
command_server(io) click to toggle source
# File lib/drbqs/setting/ssh.rb, line 136
def command_server(io)
  manage_ssh(connecting_ssh_server, io).server(@mode_argument_array, :nice => @nice, :daemon => @output)
end
command_show(io) click to toggle source
# File lib/drbqs/setting/ssh.rb, line 102
def command_show(io)
  if io
    name = only_first_argument
    ssh_host = DRbQS::Config.new.ssh_host
    if path = ssh_host.get_path(name)
      io.puts File.read(path)
    else
      raise DRbQS::Setting::InvalidArgument, "Can not find configuration file '#{name}'."
    end
  end
end
connecting_ssh_server() click to toggle source
# File lib/drbqs/setting/ssh.rb, line 97
def connecting_ssh_server
  only_first_argument
end
manage_ssh(dest, io) click to toggle source
# File lib/drbqs/setting/ssh.rb, line 115
def manage_ssh(dest, io)
  DRbQS::Manage::SSHExecute.new(dest, { :io => io }.merge(@options))
end
only_first_argument() click to toggle source
# File lib/drbqs/setting/ssh.rb, line 91
def only_first_argument
  check_argument_size(@argv, :==, 1)
  @argv[0]
end
preprocess!() click to toggle source
# File lib/drbqs/setting/ssh.rb, line 48
def preprocess!
  if connect = get_first(:connect)
    value.argument << connect
    clear(:connect)
  end
  if type = get_argument[0]
    case type.intern
    when :server
      @mode_setting.clear(:log_file)
      @mode_setting.clear(:daemon)
    when :node
      @mode_setting.clear(:log_prefix)
      @mode_setting.clear(:daemon)
    end
  end
end