Sha256: 8449db8aa72ced417223fb86ad989473f5c7ab57c8bd9a1f56ad2b21b12a3230

Contents?: true

Size: 846 Bytes

Versions: 12

Compression:

Stored size: 846 Bytes

Contents

# coding: utf-8
require 'rainbow'
require 'sshkit'
require 'gaptool_client/api'

module Gaptool
  class InteractionHandler
    attr_reader :host
    def initialize(host)
      @host = host
    end

    def on_data(_command, stream_name, data, _channel)
      case stream_name
      when :stdout
        puts "#{Rainbow("#{@host}").yellow}> #{data}"
      when :stderr
        STDERR.puts "#{Rainbow("#{@host}").red}> #{data}"
      end
    end
  end

  class Host < SSHKit::Host
    attr_reader :info

    def initialize(node)
      super(node['hostname'])
      @info = node
    end

    def method_missing(attr, *args, &_block)
      @info[attr] || super
    end

    def [](attr)
      @info[attr]
    end

    def name
      @name ||= Gaptool::API.get_host(@info)
    end

    def handler
      InteractionHandler.new(name)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gaptool-client-0.8.2 lib/gaptool_client/host.rb
gaptool-client-0.8.1 lib/gaptool_client/host.rb
gaptool-client-0.8.0 lib/gaptool_client/host.rb
gaptool-client-0.8.0.pre.beta5 lib/gaptool_client/host.rb
gaptool-client-0.8.0.pre.beta4 lib/gaptool_client/host.rb
gaptool-client-0.8.0.pre.beta3 lib/gaptool_client/host.rb
gaptool-client-0.8.0.pre.beta2 lib/gaptool_client/host.rb
gaptool-client-0.8.0.pre.beta1 lib/gaptool_client/host.rb
gaptool-client-0.8.0.pre.beta lib/gaptool_client/host.rb
gaptool-client-0.8.0.pre.alpha10 lib/gaptool_client/host.rb
gaptool-client-0.8.0.pre.alpha9 lib/gaptool_client/host.rb
gaptool-client-0.8.0.pre.alpha8 lib/gaptool_client/host.rb