Class: Awt::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/awt/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host: "localhost", port: 22, user: nil, key: "~/.ssh/id_rsa") ⇒ Server

Returns a new instance of Server.



5
6
7
8
9
10
# File 'lib/awt/server.rb', line 5

def initialize(host: "localhost", port: 22, user: nil, key: "~/.ssh/id_rsa")
  @host = host
  @user = user.nil? ? ENV["USER"] : user
  @options = {port: port, keys: File.expand_path(key)}
  @printer = Printer.new(@host)
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/awt/server.rb', line 3

def host
  @host
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/awt/server.rb', line 3

def options
  @options
end

#userObject

Returns the value of attribute user.



3
4
5
# File 'lib/awt/server.rb', line 3

def user
  @user
end

Instance Method Details

#run(cmd) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/awt/server.rb', line 12

def run(cmd)
  @printer.host = @host if @printer.host != @host
  Net::SSH.start(@host, @user, @options) do |ssh|
    @printer.print_run cmd
    out = ssh.exec!(cmd)
    @printer.print_out out
  end
end