Class: URI::Ssh

Inherits:
GenericEx show all
Defined in:
lib/uri/ssh.rb

Constant Summary collapse

SCHEME =
'ssh'.freeze
DEFAULT_HOST =
'localhost'.freeze
DEFAULT_PORT =
22
DEFAULT_QUERY =
''.freeze
COMPONENT =
[
  :scheme,
  :userinfo,
  :host,
  :path,
  :query
].freeze

Instance Method Summary collapse

Methods inherited from Generic

#add_query, #mk_custom_opts, #pathname, #pathname=, #to_uri, #to_yaml_string, yaml_load

Instance Method Details

#checkoutObject



39
40
41
42
# File 'lib/uri/ssh.rb', line 39

def checkout
  out = TempPath.new('checkout', pathname.basename.to_s)
  [out, shell.scp!(mk_opts, mk_scp_arg, out)]
end

#commit(aPath) ⇒ Object



48
49
50
# File 'lib/uri/ssh.rb', line 48

def commit ( aPath )
  shell.scp! mk_opts, aPath, mk_scp_arg
end

#jump_and_eval(aString, ruby = 'ruby', ruby_opts = [], &block) ⇒ Object Also known as: remote_eval



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/uri/ssh.rb', line 52

def jump_and_eval ( aString, ruby='ruby', ruby_opts=[], &block )
  tag = "=== RESULT ===\n"
  TempPath.new do |tmp|
    tmp.open('w') do |f|
      f.print "
        aProc = proc { #{aString} }
        result =
          begin
            [true, aProc[]]
          rescue Exception => ex
            [false, ex]
          end
        STDERR.print '#{tag}'
        STDERR.print Marshal.dump(result)
      "
    end
    cmd = shell.ssh(mk_opts, mk_ssh_arg, ruby, *ruby_opts) < tmp
    data = cmd.popen
    block[data.output]
    data.waitpid
    if data.status.success?
      err = data.error.read
      err, result = err.split(tag)
      STDERR.print err
      st, obj = Marshal.load(result)
      if st
        return obj
      else
        raise obj
      end
    else
      data.display
      raise "Command failed #{cmd}"
    end
  end
end

#mk_optsObject



23
24
25
26
27
# File 'lib/uri/ssh.rb', line 23

def mk_opts
  opts = ['-q']
  opts << '-P' << @port if @port != DEFAULT_PORT
  opts + mk_custom_opts
end

#mk_scp_argObject



29
30
31
# File 'lib/uri/ssh.rb', line 29

def mk_scp_arg
  "#{mk_ssh_arg}:#{@path.gsub(/^\//, '')}"
end

#mk_ssh_argObject



33
34
35
36
37
# File 'lib/uri/ssh.rb', line 33

def mk_ssh_arg
  result = ''
  result << @user << '@' if @user
  result + @host
end

#saveObject



44
45
46
# File 'lib/uri/ssh.rb', line 44

def save
  checkout.first.save
end