Class: Awt::Server
- Inherits:
-
Object
- Object
- Awt::Server
- Defined in:
- lib/awt/server.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#options ⇒ Object
Returns the value of attribute options.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(host: "localhost", port: 22, user: nil, key: "~/.ssh/id_rsa") ⇒ Server
constructor
A new instance of Server.
- #run(cmd) ⇒ Object
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.(key)} @printer = Printer.new(@host) end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
3 4 5 |
# File 'lib/awt/server.rb', line 3 def host @host end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/awt/server.rb', line 3 def @options end |
#user ⇒ Object
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 |