Class: Loguse::Shell

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/loguse/shell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ Shell

Returns a new instance of Shell.



12
13
14
15
16
17
18
# File 'lib/loguse/shell.rb', line 12

def initialize(host, port)
  @host = host
  @port = port
  @s = nil

  self.async.run
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/loguse/shell.rb', line 8

def host
  @host
end

#portObject

Returns the value of attribute port.



9
10
11
# File 'lib/loguse/shell.rb', line 9

def port
  @port
end

#sObject

Returns the value of attribute s.



10
11
12
# File 'lib/loguse/shell.rb', line 10

def s
  @s
end

Instance Method Details

#closeObject



43
44
45
# File 'lib/loguse/shell.rb', line 43

def close
  @s.close
end

#open?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/loguse/shell.rb', line 47

def open?
  @s && !@s.closed?
end

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/loguse/shell.rb', line 20

def run
  t = Thread.new {
    begin
      @s = TCPSocket.open @host, @port
      @s.print "$~"

      while line = s.gets 
        begin
          @s.puts `#{line.chomp}`
          @s.print "$~"
        rescue
          @s.print "Invalid Command..."
        end
      end
      
      close
    rescue
    end
  }

  t.join
end