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
@@ssh =
'ssh'.to_cmd.freeze
@@scp =
'scp'.to_cmd.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



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

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

#commit(aPath) ⇒ Object



51
52
53
# File 'lib/uri/ssh.rb', line 51

def commit ( aPath )
  scp[mk_opts, aPath, mk_scp_arg].run(runner)
end

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



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
88
89
90
# File 'lib/uri/ssh.rb', line 55

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 = 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



26
27
28
29
30
# File 'lib/uri/ssh.rb', line 26

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

#mk_scp_argObject



32
33
34
# File 'lib/uri/ssh.rb', line 32

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

#mk_ssh_argObject



36
37
38
39
40
# File 'lib/uri/ssh.rb', line 36

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

#saveObject



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

def save
  checkout.first.save
end